Skip to main content
Known Participant
June 3, 2020
Answered

PS Script to count number of vertical & horizontal frames in any psd template and rename doc

  • June 3, 2020
  • 2 replies
  • 4571 views

I have several psd templates in which I have few vertical frames and few horizontal frames in which i fills image and resize. I am not able to create a script which can count number of selected vertical and horizontal frames and duplicate the document with new name based on vertical and horizontal frame count. For example I have a template which contains 4 vertical frame layer and 2 horizontal frame layer. I want a script which will count them and duplicate the document and name duplicate doc 4v2htemplate. 
Is it possible using script ? Please help me 
Hi..sorry about my english..I have one template here...I selected the all six frame layers, out of which 2 are horizontal and 4 are vertical . I wish if a script could count the number of vertical and horizontal frame from selected layer and duplicate the document and give its name 4v2h page..Hope this will clear my above question ..Thank in advance

This topic has been closed for replies.
Correct answer r-bin
1. Instead of copying layers, use the command
app.activeDocument.duplicate (doc_name);

2. Initially nothing was said about the squares. Now you haven’t explained anything either - you won’t get anything. I am not extrasensory.
 
P.S. I also do not understand English well.

2 replies

Legend
June 3, 2020

select layers and try this

try {
    var r = new ActionReference();
    r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("targetLayersIDs"));
    r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

    var list = executeActionGet(r).getList(stringIDToTypeID("targetLayersIDs"));

    var h_cnt = 0;
    var v_cnt = 0;

    for (var i = 0; i < list.count; i++)
        {
        var r = new ActionReference();
        r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("bounds"));

        r.putIdentifier(stringIDToTypeID("layer"), list.getReference(i).getIdentifier());

        var w = executeActionGet(r).getObjectValue(stringIDToTypeID("bounds")).getUnitDoubleValue(stringIDToTypeID("width"));
        var h = executeActionGet(r).getObjectValue(stringIDToTypeID("bounds")).getUnitDoubleValue(stringIDToTypeID("height"));

        if (w > h) ++h_cnt;
        else       ++v_cnt;
        }

    var doc_name = "";

    if (v_cnt) doc_name += v_cnt+"v";
    if (h_cnt) doc_name += h_cnt+"h";

    doc_name += " page";

    var d = new ActionDescriptor();
    var r = new ActionReference();
    r.putClass(stringIDToTypeID("document"));
    d.putReference(stringIDToTypeID("null"), r);
    d.putString(stringIDToTypeID("name"), doc_name);
    var r1 = new ActionReference();
    r1.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
    d.putReference(stringIDToTypeID("using"), r1);
    d.putInteger(stringIDToTypeID("version"), 5);
    executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
    }
catch (e) { alert(e); }
    
Known Participant
June 4, 2020

Thank you  soooo much...it works same as I expected except just two thing.
First : In new document only selected frames  layers are present . I wish if script could duplicate the whole document with all the different layers preset in first document not just with selected frame layers (including background layer, text layers , png layers etc)
Second : It doesnt count square frame layer so can you make the script count square frame layers as Vertical layer.
Thank you so much and I hope you will understand my weak english.

Kukurykus
Legend
June 1, 2021

To nirmohi photoa art

If you still need it, post the script here in its normal form. And please do not write to me in private messages.


I suggested him exactly the same, but 'forgive' him his english. He barely understands that.

c.pfaffenbichler
Community Expert
Community Expert
June 3, 2020

Please provide a meaningful description including sample files or at the very least screenshots (which in turn include the pertinent Panels like Layers). 

 

What number of templates are you talking about that would justify Scripting the task? 

Known Participant
June 3, 2020


Hi..sorry about my english..I have one template here...I selected the all six frame layers, out of which 2 are horizontal and 4 are vertical . I wish if a script could count the number of vertical and horizontal frame from selected layer and duplicate the document and give its name 4v2h page..Hope this will clear my above question ..Thank in advance

JJMack
Community Expert
Community Expert
June 3, 2020

There is no standard for templates and mockups PSD file.  Therefor a script that can handle all possible way psd can create a composite like yours is impossible because template design vary all over the place.  My scripts have no problems counting the number of images the nets to be populated in my Collage and Mockup Templates.  For my scripts  require the template to adhere to met simple design rules for templates.  My template for your Collage would be created like this. My scripts would see they needed to populated 6 images. Saved as a PSD with whatever name I want,  A Script can Batch populate it or a script can interactively populate it. A script can automatically populated and leave it open  in Photoshop,  The scripts cans stamp filename on the populated images. and add layer styles to populated text and image layers.

Free Photoshop Photo Collage and Mockup Toolkit 

 

JJMack