Skip to main content
Known Participant
August 30, 2021
Answered

Make a Frame all Layer in PS Script

  • August 30, 2021
  • 2 replies
  • 1670 views

I have 5Layers, I want make Convert to Frame 5Layers ??

Here is script !!

 

#target photoshop
//
// ST.jsx
//

//
// Generated Tue Aug 31 2021 03:33:47 GMT+0530
//

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

//
//==================== ST ==============
//
function ST() {
  // 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);
    desc1.putString(cTID('Nm  '), "HFrame");
    var desc2 = new ActionDescriptor();
    desc2.putDouble(cTID('Top '), 1800);
    desc2.putDouble(cTID('Left'), 2719);
    desc2.putDouble(cTID('Btom'), 3446);
    desc2.putDouble(cTID('Rght'), 5268);
    desc1.putObject(sTID("framedGroupRect"), sTID("classFloatRect"), desc2);
    desc1.putDouble(sTID("framedGroupPathResolution"), 300);
    var desc3 = new ActionDescriptor();
    var list1 = new ActionList();
    var desc4 = new ActionDescriptor();
    desc4.putEnumerated(sTID("shapeOperation"), sTID("shapeOperation"), cTID('Add '));
    var list2 = new ActionList();
    var desc5 = new ActionDescriptor();
    desc5.putBoolean(cTID('Clsp'), true);
    var list3 = new ActionList();
    var desc6 = new ActionDescriptor();
    var desc7 = new ActionDescriptor();
    desc7.putUnitDouble(cTID('Hrzn'), cTID('#Pxl'), 2724);
    desc7.putUnitDouble(cTID('Vrtc'), cTID('#Pxl'), 1800.5);
    desc6.putObject(cTID('Anch'), cTID('Pnt '), desc7);
    var desc8 = new ActionDescriptor();
    desc8.putUnitDouble(cTID('Hrzn'), cTID('#Pxl'), 2724);
    desc8.putUnitDouble(cTID('Vrtc'), cTID('#Pxl'), 1800.5);
    desc6.putObject(cTID('Fwd '), cTID('Pnt '), desc8);
    var desc9 = new ActionDescriptor();
    desc9.putUnitDouble(cTID('Hrzn'), cTID('#Pxl'), 2721.238577);
    desc9.putUnitDouble(cTID('Vrtc'), cTID('#Pxl'), 1800.5);
    desc6.putObject(cTID('Bwd '), cTID('Pnt '), desc9);
    desc6.putBoolean(cTID('Smoo'), true);
    list3.putObject(cTID('Pthp'), desc6);
    var desc10 = new ActionDescriptor();
    var desc11 = new ActionDescriptor();
    desc11.putUnitDouble(cTID('Hrzn'), cTID('#Pxl'), 5263);
    desc11.putUnitDouble(cTID('Vrtc'), cTID('#Pxl'), 1800.5);
    desc10.putObject(cTID('Anch'), cTID('Pnt '), desc11);
    var desc12 = new ActionDescriptor();
    desc12.putUnitDouble(cTID('Hrzn'), cTID('#Pxl'), 5265.761423);
    desc12.putUnitDouble(cTID('Vrtc'), cTID('#Pxl'), 1800.5);
    desc10.putObject(cTID('Fwd '), cTID('Pnt '), desc12);
    var desc13 = new ActionDescriptor();
    desc13.putUnitDouble(cTID('Hrzn'), cTID('#Pxl'), 5263);
    desc13.putUnitDouble(cTID('Vrtc'), cTID('#Pxl'), 1800.5);
    desc10.putObject(cTID('Bwd '), cTID('Pnt '), desc13);
    desc10.putBoolean(cTID('Smoo'), true);
    list3.putObject(cTID('Pthp'), desc10);
    var desc14 = new ActionDescriptor();
    var desc15 = new ActionDescriptor();
    desc15.putUnitDouble(cTID('Hrzn'), cTID('#Pxl'), 5268);
    desc15.putUnitDouble(cTID('Vrtc'), cTID('#Pxl'), 1805.5);
    desc14.putObject(cTID('Anch'), cTID('Pnt '), desc15);
    var desc16 = new ActionDescriptor();
    desc16.putUnitDouble(cTID('Hrzn'), cTID('#Pxl'), 5268);
    desc16.putUnitDouble(cTID('Vrtc'), cTID('#Pxl'), 1805.5);
    desc14.putObject(cTID('Fwd '), cTID('Pnt '), desc16);
    var desc17 = new ActionDescriptor();
    desc17.putUnitDouble(cTID('Hrzn'), cTID('#Pxl'), 5268);
    desc17.putUnitDouble(cTID('Vrtc'), cTID('#Pxl'), 1802.738577);
    desc14.putObject(cTID('Bwd '), cTID('Pnt '), desc17);
    desc14.putBoolean(cTID('Smoo'), true);
    list3.putObject(cTID('Pthp'), desc14);
    var desc18 = new ActionDescriptor();
    var desc19 = new ActionDescriptor();
    desc19.putUnitDouble(cTID('Hrzn'), cTID('#Pxl'), 5268);
    desc19.putUnitDouble(cTID('Vrtc'), cTID('#Pxl'), 3441);
    desc18.putObject(cTID('Anch'), cTID('Pnt '), desc19);
    var desc20 = new ActionDescriptor();
    desc20.putUnitDouble(cTID('Hrzn'), cTID('#Pxl'), 5268);
    desc20.putUnitDouble(cTID('Vrtc'), cTID('#Pxl'), 3443.761423);
    desc18.putObject(cTID('Fwd '), cTID('Pnt '), desc20);
    var desc21 = new ActionDescriptor();
    desc21.putUnitDouble(cTID('Hrzn'), cTID('#Pxl'), 5268);
    desc21.putUnitDouble(cTID('Vrtc'), cTID('#Pxl'), 3441);
    desc18.putObject(cTID('Bwd '), cTID('Pnt '), desc21);
    desc18.putBoolean(cTID('Smoo'), true);
    list3.putObject(cTID('Pthp'), desc18);
    var desc22 = new ActionDescriptor();
    var desc23 = new ActionDescriptor();
    desc23.putUnitDouble(cTID('Hrzn'), cTID('#Pxl'), 5263);
    desc23.putUnitDouble(cTID('Vrtc'), cTID('#Pxl'), 3446);
    desc22.putObject(cTID('Anch'), cTID('Pnt '), desc23);
    var desc24 = new ActionDescriptor();
    desc24.putUnitDouble(cTID('Hrzn'), cTID('#Pxl'), 5263);
    desc24.putUnitDouble(cTID('Vrtc'), cTID('#Pxl'), 3446);
    desc22.putObject(cTID('Fwd '), cTID('Pnt '), desc24);
    var desc25 = new ActionDescriptor();
    desc25.putUnitDouble(cTID('Hrzn'), cTID('#Pxl'), 5265.761423);
    desc25.putUnitDouble(cTID('Vrtc'), cTID('#Pxl'), 3446);
    desc22.putObject(cTID('Bwd '), cTID('Pnt '), desc25);
    desc22.putBoolean(cTID('Smoo'), true);
    list3.putObject(cTID('Pthp'), desc22);
    var desc26 = new ActionDescriptor();
    var desc27 = new ActionDescriptor();
    desc27.putUnitDouble(cTID('Hrzn'), cTID('#Pxl'), 2724);
    desc27.putUnitDouble(cTID('Vrtc'), cTID('#Pxl'), 3446);
    desc26.putObject(cTID('Anch'), cTID('Pnt '), desc27);
    var desc28 = new ActionDescriptor();
    desc28.putUnitDouble(cTID('Hrzn'), cTID('#Pxl'), 2721.238577);
    desc28.putUnitDouble(cTID('Vrtc'), cTID('#Pxl'), 3446);
    desc26.putObject(cTID('Fwd '), cTID('Pnt '), desc28);
    var desc29 = new ActionDescriptor();
    desc29.putUnitDouble(cTID('Hrzn'), cTID('#Pxl'), 2724);
    desc29.putUnitDouble(cTID('Vrtc'), cTID('#Pxl'), 3446);
    desc26.putObject(cTID('Bwd '), cTID('Pnt '), desc29);
    desc26.putBoolean(cTID('Smoo'), true);
    list3.putObject(cTID('Pthp'), desc26);
    var desc30 = new ActionDescriptor();
    var desc31 = new ActionDescriptor();
    desc31.putUnitDouble(cTID('Hrzn'), cTID('#Pxl'), 2719);
    desc31.putUnitDouble(cTID('Vrtc'), cTID('#Pxl'), 3441);
    desc30.putObject(cTID('Anch'), cTID('Pnt '), desc31);
    var desc32 = new ActionDescriptor();
    desc32.putUnitDouble(cTID('Hrzn'), cTID('#Pxl'), 2719);
    desc32.putUnitDouble(cTID('Vrtc'), cTID('#Pxl'), 3441);
    desc30.putObject(cTID('Fwd '), cTID('Pnt '), desc32);
    var desc33 = new ActionDescriptor();
    desc33.putUnitDouble(cTID('Hrzn'), cTID('#Pxl'), 2719);
    desc33.putUnitDouble(cTID('Vrtc'), cTID('#Pxl'), 3443.761423);
    desc30.putObject(cTID('Bwd '), cTID('Pnt '), desc33);
    desc30.putBoolean(cTID('Smoo'), true);
    list3.putObject(cTID('Pthp'), desc30);
    var desc34 = new ActionDescriptor();
    var desc35 = new ActionDescriptor();
    desc35.putUnitDouble(cTID('Hrzn'), cTID('#Pxl'), 2719);
    desc35.putUnitDouble(cTID('Vrtc'), cTID('#Pxl'), 1805.5);
    desc34.putObject(cTID('Anch'), cTID('Pnt '), desc35);
    var desc36 = new ActionDescriptor();
    desc36.putUnitDouble(cTID('Hrzn'), cTID('#Pxl'), 2719);
    desc36.putUnitDouble(cTID('Vrtc'), cTID('#Pxl'), 1802.738577);
    desc34.putObject(cTID('Fwd '), cTID('Pnt '), desc36);
    var desc37 = new ActionDescriptor();
    desc37.putUnitDouble(cTID('Hrzn'), cTID('#Pxl'), 2719);
    desc37.putUnitDouble(cTID('Vrtc'), cTID('#Pxl'), 1805.5);
    desc34.putObject(cTID('Bwd '), cTID('Pnt '), desc37);
    desc34.putBoolean(cTID('Smoo'), true);
    list3.putObject(cTID('Pthp'), desc34);
    desc5.putList(cTID('Pts '), list3);
    list2.putObject(cTID('Sbpl'), desc5);
    desc4.putList(cTID('SbpL'), list2);
    list1.putObject(cTID('PaCm'), desc4);
    desc3.putList(sTID("pathComponents"), list1);
    desc1.putObject(sTID("framedGroupPath"), sTID("pathClass"), desc3);
    desc1.putInteger(sTID("framedGroupType"), 4);
    desc1.putBoolean(sTID("LockPPI"), false);
    desc1.putDouble(sTID("PreferredResolution"), 300);
    desc1.putString(sTID("SavedIteratedName"), "");
    executeAction(cTID('Mk  '), desc1, dialogMode);
  };

  step1();      // Make
};



