Highlighted

Create and name a group using javascript

Community Beginner ,
Aug 22, 2020

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 );
  } 

 

 

Adobe Community Professional
Correct answer by r-bin | Adobe Community Professional
While creating a group, hold down the Alt key.
Enter your group name in the dialog.
You will see your name appear in a completely different place in the ScriptListener code. Also, that line of your code with "Group 1" is not needed at all.
 

Topics

Actions and scripting, How to, Problem or error, Windows

Views

48

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Create and name a group using javascript

Community Beginner ,
Aug 22, 2020

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 );
  } 

 

 

Adobe Community Professional
Correct answer by r-bin | Adobe Community Professional
While creating a group, hold down the Alt key.
Enter your group name in the dialog.
You will see your name appear in a completely different place in the ScriptListener code. Also, that line of your code with "Group 1" is not needed at all.
 

Topics

Actions and scripting, How to, Problem or error, Windows

Views

49

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Aug 22, 2020

Copy link to clipboard

Copied

While creating a group, hold down the Alt key.
Enter your group name in the dialog.
You will see your name appear in a completely different place in the ScriptListener code. Also, that line of your code with "Group 1" is not needed at all.
 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Community Beginner ,
Aug 22, 2020

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 ); 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...