• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Explorer ,
Jun 03, 2020 Jun 03, 2020

Copy link to clipboard

Copied

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

TOPICS
Actions and scripting

Views

3.3K

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
community guidelines

correct answers 2 Correct answers

Valorous Hero , Jun 03, 2020 Jun 03, 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(
...

Votes

Translate

Translate
Valorous Hero , Jun 04, 2020 Jun 04, 2020
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.

Votes

Translate

Translate
Adobe
Community Expert ,
Jun 03, 2020 Jun 03, 2020

Copy link to clipboard

Copied

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? 

Votes

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
community guidelines
Explorer ,
Jun 03, 2020 Jun 03, 2020

Copy link to clipboard

Copied

problem.jpg
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

Votes

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
community guidelines
Community Expert ,
Jun 03, 2020 Jun 03, 2020

Copy link to clipboard

Copied

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.

image.png

Free Photoshop Photo Collage and Mockup Toolkit 

 

JJMack

Votes

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
community guidelines
Valorous Hero ,
Jun 03, 2020 Jun 03, 2020

Copy link to clipboard

Copied

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

Votes

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
community guidelines
Explorer ,
Jun 03, 2020 Jun 03, 2020

Copy link to clipboard

Copied

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.Screenshot.jpg

Votes

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
community guidelines
Community Expert ,
Jun 03, 2020 Jun 03, 2020

Copy link to clipboard

Copied

I do not understand why you just do not save the document  as a PSD with the file name you want.   R-bin script requires you to select the Images layers so the script can get the bounds of the image layers. So it can tell portrait from landscape to know how many of each type you have.  Since you have to target the images layers you should know  how many of each you have targeted.  Just save a PSD fron the document with the file name you want instead of running that script. There is no need to duplicate the document all yoy need to do is save the document with the Filename you want.

JJMack

Votes

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
community guidelines
Valorous Hero ,
Jun 04, 2020 Jun 04, 2020

Copy link to clipboard

Copied

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.

Votes

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
community guidelines
Valorous Hero ,
Jun 01, 2021 Jun 01, 2021

Copy link to clipboard

Copied

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.

Votes

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
community guidelines
LEGEND ,
Jun 01, 2021 Jun 01, 2021

Copy link to clipboard

Copied

LATEST

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

Votes

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
community guidelines