//=========================================
//                    ST.main
//=========================================
//

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

ST.main();

// EOF

"ST.jsx"
// EOF

 

This topic has been closed for replies.
Correct answer Stephen Marsh

The following script will add a frame at the document bounds to all top level layers (code modifed to work in reverse layer order since the original screenshot).

 

 

/*
Add Frame To All Layers.jsx
v1.1 - Stephen Marsh, 5th August 2021

https://community.adobe.com/t5/photoshop-ecosystem-discussions/make-a-frame-all-layer-in-ps-script/td-p/12352583
Make a Frame all Layer in PS Script
*/

#target photoshop

function main() {
    // Save the current ruler units and set to pixels
    var savedRuler = app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.PIXELS;

    app.activeDocument.activeLayer = app.activeDocument.layers[app.activeDocument.layers.length - 1];

    // Loop forward over top level layers
    // for (var i = 0; i < app.activeDocument.layers.length; i++) {
    // Loop backward over top level layers
    for (var i = app.activeDocument.layers.length - 1; i >= 0; i--) {
        try {
            app.activeDocument.activeLayer = app.activeDocument.layers[i];
            layerFrameFromDocWidthHeight(4, 5, "Frame 1", 0, 0, app.activeDocument.height.value, app.activeDocument.width.value, 1, false, 300, "");
        } catch (e) { }
    }

    // Restore the ruler units
    app.preferences.rulerUnits = savedRuler;

    function layerFrameFromDocWidthHeight(layerSectionStart, layerSectionEnd, name2, top, left, bottom, right, framedGroupType, LockPPI, PreferredResolution, SavedIteratedName) {
        var layerName = app.activeDocument.activeLayer.name;
        var s2t = function (s) {
            return app.stringIDToTypeID(s);
        };
        var descriptor = new ActionDescriptor();
        var descriptor2 = new ActionDescriptor();
        var reference = new ActionReference();
        var reference2 = new ActionReference();
        reference.putClass(s2t("framedGroupSection"));
        descriptor.putReference(s2t("null"), reference);
        reference2.putName(s2t("layer"), app.activeDocument.activeLayer.name);
        descriptor.putReference(s2t("from"), reference2);
        descriptor.putInteger(s2t("layerSectionStart"), layerSectionStart);
        descriptor.putInteger(s2t("layerSectionEnd"), layerSectionEnd);
        descriptor.putString(s2t("name"), name2);
        descriptor2.putDouble(s2t("top"), top);
        descriptor2.putDouble(s2t("left"), left);
        descriptor2.putDouble(s2t("bottom"), bottom);
        descriptor2.putDouble(s2t("right"), right);
        descriptor.putObject(s2t("framedGroupRect"), s2t("classFloatRect"), descriptor2);
        descriptor.putInteger(s2t("framedGroupType"), framedGroupType);
        descriptor.putBoolean(s2t("LockPPI"), LockPPI);
        descriptor.putDouble(s2t("PreferredResolution"), PreferredResolution);
        descriptor.putString(s2t("SavedIteratedName"), SavedIteratedName);
        executeAction(s2t("make"), descriptor, DialogModes.NO);
        app.activeDocument.activeLayer.name = layerName;
    }
}
app.activeDocument.suspendHistory("Add Frame To All Layers.jsx", "main()");

 

