Photoshop script that loop through layersets and creates new one based on layers name
Hi! I'm new with scripting and can't figure out how to make one that works for me.
Inside my psd file i have Groups with layers named *shutterstock*. I need to:
For every layerset:
1. Select *shutterstock* layer and every layer below until selection reach to another *shutterstock* layer
2. Group this selection and give it the name of Parent LayerSet.
3.Move created group from Parent LayerSet.
4. Continue loop with another *shutterstock* layer and so on
I have attached screenshot to visualize my goal.
At that point i figgured out how to select *shutterstock* layers:
if (app.documents.length > 0) {
// the file;
var doc = app.activeDocument;
// get number of layers;
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
for (var m = 0; m <= theNumber; m++) {
try {
var ref = new ActionReference();
ref.putIndex(charIDToTypeID("Lyr "), m);
var layerDesc = executeActionGet(ref);
var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));
// if not layer group collect values;
if (layerSet != "layerSectionEnd" /*&& layerSet != "layerSectionStart"*/ && isBackground != true) {
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theColor = layerDesc.getEnumerationValue(stringIDToTypeID("color"));
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
var visible = layerDesc.getBoolean(stringIDToTypeID("visible"));
if ((theName).match(/shutterstock/)) {
var desc = new ActionDescriptor()
var ref = new ActionReference()
ref.putIndex(stringIDToTypeID("layer"), m)
desc.putReference(stringIDToTypeID("null"), ref)
desc.putEnumerated(stringIDToTypeID("selectionModifier"), stringIDToTypeID("addToSelectionContinuous"), stringIDToTypeID("addToSelection"))
//desc.putEnumerated(stringIDToTypeID("selectionModifier"), stringIDToTypeID("selectionModifierType"), stringIDToTypeID("addToSelectionContinuous"))
executeAction(stringIDToTypeID("select"), desc, DialogModes.NO);
}
};
}
catch (e) { };
};
};
I can't figure out how to select other layers and group them.
It should be some kind of list or array?
From scripting listener i made some draft but i can't finalize it 😞
var idselect = stringIDToTypeID( "select" );
var desc386 = new ActionDescriptor();
var idnull = stringIDToTypeID( "null" );
var ref27 = new ActionReference();
var idlayer = stringIDToTypeID( "layer" );
ref27.putName( idlayer, "bow_4" );
desc386.putReference( idnull, ref27 );
var idselectionModifier = stringIDToTypeID( "selectionModifier" );
var idselectionModifierType = stringIDToTypeID( "selectionModifierType" );
var idaddToSelectionContinuous = stringIDToTypeID( "addToSelectionContinuous" );
desc386.putEnumerated( idselectionModifier, idselectionModifierType, idaddToSelectionContinuous );
var idmakeVisible = stringIDToTypeID( "makeVisible" );
desc386.putBoolean( idmakeVisible, false );
var idlayerID = stringIDToTypeID( "layerID" );
var list23 = new ActionList();
list23.putInteger( 3340 );
list23.putInteger( 3341 );
list23.putInteger( 3342 );
list23.putInteger( 3343 );
desc386.putList( idlayerID, list23 );
executeAction( idselect, desc386, DialogModes.NO );var desc = new ActionDescriptor()
var ref = new ActionReference()
ref.putIndex(stringIDToTypeID("layer"), m)
desc.putReference(stringIDToTypeID("null"), ref)
desc.putEnumerated(stringIDToTypeID("selectionModifier"), stringIDToTypeID("addToSelectionContinuous"), stringIDToTypeID("addToSelection"))
//desc.putEnumerated(stringIDToTypeID("selectionModifier"), stringIDToTypeID("selectionModifierType"), stringIDToTypeID("addToSelectionContinuous"))
var idmake = stringIDToTypeID("make");
var idnull = stringIDToTypeID("null");
var idlayerSection = stringIDToTypeID("layerSection");
var idfrom = stringIDToTypeID("from");
var idlayer = stringIDToTypeID("layer");
var idordinal = stringIDToTypeID("ordinal");
var idtargetEnum = stringIDToTypeID("targetEnum");
var idcolor = stringIDToTypeID("color");
var idred = stringIDToTypeID("red");
var idlayerSection = stringIDToTypeID("layerSection");
var idusing = stringIDToTypeID("using");
var idname = stringIDToTypeID("name");
var idlayerSectionStart = stringIDToTypeID("layerSectionStart");
var idlayerSectionEnd = stringIDToTypeID("layerSectionEnd");
var desc1695 = new ActionDescriptor();
var ref155 = new ActionReference();
ref155.putClass(idlayerSection);
desc1695.putReference(idnull, ref155);
var ref156 = new ActionReference();
ref156.putEnumerated(idlayer, idordinal, idtargetEnum);
desc1695.putReference(idfrom, ref156);
var desc1696 = new ActionDescriptor();
//desc1696.putEnumerated(idcolor, idcolor, idred);
desc1695.putObject(idusing, idlayerSection, desc1696);
desc1695.putInteger(idlayerSectionStart, 3839);
desc1695.putInteger(idlayerSectionEnd, 3840);
desc1695.putString(idname, """Group 1""");
//executeAction(idmake, desc1695, DialogModes.NO);
executeAction(stringIDToTypeID("select"), desc, DialogModes.NO);






