Copy link to clipboard
Copied
So I spent the evening researching a way to expand/contract a layer group.. normally we have to click on the small triangle icon that appears before the layer name in the layers panel to expand the group, and click it again to fold it all up. So far, I've found information stating that it can't be done via scripting...
I thought up one way to do it, and that would be to search a layer by name (using a different script), and make sure that the layer name being searched for is inside of a contracted group.. and when that layer name is found and selected, it will unfold the layer group and show select the layer. It's quite a runaround though. Is there a more efficient way to do it with a script?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thanks, had a look through the topic (I had actualy browsed through one of those links a few months back) and it seems that there's no way to do it via a script. Tried all the sample code there and none of it was able to pull it off... seems the only way to do it is to activate a layer within the layer group and then it will unfold it.
Just gotta make sure one of the layer names within the group is always the same (create an empty layer and name it "unfold" for example) and then use a script which activates the layer "unfold" and then it will expand that group.. but what if several layer groups all contain "unfold".. it might not know which layer group to go to (or it will go to the first one)
It's quite a workaround but it would likely do the trick...
Copy link to clipboard
Copied
To expand or open a layerSet in the layers panel all you need to do is make it active as you said. But you don't have to worry about layer names and you especially don't need to create a empty layer just so you can expand the set with a script.
function openAllLayerSets( parent ){
for(var setIndex=0;setIndex<parent.layerSets.length;setIndex++){
app.activeDocument.activeLayer = parent.layerSets[setIndex].layers[0];
openAllLayerSets( parent.layerSets[setIndex]);
}
};
openAllLayerSets( app.activeDocument );
Because selecting and working with a layer expands the layerSet more people ask about closing the set or how to determine if a set is open or closed. I don't think there is a good simple way to close a layerSet via scripting. Paul's code at ps-scripts does work to close a layerSet but I don't think it is worth the extra steps just to make a change that doesn't really effect the document. And I don't know of any way to tell the current state of the layerSet in an open document.
Copy link to clipboard
Copied
wow, you guys are incredible... I recalled finding a way to open all existing layer groups (as your script does), but I was never able to retrieve it... but this works! Does this script need to open all groups or could it open just the active layer group and then keep the top level layer of that group active (the layer that contains the small triangle to expand/contract)?
Copy link to clipboard
Copied
I've played around with the script a little bit, trying to understand it... I've come up with this:
function openGroup(layerSet){
for(var setIndex=0;setIndex<layerSet.length;setIndex++){
app.activeDocument.activeLayer =
layerSet[setIndex].layers[0];
openGroup( layerSet[setIndex]);
}
};
openGroup( app.activeDocument );
...but it does nothing - on the bright side, it doesn't cause an error message either. So I tried another one, closer to Michael's script, and changed 'OpenAllLayerSets' to 'OpenActiveLayerSets' and for some reason it doesn't change anything - all layer groups are unfolded instead of just the active group:
function openActiveLayerSets( parent ){
for(var
setIndex=0;setIndex<parent.layerSets.length;setIndex++){
app.activeDocument.activeLayer =
parent.layerSets[setIndex].layers[0];
openActiveLayerSets( parent.layerSets[setIndex]);
}
};
openActiveLayerSets( app.activeDocument );
Copy link to clipboard
Copied
I am not sure what you want to do. Normally selecting a layer that is inside a layer set opens the layerSet so if the activeLayer is inside a set that set should already be open. In other words if you just want to open one layerSet you don't need a recursive function like those above. Just select one layer.
If you want to open all the nested sets inside the selected set then pass that set as the argument( pass the set instead of the document ).
Copy link to clipboard
Copied
I'm attempting to open just one layer group, not all. So I would select the parent layer of that group (by parent layer I mean the top layer of the group which contains the small triangle icon to open/close the group), then run your script, and it opens the layer group like we want to, but it also opens all other layer groups in the document as well. I was looking for a way to open just one layer group that is currently selected, and leave all the other layer groups (if any) untouched. Then, I'll examine the code to perform the reverse function which would be to close the selected layer group (I hope I'm making sense!!) I've been modifying the script for a few hours, and trying to merge portions of other scripts in with it, but so far am not getting anywhere...I can show you all the modifications I've made but it might not be worthwhile since they aren't doing anything just yet..thanks
Copy link to clipboard
Copied
If a layerSet is the activeLayer and you just want to open that one layerSet do something like this.
if(app.activeDocument.activeLayer.typename == 'LayerSet' && app.activeDocument.activeLayer.layers.length>0) app.activeDocument.activeLayer = app.activeDocument.activeLayer.layers[0];
Copy link to clipboard
Copied
Michael, I'm so grateful - this is it. I have to thank you again.
I examined the code, and from what I can tell, it's stating that if the layer group has 1 layer or more (app.activeDocument.activeLayer.layers.length>0)), then it will activate the layer which is assigned as Index 0 (app.activeDocument.activeLayer.layers[0];).. and as a result, when the layer (Index 0) is activated, it automatically unfolds the group.
I'm guessing then, that since it's an indirect approach unfold the layer group, that there actually is no way to fold it up again?
This is kind of exciting, because I'm starting to figure out how this coding language works
edit- nevermind, I re-read this topic and can see that as of now there seems to be no way to fold a layer group back up. I'll keep searching in the meantime though..
Copy link to clipboard
Copied
Hello, I don't know if you seen my post or not , I've made a script that toggles open/close layer set. You can check it out here:
Copy link to clipboard
Copied
cbuliarca - these scritps are FANTASTIC. Every one of them is useful and solves a lot of problems I was trying to overcome with the layers panel. Only one script does not work for me: 'SelectByName'. Here is the error message I get when running the script:
Copy link to clipboard
Copied
Great, I'm glad they helped, I'm guessin it's a error with the ScriptUI listbox subitems, can you open the script aand modify all the lines that looks like this:
var mbSimpleSwitch = false;//make this true if you have problems with the UI
to this:
var mbSimpleSwitch = true;//make this true if you have problems with the UI
tell me if you will have this problem
Copy link to clipboard
Copied
it works!! I have been searching for a way to do this for a while now... this is the best script to search for layers.
the only difference is that my 'BCM FastSelection' looks different - it's missing the titles across the top ("Layer Name", "parents", Index", "isLayerSet?"). Also, I cannot left-click to select the layer. Here is the image I get:
Copy link to clipboard
Copied
this is wierd, on my computer I am able to select, to be honest I don't kow how I can solve this....probably it's another bug in the ScriptUI....what version of Photoshop are you using?
about the names ("Layer Name", "parents", Index", "isLayerSet?") on the top I've decided to not show them in this version of the ui, because I thought to go throw fields by pressing tab on the keyboard, and than select with the rightdown arrow and control or shift pressed.
If I would have added another text fiel with the names you would need to press tab once more. To pass throw that field.
But if you think that will help, I will add it.
Copy link to clipboard
Copied
Excellent! It works perfect now (I didn't know about hitting tab and/or using 'up/down' to select the layers). Thanks to you and everyone else here who helps with these awesome scripts- it's always very appreciated
Copy link to clipboard
Copied
question - how do we make sure that the columns are aligned properly? Right now, some of the columns are off-center. I noticed that if a layer name is more than 10 letters, then it begins to indent. So I tried changing all the "x:10" values in the script to a higher number but so far it hasn't worked.
Copy link to clipboard
Copied
till now I didn't found any fast good solution to align the columns in this version of ui. The problem is that the entire line is a string and the solution I found, but doesn't always work, is to create some tabs character to align the "|" character. The problem is that I can't exactly measure the text before the tabs. Because every character has his own width and even if I've made a table with each character's width the combination between them is actually not as expected. For example let's say I have the name "TAI"
the width of the entire text should be : 7(T)+1(the space)+9(A)+1(the space)+2(I) = 20 but actually it's less because the A character goes inside T so the width of them will be less.... probably I should create some conditional code for each special cases like this but this will probably be some tedious process, to find all of the combinations possible....
If anyone has another idea I will be grateful if he will share it.
Copy link to clipboard
Copied
that's fine... your script is excellent . It's much easier than using the normal Photoshop layers panel. I use it every day now.
Copy link to clipboard
Copied
Great, I'm glad it's helping you.
Copy link to clipboard
Copied
cbuliarca wrote:
The problem is that the entire line is a string...
Couldn't you set the font for that control to use a mono spaced font?
Copy link to clipboard
Copied
Hi Michael,
I never knew about the mono spaced fonts, I did a search and seen what's about, and seams to me that this kind of font could solve my problems. I will give it a try.
Thank you very much for your suggestion
Copy link to clipboard
Copied
following Michael's suggestion I've managed to adjust the columns for the second UI as well.
Thank you Michael.
You need to take the scripts again from my site:
Copy link to clipboard
Copied
hello cbuliarca, I have tried the updated script and am receiving this error:
Copy link to clipboard
Copied
just do the same thing with the
var mbSimpleSwitch = true;
The uploaded script uses the first version of interface but if you put the variable to true it will use the other version.