Hi all,
I'm using the COM interop for photoshop in my C# assembly to automate some actions in photoshop. The problem is that LayerSet.Merge() throws a COM exception in certain situations. I don't know if I have all the cases, but in general, I assumed that LayerSet.Merge() would collapse a LayerSet, regardless of how many nested LayerSets and ArtLayers were in it to an ArtLayer that I could assign to the ActiveLayer. That appears to not be the case. So I do something like this:
// store state
HistoryState state = d.ActiveHistoryState;
d.ActiveLayer = set.Merge();
d.Selection.SelectAll();
// process the layer in some way...
// restore state
d.ActiveHistoryState = state;
where d is the ActiveDocument and set is the LayerSet I'd like to merge. I checked in the debugger and the ActiveDocument (d) is not null and is the right document opened in Photoshop. The LayerSet I'm calling Merge() on (set) is also not null and the correct LayerSet, but for some reason, I get this exception:
System.Runtime.InteropServices.COMException was unhandled by user code
Message: General Photoshop error occurred. This functionality may not be available in this version of Photoshop.
- The object "layer 38 of document 37" is not currently available.
My photoshop file looks like this:
myFile.psd
|-mySet1
|-mySet1_1
|-artLayer1
|-mySet1_2
|-artLayer2
|-artLayer3
so my code loops through and merges each LayerSet starting at the deepest point. In other words, mySet1_2 is merged first and assigned to the ActiveLayer (then processed etc) and that works. Then mySet1_2 is merged and assigned to ActiveLayer, then mySet1 is merged and that's when I hit the COM exception.
I assumed LayerSet.Merge() was exactly the same as using Layer->MergeLayers in the Photoshop UI, but that's apparently not the case since I can merge all of those LayerSets using the UI, but the COM object seems to balk.
does anyone have any idea what the issue is?
Thanks!
-C