Layer Sequentially From left to Right

Community Beginner ,
May 04, 2021 May 04, 2021

Copy link to clipboard

Copied

In this script, Button To Top Rename Sequentially, But I wish Left to Right Rename Sequentially, Is that possible, Please Help me sir

Thanks in Advance

 

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

//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, How to, Make It, Problem or error

Views

8.7K

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 04, 2021 May 04, 2021

Copy link to clipboard

Copied

Well.

Here, suppose you have an eight-layer document.

How are you going to rename the layers (rectangles, but layers can come from several parts too)?

Untitled-1.png

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
Community Beginner ,
May 04, 2021 May 04, 2021

Copy link to clipboard

Copied

In this condition, Every template between gaps and i want to select layer from left to right .

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 04, 2021 May 04, 2021

Copy link to clipboard

Copied

Untitled-2.png

 

The layers are numbered from left to right.

Confirm or refute the sequence, but only reasonably, and not like this: "i want ...".

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
Community Beginner ,
May 04, 2021 May 04, 2021

Copy link to clipboard

Copied

Yes, I want this, Please How to create script

Please help me

Thanks in Advance

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 04, 2021 May 04, 2021

Copy link to clipboard

Copied

In your script, right after the line

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

 

paste this code:

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 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 l2 = b2.getUnitDoubleValue(stringIDToTypeID("left"));

        return l1 > l2;
        }
    catch (e) { throw(e); }
    }

 

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
Community Beginner ,
May 04, 2021 May 04, 2021

Copy link to clipboard

Copied

This is right ,Please check it

 

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

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 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 l2 = b2.getUnitDoubleValue(stringIDToTypeID("left"));

return l1 > l2;
}
catch (e) { throw(e); }
}


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

 

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
Community Beginner ,
May 04, 2021 May 04, 2021

Copy link to clipboard

Copied

Please Add The Rename Each Layer From Left to right like layer1,layer2,layer3 etc

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 04, 2021 May 04, 2021

Copy link to clipboard

Copied

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

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 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 l2 = b2.getUnitDoubleValue(stringIDToTypeID("left"));

        return l1 - l2;
        }
    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);
};

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 04, 2021 May 04, 2021

Copy link to clipboard

Copied

Yes, sort of like that. But your code is not complete as in the first post. It won't work.

 

There I have a mistake !!!!!!!!!.

Correct

return l1> l2;

to the

return l1 - l2;

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
Community Beginner ,
May 04, 2021 May 04, 2021

Copy link to clipboard

Copied

Yes, It's perfect working, But one thing I want to this right to left, You have button to top,

Please see the image

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
Community Beginner ,
May 04, 2021 May 04, 2021

Copy link to clipboard

Copied

Modify the script, Please see the image below

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 04, 2021 May 04, 2021

Copy link to clipboard

Copied

OK

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

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
Community Beginner ,
May 04, 2021 May 04, 2021

Copy link to clipboard

Copied

Yes, Thanku so much But entire left right now, Please see the image below,

Please modify it

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 04, 2021 May 04, 2021

Copy link to clipboard

Copied

Where did you see there from left to right and from top to bottom? I see no logic.

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
Community Beginner ,
May 04, 2021 May 04, 2021

Copy link to clipboard

Copied

Everyting is ok, but one thing is entire left to right , Please see the image...

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 04, 2021 May 04, 2021

Copy link to clipboard

Copied

I do not understand you. Be clearer.

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
Community Beginner ,
May 04, 2021 May 04, 2021

Copy link to clipboard

Copied

Yes everything is fine, But I will put on 12x36 page. The script is entire left so I with 12x18 page is good working but 12x36 page is enitre left so

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 04, 2021 May 04, 2021

Copy link to clipboard

Copied

Post the PSD with the problem. I'll see.

And explain what you are doing, which layers you are selecting.

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
Community Beginner ,
May 04, 2021 May 04, 2021

Copy link to clipboard

Copied

I have put on 12x36 page, The script is entire left Please check it.

1:- Create 12x36 Page

2:- Create 8 Layer

3:- Run the Script

4:- The result is entire left to right.

 

12x18 Page is good working and 4 layer also good working, Just 8 Layer to entire left to right,

Please see the image below

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
Community Beginner ,
May 04, 2021 May 04, 2021

Copy link to clipboard

Copied

I have given the the psd below please check it, The psd entire left to right, I wish see image below right

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
Community Beginner ,
May 04, 2021 May 04, 2021

Copy link to clipboard

Copied

Did you understand that

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
Community Beginner ,
May 04, 2021 May 04, 2021

Copy link to clipboard

Copied

Did you check it , let me know Did you understand the problem

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 04, 2021 May 04, 2021

Copy link to clipboard

Copied

You were asked:

quote

Confirm or refute the sequence, but only reasonably, and not like this: "i want ...".

 

Then you replied:

quote

Yes, I want this


And now you act like nor the question was asked, nor you answered to 😄

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
Community Beginner ,
May 04, 2021 May 04, 2021

Copy link to clipboard

Copied

Yes but some change its not a problem

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