Modify the script

Explorer ,
May 05, 2021 May 05, 2021

Copy link to clipboard

Copied

In this Script, Please Modify it ,It is working good , There are 8 layers in psd template, The script have run enitre row layer sequentially But I wish left to right and again right to left, Please see the image below.

var newName = "Layer";
var ids = getLayersIDs(); // getting ids of selected layers

var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("width"));
r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var doc_w = executeActionGet(r).getUnitDoubleValue(stringIDToTypeID("width"));

var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("height"));
r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var doc_h = executeActionGet(r).getUnitDoubleValue(stringIDToTypeID("height"));

ids.sort(cmp);
function cmp(a, b)
{
try {
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("bounds"));
r.putIdentifier(stringIDToTypeID("layer"), a);
var b1 = executeActionGet(r).getObjectValue(stringIDToTypeID("bounds"));

var t1 = b1.getUnitDoubleValue(stringIDToTypeID("top"));
var l1 = b1.getUnitDoubleValue(stringIDToTypeID("left"));

var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("bounds"));
r.putIdentifier(stringIDToTypeID("layer"), b);
var b2 = executeActionGet(r).getObjectValue(stringIDToTypeID("bounds"));

var t2 = b2.getUnitDoubleValue(stringIDToTypeID("top"));
var l2 = b2.getUnitDoubleValue(stringIDToTypeID("left"));

t1 = 100-Math.round(doc_h/t1)*100;
t2 = 100-Math.round(doc_h/t2)*100;

var x1 = l1 + t1*doc_w;
var x2 = l2 + t2*doc_w;

return x1 - x2;
}
catch (e) { throw(e); }
}


//for each id in the list
for (var i = 0; i < ids.length; i++)
{
// select the layer first (well, artboard in this case)
selectById(ids[i]);

//rename it to "my name 1", "my name 2", etc
activeDocument.activeLayer.name = newName + " " + (i + 1);
}

// this will get IDs of selected layers/groups/artboards
function getLayersIDs()
{
var lyrs = [];
var lyr;
var ref = new ActionReference();
var desc;
var tempIndex;
var ref2;

ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("targetLayers"));
ref.putEnumerated(charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));

var targetLayers = executeActionGet(ref).getList(stringIDToTypeID("targetLayers"));
for (var i = 0; i < targetLayers.count; i++)
{
tempIndex = 0;
ref2 = new ActionReference();
try
{
activeDocument.backgroundLayer;
ref2.putIndex(charIDToTypeID('Lyr '), targetLayers.getReference(i).getIndex());
try
{
desc = executeActionGet(ref2);
tempIndex = desc.getInteger(stringIDToTypeID("itemIndex")) - 1;
}
catch (e)
{
tempIndex = 0;
}
}
catch (o)
{
ref2.putIndex(charIDToTypeID('Lyr '), targetLayers.getReference(i).getIndex() + 1);
desc = executeActionGet(ref2);
tempIndex = desc.getInteger(stringIDToTypeID("itemIndex"));
}

lyrs.push(desc.getInteger(stringIDToTypeID("layerID")));
}

return lyrs;
};

// this will select a layer by ID
function selectById(id)
{
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putIdentifier(charIDToTypeID('Lyr '), id);
desc1.putReference(charIDToTypeID('null'), ref1);
executeAction(charIDToTypeID('slct'), desc1, DialogModes.NO);
};

TOPICS
Actions and scripting, Bug, How to, Make It, Problem or error

Views

2.0K

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

correct answers 1 Correct Answer

Adobe Community Professional , May 05, 2021 May 05, 2021

Likes

Translate

Translate
LEGEND ,
May 05, 2021 May 05, 2021

Copy link to clipboard

Copied

If you want that script to be modified to operate differently you should make the modification yourself.  If you want a template like you show in the order that you show and not do any Photoshop scripting.  You need to find a Collage populating script the its easy to create templates for that will be populated in the order you desire.   You just need to create a simple collage template. 

 

My free Photoshop Photo Collage and Mockup Toolkit's  collage script would have no problem populating a template like you want.  You just need need to create the template psd/psdt  then point a collage populating script to the template and the folder your image are in. The image will be populated in File Name sort order into the collage template Image areas in the Image Area order you created in the template.  You control the Image  file processing order via file name and collage area by Image area alpha channel image numbers the  Image 1 to Image N.  N has a Photoshop limit of 53 alpha channes. So a collage template has a limit of 53 Images the cans be populated and the Image numbers need to be sequential 1,2,3,4,... there cans be no gaps if there  is no 3 only two image will be populated.

 

The template for your College would look like this:

image.png

JJMack

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
community guidelines
Explorer ,
May 05, 2021 May 05, 2021

Copy link to clipboard

Copied

Yes This is perfect, But which script to do, Please share the name of script. Is that possible to modify the script as per as your script..

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
community guidelines
LEGEND ,
May 05, 2021 May 05, 2021

Copy link to clipboard

Copied

Sure knock yourself out look at the script code in my script and modify that script with code in like my scripts have.  IMO you should read the help in my package to understand how my scripts work and learn all they can do.

 

Im my Package the followind scripts can be used to populate a collage template like you want.

  1. TestCollageTemplate.jsx - Used to test a Photo Collage Template while you are making it with Photoshop.
  2. InteractivePopulateCollage.jsx - Used to interactively populate Any Photo Collage template. Offers most user control inserting pictures and text.
  3. PopulateCollageTemplate.jsx - Used to Automatically populate a Photo Collage template and leave the populated copy open in Photoshop.
  4. BatchMultiImageCollage.jsx - Used to Automatically Batch Populate Any Photo Collage template with images in a source image folder. Easier to use than the interactive script. Saved collages can be tweaked.
JJMack

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
community guidelines
Adobe Community Professional ,
May 05, 2021 May 05, 2021

Copy link to clipboard

Copied

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
community guidelines
Adobe Community Professional ,
May 05, 2021 May 05, 2021

Copy link to clipboard

Copied

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
community guidelines
Adobe Community Professional ,
May 05, 2021 May 05, 2021

Copy link to clipboard

Copied

LATEST

Wow! There's 3rd one same thread? What a mess. If you're moderator combine them into one.

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