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

script rotate content to 180 degrees

Explorer ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

Hello,

Can I rotate the content of an artboard with  180 degrees with a script?and optional : to save in ai format but for an older version than  CS6

I know it's possible with an action, but it's about several files with different formats..

 

Thank you

 

[1]03-24-2021.jpg[2]03-24-2021.jpg

TOPICS
Scripting

Views

1.2K

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

Guide , Mar 30, 2021 Mar 30, 2021

To rotate on multiple artboards:

 

var doc = app.activeDocument;
var paths = doc.pathItems;

function multiRotate (){
    for (var i = 0; i < doc.artboards.length; i++) {
        doc.artboards.setActiveArtboardIndex(i);
        var AB = doc.artboards[i].artboardRect;
        var tempRect = paths.rectangle(AB[1], AB[0], AB[2]-AB[0], -AB[3]+AB[1]);
        doc.selectObjectsOnActiveArtboard();
        app.executeMenuCommand("group");
        app.selection[0].rotate(-180);
        app.executeMenuComma
...

Votes

Translate

Translate
Adobe
Community Expert ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

Hi, 

For rotation what you want to rotate, each pageitems exists on the artboard or the groupItems?

Below is the sample script, to rotate the each pageitems of the document

 

function main() {
    var doc = app.activeDocument;
    var _items = doc.pageItems;
    for (var k = 0; k < _items.length; k++) {
        _items[k].rotate(180);
    }
}
main();

 

 

In case you want to rotate the group, replace following line

 

 var _items = doc.pageItems;

 

with 

 

 var _items = doc.groupItems;

 

 

 

 

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 ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

Sorry but is not work

the rotation  must be as in the picture I attached above..as if you were rotating the artboard and content

Thank you

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
Guide ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

This is a script I wrote for rotating everything 90 degrees.  Try changing the 90 in line 6 to 180.  

 

https://community.adobe.com/t5/illustrator/rotate-an-entire-document-with-all-elements-90-degrees/m-... 

 

 

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 ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

@femkeblanco 

It works.

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 ,
Mar 29, 2021 Mar 29, 2021

Copy link to clipboard

Copied

Thanks

The  script from link doesn't work for me too so I made some changes. now it works but only for one artboard
I can't figure out how to do it I have more than one artboards....

this is the script...

var doc = app.activeDocument;  
var artSize = doc.artboards; 
var groups = app.activeDocument.groupItems;
var originalDocPath = doc.path;  
var originalDocName = doc.name;  
var allLayers = doc.layers;  
originalDocName = originalDocName.replace(/\.pdf|\.ai/gi, "")  
  
  for(i=0;i<artSize.length;i++){  
     var t=artSize[i].artboardRect[1] ;  
     var l=artSize[i].artboardRect[0];  
     var x=artSize[i].artboardRect[2]-artSize[i].artboardRect[0];  
     var y=artSize[i].artboardRect[1]-artSize[i].artboardRect[3];  
     var box = doc.pathItems.rectangle (t, l, x, y);  
     }  

function rotate(){
app.executeMenuCommand( "selectall");
app.executeMenuCommand( "group");
groups[0].rotate(-180);
app.executeMenuCommand( "deselectall");
box.selected = true;
app.executeMenuCommand( "setCropMarks");
app.activeDocument.artboards[0].remove();
app.executeMenuCommand( "selectall");
app.executeMenuCommand( "ungroup");
app.executeMenuCommand( "deselectall");
}

function saveAiFile(){
    // 8, 9, 10, 11 (cs), 12 (cs2), 13 (cs3), 14 (cs4), 15 (cs5), 16 (cs6), 17 (cc)
    targetVersion = 15;
    var saveOptions = new IllustratorSaveOptions();
    saveOptions.compatibility = Compatibility[ "ILLUSTRATOR" + targetVersion ];
    saveOptions.flattenOutput = OutputFlattening.PRESERVEAPPEARANCE;
    saveOptions.compressed = false;
    saveOptions.pdfCompatible = false;
    saveOptions.saveMultipleArtboards = true;
    //saveOptions.artboardRange = true;
    app.activeDocument.saveAs(File(originalDocPath + "/" + originalDocName + ".ai"), saveOptions);
}

rotate()
saveAiFile()

 

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
Guide ,
Mar 30, 2021 Mar 30, 2021

Copy link to clipboard

Copied

LATEST

To rotate on multiple artboards:

 

var doc = app.activeDocument;
var paths = doc.pathItems;

function multiRotate (){
    for (var i = 0; i < doc.artboards.length; i++) {
        doc.artboards.setActiveArtboardIndex(i);
        var AB = doc.artboards[i].artboardRect;
        var tempRect = paths.rectangle(AB[1], AB[0], AB[2]-AB[0], -AB[3]+AB[1]);
        doc.selectObjectsOnActiveArtboard();
        app.executeMenuCommand("group");
        app.selection[0].rotate(-180);
        app.executeMenuCommand("ungroup");
        app.selection = null;
        tempRect.remove();
    }
}
multiRotate();

 

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 ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

As you have mention 180, so script does 180. 

Please attach you ai sample file that will help us to guide in corrcet direction.

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
Community Expert ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

For saving the file in lower version, try following snippet.

 

function saveFile(){
    // 8, 9, 10, 11 (cs), 12 (cs2), 13 (cs3), 14 (cs4), 15 (cs5), 16 (cs6), 17 (cc)
    targetVersion = 16;
    var saveOptions = new IllustratorSaveOptions();
    saveOptions.compatibility = Compatibility[ "ILLUSTRATOR" + targetVersion ];
    saveOptions.flattenOutput = OutputFlattening.PRESERVEAPPEARANCE;
    app.activeDocument.saveAs( File('~/Desktop/Test.ai'), saveOptions )
}

saveFile()

 

 

NOTE: Not tested from my side I don't have CS6 version.

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