EDIT: Original code updated 5th September 2021

2 replies

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
August 31, 2021

The following script will add a frame at the document bounds to all top level layers (code modifed to work in reverse layer order since the original screenshot).

 

 

/*
Add Frame To All Layers.jsx
v1.1 - Stephen Marsh, 5th August 2021

https://community.adobe.com/t5/photoshop-ecosystem-discussions/make-a-frame-all-layer-in-ps-script/td-p/12352583
Make a Frame all Layer in PS Script
*/

#target photoshop

function main() {
    // Save the current ruler units and set to pixels
    var savedRuler = app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.PIXELS;

    app.activeDocument.activeLayer = app.activeDocument.layers[app.activeDocument.layers.length - 1];

    // Loop forward over top level layers
    // for (var i = 0; i < app.activeDocument.layers.length; i++) {
    // Loop backward over top level layers
    for (var i = app.activeDocument.layers.length - 1; i >= 0; i--) {
        try {
            app.activeDocument.activeLayer = app.activeDocument.layers[i];
            layerFrameFromDocWidthHeight(4, 5, "Frame 1", 0, 0, app.activeDocument.height.value, app.activeDocument.width.value, 1, false, 300, "");
        } catch (e) { }
    }

    // Restore the ruler units
    app.preferences.rulerUnits = savedRuler;

    function layerFrameFromDocWidthHeight(layerSectionStart, layerSectionEnd, name2, top, left, bottom, right, framedGroupType, LockPPI, PreferredResolution, SavedIteratedName) {
        var layerName = app.activeDocument.activeLayer.name;
        var s2t = function (s) {
            return app.stringIDToTypeID(s);
        };
        var descriptor = new ActionDescriptor();
        var descriptor2 = new ActionDescriptor();
        var reference = new ActionReference();
        var reference2 = new ActionReference();
        reference.putClass(s2t("framedGroupSection"));
        descriptor.putReference(s2t("null"), reference);
        reference2.putName(s2t("layer"), app.activeDocument.activeLayer.name);
        descriptor.putReference(s2t("from"), reference2);
        descriptor.putInteger(s2t("layerSectionStart"), layerSectionStart);
        descriptor.putInteger(s2t("layerSectionEnd"), layerSectionEnd);
        descriptor.putString(s2t("name"), name2);
        descriptor2.putDouble(s2t("top"), top);
        descriptor2.putDouble(s2t("left"), left);
        descriptor2.putDouble(s2t("bottom"), bottom);
        descriptor2.putDouble(s2t("right"), right);
        descriptor.putObject(s2t("framedGroupRect"), s2t("classFloatRect"), descriptor2);
        descriptor.putInteger(s2t("framedGroupType"), framedGroupType);
        descriptor.putBoolean(s2t("LockPPI"), LockPPI);
        descriptor.putDouble(s2t("PreferredResolution"), PreferredResolution);
        descriptor.putString(s2t("SavedIteratedName"), SavedIteratedName);
        executeAction(s2t("make"), descriptor, DialogModes.NO);
        app.activeDocument.activeLayer.name = layerName;
    }
}
app.activeDocument.suspendHistory("Add Frame To All Layers.jsx", "main()");

 

