Skip to main content
Known Participant
October 22, 2021
Answered

Can't run the script in selected layers

  • October 22, 2021
  • 2 replies
  • 873 views

I can't do Selected Layers to Frame from layer, if i select 4 layer and run the my script, getting a error..

Anyone help me 

Here is my script 

#target photoshop
//
// Convt.jsx
//

//
// Generated Fri Oct 22 2021 16:03:19 GMT+0530
//

cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };

//
//==================== Convt ==============
//
function Convt() {
  // Make
  function step1(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putClass(sTID("framedGroupSection"));
    desc1.putReference(cTID('null'), ref1);
    var ref2 = new ActionReference();
    ref2.putName(cTID('Lyr '), "Layer");
    desc1.putReference(cTID('From'), ref2);
    desc1.putInteger(sTID("layerSectionStart"), 135);
    desc1.putInteger(sTID("layerSectionEnd"), 136);
    desc1.putString(cTID('Nm  '), "Frame 2");
    executeAction(cTID('Mk  '), desc1, dialogMode);
  };

  step1();      // Make
};



//=========================================
//                    Convt.main
//=========================================
//

Convt.main = function () {
  Convt();
};

Convt.main();

// EOF

"Convt.jsx"
// EOF

 

This topic has been closed for replies.
Correct answer jazz-y

The problem with your code is that it refers to a predefined range of layers. To solve this, replace your step1 function code with this one:

 

  function step1(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putClass(sTID("framedGroupSection"));
    desc1.putReference(cTID('null'), ref1);
    var ref2 = new ActionReference();
    ref2.putEnumerated(sTID("layer"), sTID("ordinal"), sTID("targetEnum"));
    desc1.putReference(cTID('From'), ref2);
    executeAction(cTID('Mk  '), desc1, dialogMode);
  };

 

2 replies

jazz-yCorrect answer
Legend
October 22, 2021

The problem with your code is that it refers to a predefined range of layers. To solve this, replace your step1 function code with this one:

 

  function step1(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putClass(sTID("framedGroupSection"));
    desc1.putReference(cTID('null'), ref1);
    var ref2 = new ActionReference();
    ref2.putEnumerated(sTID("layer"), sTID("ordinal"), sTID("targetEnum"));
    desc1.putReference(cTID('From'), ref2);
    executeAction(cTID('Mk  '), desc1, dialogMode);
  };

 

Sriya69Author
Known Participant
October 22, 2021

Wow greate, thanku so much sir Worked it , I have replaced to function

Kukurykus
Legend
October 22, 2021

Don't forget to mark one of the replies as correct solution 😉

JJMack
Community Expert
Community Expert
October 22, 2021

Your function is bad.  I used the script listener to record a Step frame from layers like you did.  And used then Clean SL script the convert the log to more readable code. If you look at your function it has hard coded layer ID and frame name.  It is an action step with hard coded settings.   You need to make the setting parameters that you  passed to your function.  Your script will need toe retrieve the layer selected ID and come up withe a frame name like Photoshop does (Frame 1)  for the Action step.   I only had two layers targeted when I made the frame. So I do not know it you need to pass all the Id  or just the start and end id.  For I do not use Adobe Frame I use my own method for framing images since CS2 and do not frame composites of Layers.  Adobe use place in frames so Photoshop  made your selected layers a Smart object.. It may be easier to create the smart object first then make the frame..  Here is the Function Clean SL made from the Scriptlistener code.  You can see the Layer ID and the Frame name that Clean SL extracted from the script listener code. 

// =======================================================
make(12, 13, "Frame 1");
function make(layerSectionStart, layerSectionEnd, name2) {
	var descriptor = new ActionDescriptor();
	var reference = new ActionReference();
	var reference2 = new ActionReference();

	reference.putClass( stringIDToTypeID( "framedGroupSection" ));
	descriptor.putReference( charIDToTypeID( "null" ), reference );
	reference2.putName( stringIDToTypeID( "layer" ), "Layer 1" );
	descriptor.putReference( stringIDToTypeID( "from" ), reference2 );
	descriptor.putInteger( stringIDToTypeID( "layerSectionStart" ), layerSectionStart );
	descriptor.putInteger( stringIDToTypeID( "layerSectionEnd" ), layerSectionEnd );
	descriptor.putString( stringIDToTypeID( "name" ), name2 );
	executeAction( stringIDToTypeID( "make" ), descriptor, DialogModes.NO );
}

 

JJMack
Sriya69Author
Known Participant
October 22, 2021

Yes, I am new in PS Script Could you provide some tips for learn javascript of PS..

And your script is also find thanku so much

Kukurykus
Legend
October 22, 2021