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

Script for rotating pieces by name

Explorer ,
Jun 29, 2020 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

TOPICS
Scripting

Views

318

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

Community Expert , Jun 29, 2020 Jun 29, 2020

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. 

Votes

Translate

Translate
Adobe
Community Expert ,
Jun 29, 2020 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

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 30, 2020 Jun 30, 2020

Copy link to clipboard

Copied

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

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 30, 2020 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?

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 30, 2020 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

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 30, 2020 Jun 30, 2020

Copy link to clipboard

Copied

LATEST

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

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 29, 2020 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);
}

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 30, 2020 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!

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