EDIT: Original code updated 5th September 2021

MXKSAuthor
Known Participant
September 3, 2021

Thanku so much @Stephen Marsh  Perfect Working , I have seen just now because i had out of station 

Participating Frequently
June 21, 2024

The script was explicity written to apply the frame to the document bounds. You can of course modify it to suit your unspecified and or belatedly stated requirements.

 

I have not tested, perhaps something like:

 

///// Do stuff to selected layers /////
var theBounds = app.activeDocument.activeLayer.bounds;
layerFrameFromDocWidthHeight(4, 5, "Frame 1", theBounds[1], theBounds[0], theBounds[3], theBounds[2], 1, false, 300, "");
///////////////////////////////////////

 

 


anyone help to Make a Frame all Layer in PS Scriptx with retain effects of layers like shadow border etc.

Stephen Marsh
Community Expert
Community Expert
August 31, 2021

It appears that you have converted an action to jsx using xtools.

 

I had a new doc created with 5 empty layers.

 

Your code has added a new 6th layer with a frame. I was expecting that one or more of the existing layers would be converted to a frame.

 

Can you provide a cropped screenshot of the layer panel, before and after so that the forum can visually understand what you are trying to achieve?

 

What should the frame size be? A fixed numeric value? The document size? The bounding size of layer content? Artboard size etc?