I have 6 groups in Photoshop that contain a number of layers within each group. I'm looking to turn on/off a layer within each group to create every possible combination of the image.
Can someone point me in the right direction?
I've never scripted in Photoshop but trying to figure this out on my own.
I'm quite new to CS5 scripting myself, but I think I can explain how it works. The code examples may not be the most effective way to do it, but it does the trick.
There is a big difference between a Group of layers or the individual layer itself. All layers and groups are ordered in the DOM format. To get your root you can use the global instance
app
to get the active document:app.activeDocument
.The messy part is that there are two separate arrays for single layers and groups. To get the array of single layers use
app.activeDocument.layers
andapp.activeDocument.layerSets
for the groups.To go deeper down in the hieralcy, use the layerSets array to iterate down.
For example, let us assume the following hieralcy:
Here
Border
,Star
,Home
,Add
andRemove
are all single layers whileIcons
,Left
andRight
are Groups.To turn on group
Left
we need to iterate down theIcon
group:If you show a layer/group in CS5 by clicking with your mouse, all parent groups will automatically be shown too. By scripting this isn't the case, you have to enable all parents as well.
To show the Border layer you need to use the layers array instead.
Same things apply if you want to show the Add layer.
This can be a bit messy if you have a lot of groups and layers. I created a function that follows a supplied path to get the end object. It will determine by itself if it is a layer or a group.
...and one function to simply set or clear a group or layer by its path.
..and at last I wrote this function to hide all groups and/or layers from a user specified root.
Here is an example of how to use the functions
I hope this is useful to someone more than just me :)