Skip to main content
Inspiring
August 10, 2022
Answered

Select group below currently selected group using javascript

  • August 10, 2022
  • 4 replies
  • 588 views

How its possible to select group below currently selected group using javascript? For example i selected group Left and i need to create script which will automatically select group below (Front).

 

This topic has been closed for replies.
Correct answer Stephen Marsh

Easy if the group is visible and collapsed, keyboard shortcut of OPT/ALT + [ (which can be recorded into an Action or ScriptingListner can record the code).

 

However, if expanded, a script would be required as mentioned by @c.pfaffenbichler 

4 replies

Stephen Marsh
Community Expert
Community Expert
August 15, 2022
Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
August 10, 2022

Easy if the group is visible and collapsed, keyboard shortcut of OPT/ALT + [ (which can be recorded into an Action or ScriptingListner can record the code).

 

However, if expanded, a script would be required as mentioned by @c.pfaffenbichler 

milevicAuthor
Inspiring
August 12, 2022

Thanks, i copy this shortcut from SL and it works ok

var idselect = stringIDToTypeID( "select" );
    var desc23 = new ActionDescriptor();
    var idnull = stringIDToTypeID( "null" );
        var ref18 = new ActionReference();
        var idlayer = stringIDToTypeID( "layer" );
        var idordinal = stringIDToTypeID( "ordinal" );
        var idbackwardEnum = stringIDToTypeID( "backwardEnum" );
        ref18.putEnumerated( idlayer, idordinal, idbackwardEnum );
    desc23.putReference( idnull, ref18 );
    var idmakeVisible = stringIDToTypeID( "makeVisible" );
    desc23.putBoolean( idmakeVisible, false );
    var idlayerID = stringIDToTypeID( "layerID" );
        var list13 = new ActionList();
        list13.putInteger( 553 );
    desc23.putList( idlayerID, list13 );
executeAction( idselect, desc23, DialogModes.NO );
Stephen Marsh
Community Expert
Community Expert
August 12, 2022

@milevic – fantastic, that is how one starts! The following steps are realising that this can be put into a function and swapping out hard-coded values for variables... Then you'll have a single function that can use a parameter to select either forwards or backwards. I only mention this as it took me a little while before this became obvious (as I am self-taught with no formal JS or programming background).

 

By itself, this will have problems with an expanded group with child content or non-visible layers. But as long as the groups are collapsed and visible, there shouldn't be any issues.

c.pfaffenbichler
Community Expert
Community Expert
August 10, 2022

Do you want to work with DOM code or AM code? 

• In the first case you could iterate through the activeLayer’s parent’s layerSets (unless you also want to select the next-lower groups outside the group’s parent). 

• In the latter case you could get the itemIndex of the selected Group and then work down from that until you hit the next layerSectionStart after the layerSectionEnd of the selected group. 

c.pfaffenbichler
Community Expert
Community Expert
August 10, 2022

What is the problem? 

milevicAuthor
Inspiring
August 10, 2022

I complete some other scripts on currently active group (left) and i want to move on a group bellow (front) but i dont know how? P.S. Names of groups are not always same.