Copy link to clipboard
Copied
I am trying to select two layers and create a group containing them. I want the group to have a specific name.
I have installed the scripting tool and did the actions within photoshop. The scripting tool gave me code that works fine with one exception, the group name is coming out as "Group 1". I cannot figure out why the group is getting the default name. One thing to note, in the script produced by the scripting tool, the group name was wrapped in triple quotes *desc264.putString( idNm, """Group 1""" );* . I changed Group 1 to My Group and have tried it with triple quotes and with it quoted inside single double quotes. Neither works. Here is the comple code, the problem line is the second to last line:
function createGroup(){
//Select first layer
var idslct = charIDToTypeID( "slct" );
var desc262 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref67 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
ref67.putName( idLyr, "My Layer 1" );
desc262.putReference( idnull, ref67 );
var idMkVs = charIDToTypeID( "MkVs" );
desc262.putBoolean( idMkVs, false );
var idLyrI = charIDToTypeID( "LyrI" );
var list41 = new ActionList();
list41.putInteger( 31 );
desc262.putList( idLyrI, list41 );
executeAction( idslct, desc262, DialogModes.NO );
// Select Second Layer
var idslct = charIDToTypeID( "slct" );
var desc263 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref68 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
ref68.putName( idLyr, "My Layer 2" );
desc263.putReference( idnull, ref68 );
var idselectionModifier = stringIDToTypeID( "selectionModifier" );
var idselectionModifierType = stringIDToTypeID( "selectionModifierType" );
var idaddToSelection = stringIDToTypeID( "addToSelection" );
desc263.putEnumerated( idselectionModifier, idselectionModifierType, idaddToSelection );
var idMkVs = charIDToTypeID( "MkVs" );
desc263.putBoolean( idMkVs, false );
var idLyrI = charIDToTypeID( "LyrI" );
var list42 = new ActionList();
list42.putInteger( 31 );
list42.putInteger( 32 );
desc263.putList( idLyrI, list42 );
executeAction( idslct, desc263, DialogModes.NO );
// Create the group
var idMk = charIDToTypeID( "Mk " );
var desc264 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref69 = new ActionReference();
var idlayerSection = stringIDToTypeID( "layerSection" );
ref69.putClass( idlayerSection );
desc264.putReference( idnull, ref69 );
var idFrom = charIDToTypeID( "From" );
var ref70 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref70.putEnumerated( idLyr, idOrdn, idTrgt );
desc264.putReference( idFrom, ref70 );
var idlayerSectionStart = stringIDToTypeID( "layerSectionStart" );
desc264.putInteger( idlayerSectionStart, 33 );
var idlayerSectionEnd = stringIDToTypeID( "layerSectionEnd" );
desc264.putInteger( idlayerSectionEnd, 34 );
var idNm = charIDToTypeID( "Nm " );
desc264.putString( idNm, "My Group" );
executeAction( idMk, desc264, DialogModes.NO );
}
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thanks, that got me what I need. For those following along another descriptor was required and had to be added to the desc264. Here are the additional lines of code which were required.
var desc346 = new ActionDescriptor();
var idNm = charIDToTypeID( "Nm " );
desc346.putString( idNm, "My Group" );
var idlayerSection = stringIDToTypeID( "layerSection" );
desc264.putObject( idUsng, idlayerSection, desc346 );
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more