JSX script: using Action Manager to several layers at once by IDs
Hi guys,
I have a custom logic-heavy export script that needs to hide layers before it begins execution. And I need to use logic to figure out which layers I need to hide, so using commands like Select All Layers and then Hide Selected Layers won't cut it here.
I have a working version of the script that uses recursive DOM traversal and hides the necessary layers that way, but the performance is ridiculously slow. Some of the files I need this to run on are 1000+ layers, and it can literally take a minute to simply loop through all layers.
By using Script Listener, I have found some code that does pretty much exactly what I need:
var idhide = stringIDToTypeID( "hide" );
var desc877 = new ActionDescriptor();
var idnull = stringIDToTypeID( "null" );
var list111 = new ActionList();
var ref384 = new ActionReference();
var idlayer = stringIDToTypeID( "layer" );
ref384.putName( idlayer, "Layer 1" );
ref384.putName( idlayer, "Layer 2" );
ref384.putName( idlayer, "Layer 3" );
ref384.putName( idlayer, "Layer 4" );
list111.putReference( ref384 );
desc877.putList( idnull, list111 );
executeAction( idhide, desc877, DialogModes.NO );
I can basically use this to take a list of layer names and hide them all instantly. Marvellous! Except layer names are not unique, so this falls apart completely if any two layers share the same name, and it's a complete deal breaker for my case.
I need a version of the same code that uses layer IDs instead of names, but I have no idea how to construct it or where to look for reference (I presume it doesn't exist). I have found some functions in Photoshop that generate code that looks very similar to what I'm looking for, i.e. selecting a bunch of layers creates this snippet:
...
var idlayerID = stringIDToTypeID( "layerID" );
var list110 = new ActionList();
list110.putInteger( 238 );
list110.putInteger( 239 );
list110.putInteger( 242 );
list110.putInteger( 250 );
desc872.putList( idlayerID, list110 );
...
But I haven't been able to come up with a way to use this mode of passing layers to the "hide" command. And even in the "select" command it doesn't seem to work despite appearing like this in the Script Listener's log.
Any ideas?
