Highlighted

Script for rotating pieces by name

Explorer ,
Jun 29, 2020

Copy link to clipboard

Copied

Hey guys,

 

I was wondering if there is a way you can rotate pieces that share some part of the same name via script. Let´s say my file got 10 pieces and 3 of them have "180" incluced somewhere (or only in the end if that makes it easier) in their names. Now I want exactly these three to be rotated by 180 degree.

 

Thanks guys for any advice, I´m really grateful for your help  🙂 🙂

 

Example file

Adobe Community Professional
Correct answer by Charu Rajput | Adobe Community Professional

Hi,

Try the following snippet. Tested on your sample file.

for(var i=0;i<app.activeDocument.pageItems.length;i++){
    var _pageItem = app.activeDocument.pageItems[i];
    if(_pageItem.name.indexOf('180') != -1){
        _pageItem.rotate(180);
    }
}

 

Let us know if this works for you. 

TOPICS
Scripting

Views

111

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

Script for rotating pieces by name

Explorer ,
Jun 29, 2020

Copy link to clipboard

Copied

Hey guys,

 

I was wondering if there is a way you can rotate pieces that share some part of the same name via script. Let´s say my file got 10 pieces and 3 of them have "180" incluced somewhere (or only in the end if that makes it easier) in their names. Now I want exactly these three to be rotated by 180 degree.

 

Thanks guys for any advice, I´m really grateful for your help  🙂 🙂

 

Example file

Adobe Community Professional
Correct answer by Charu Rajput | Adobe Community Professional

Hi,

Try the following snippet. Tested on your sample file.

for(var i=0;i<app.activeDocument.pageItems.length;i++){
    var _pageItem = app.activeDocument.pageItems[i];
    if(_pageItem.name.indexOf('180') != -1){
        _pageItem.rotate(180);
    }
}

 

Let us know if this works for you. 

TOPICS
Scripting

Views

112

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
Jun 29, 2020 0
Adobe Community Professional ,
Jun 29, 2020

Copy link to clipboard

Copied

Hi,

Try the following snippet. Tested on your sample file.

for(var i=0;i<app.activeDocument.pageItems.length;i++){
    var _pageItem = app.activeDocument.pageItems[i];
    if(_pageItem.name.indexOf('180') != -1){
        _pageItem.rotate(180);
    }
}

 

Let us know if this works for you. 

Best regards

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
Reply
Loading...
Jun 29, 2020 2
Explorer ,
Jun 30, 2020

Copy link to clipboard

Copied

Wow that answer came quick! Works perfect! Thank you very much 🙂 🙂

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
Reply
Loading...
Jun 30, 2020 1
Explorer ,
Jun 30, 2020

Copy link to clipboard

Copied

Is there also a way you could match the name and the amount of degrees the piece needs to be turnt? Like if I name a piece abc37 in turns for 37 degree and abc180 for 180?

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
Reply
Loading...
Jun 30, 2020 0
Adobe Community Professional ,
Jun 30, 2020

Copy link to clipboard

Copied

Yes, that is also possible. But for this case, I would suggest you should name like abc_37 or abc_180, just to have differentiate character between name and angle. For an example if you use naming convention as abc_37, we will always know that after _, we have number for an angle and the following script will work in that case. 

for(var i=0;i<app.activeDocument.pageItems.length;i++){
    var _pageItem = app.activeDocument.pageItems[i];
    if(_pageItem.name.indexOf('_') != -1){
        var angle = _pageItem.name.split('_')[1];
        _pageItem.rotate(angle);
    }
}

 

NOTE: Above snippet assume after _ is angle number. If you have name as abc_def, in that case script may fail or stop. So, accordingly we need to change script.

 

Let us know if this solution works for you.

Best regards

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
Reply
Loading...
Jun 30, 2020 1
Explorer ,
Jun 30, 2020

Copy link to clipboard

Copied

Thank you very much!!! Works perfect again! You are so fast at answering 🙂 🙂

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
Reply
Loading...
Jun 30, 2020 1
Adobe Community Professional ,
Jun 29, 2020

Copy link to clipboard

Copied

Charu's script could be incorporated into the script I wrote a week ago.

 

I mentioned rotation was tricky for a computer but easy for humans. If you know which pieces need rotation and you will need to rename the pieces after running the previous script, may be you could skip renaming and just rotate the pices you select yourself.

 

this script does that, it rotates all selected pieces regardless of names

// rotate selected items 180 degrees
for (var a=0; a<selection.length; a++) {
    selection[a].rotate(180);
}

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
Reply
Loading...
Jun 29, 2020 2
Explorer ,
Jun 30, 2020

Copy link to clipboard

Copied

Hey Carlos thanks for helping me again! 🙂 As I use the files not regularly I might forget which items need to be turned. Therefore renaming them is the way to go for me. But your script might come in handy sometime too 🙂 Thanks!

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
Reply
Loading...
Jun 30, 2020 0