Mobile app version of vmapp.org
Login or Join
Dunderdale640

: Rotating a layer around centre and save file (72 times) I need to rotate a graphic I have made in Adobe Illustrator. The complication is that only the arrow layer needs to be rotated (around

@Dunderdale640

Posted in: #AdobeIllustrator #AdobePhotoshop #IllustratorScripting #Png #Svg

I need to rotate a graphic I have made in Adobe Illustrator.



The complication is that only the arrow layer needs to be rotated (around the centre of the image). That rules out simply throwing the file into some program and having it output at every 5 degrees otherwise the bus icon in the centre would rotate too. It needs to specifically rotate the arrow layer around the centre every 5 degrees so presumably that limits me to internal Illustrator/Photoshop scripting?

There are several different colour variations too. Doing this by hand is going to take many hours. Is there a way to simplify this with a script that can rotate the arrow layer for me and then save the file?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Dunderdale640

2 Comments

Sorted by latest first Latest Oldest Best

 

@Carla748

Create a bounding box object that sets the correct origin needed for the rotation (in the center of the bounding box object), and also fits the object you’d like to rotate. Colour the bounding box object with something unique, so it can be easily selected later.
Select and group the bounding box and the objects you’d like to rotate (but not the objects you’d like to keep fixed).
Choose Object → Transform → Transform Each, and rotate and move as required. I’ve used 5º and 20px in this example. Click Copy to translate a new copy.
Press ⌘D 71 times to create the transformed duplicates.





Press A to select the direct selection tool.
Click on one of the bounding box objects.
Choose Select → Same → Fill Color to select all the bounding box objects.
Press delete.
Select the other objects you’d like to duplicated (but not rotated).
Choose Object → Transform → Transform Each, and move as required. Click Copy to translate a new copy.
Press ⌘D 71 times to create the transformed duplicates.




Now you have the artwork, you can use slices or artboards to export them as needed.

10% popularity Vote Up Vote Down


 

@Nimeshi706

This is a very quick script that should do what you need:
#target illustrator

var doc = app.activeDocument;
var docName = doc.name.replace(/.[^.]+$/, ''),
docDir = ( doc.path != '' ) ? doc.path : '~';

var angle = 5,
iterations = 71,
layerToRotate = 'rotateMe',
destFolder = 'files';

rotateAndExport();

/**
* This is where the magic happens...
*/
function rotateAndExport() {

// loop through layers
for ( var i = 0; i < doc.layers.length; i++ ) {

// loop through layer's pageItems
var layer = doc.layers[i];
if ( layer.name == layerToRotate ) {
for ( var j = 0; j < layer.pageItems.length; j++ ) {
var item = layer.pageItems[j];

// rotate and export
for ( var r = 0; r < iterations; r++ ) {
item.rotate( angle );
exportFileAs( 'PNG', r );
exportFileAs( 'SVG', r );
}
}
}
}
}

/**
* Export as PNG or SVG
*/
function exportFileAs( fileType, iteration ) {

// create folder if it doesn't exist
var destPath = docDir + '/' + destFolder;
if ( false == Folder( destPath ).exists ) {
new Folder( destPath ).create();
}

// export options
var destFile;
var type;
var exportOptions;

if ( 'PNG' == fileType ) {

// create folder if it doesn't exist
var pngPath = destPath + '/PNG/';
if ( false == Folder( pngPath ).exists ) {
new Folder( pngPath ).create();
}
destFile = new File( pngPath + '/' + docName + '_' + iteration.toString() );

type = ExportType.PNG24;
exportOptions = new ExportOptionsPNG24();
exportOptions.artBoardClipping = true;
exportOptions.transparency = true;

} else if ( 'SVG' == fileType ) {

// create folder if it doesn't exist
var svgPath = destPath + '/SVG/';
if ( false == Folder( svgPath ).exists ) {
new Folder( svgPath ).create();
}
destFile = new File( svgPath + '/' + docName + '_' + iteration.toString() );

type = ExportType.SVG;
exportOptions = new ExportOptionsSVG();
exportOptions.preserveEditability = false;
exportOptions.embedRasterImages = true;
exportOptions.embedAllFonts = false;
exportOptions.encoding = SVGDocumentEncoding.UTF8;
exportOptions.fontType = SVGFontType.OUTLINEFONT;
}

// export
doc.exportFile( destFile, type, exportOptions );
}


Change the angle and iterations to what you need.

Change layerToRotate to the name of the layer you need to rotate.

Change destFolder to a folder name to save the files to, which will be created in the same place as your file is saved (or your home directory).

The script exports to PNG and SVG in their own folders. You can add more file types by changing the type and exportOptions in exportFile() to something else.

The rotation will originate at the center of all objects on the layer so you should draw an invisible rectangle centered on the artboard (or wherever you want to rotate from) over your arrow and group everything, as I have here:



Run the script and you should get something like this:





Note, this is all done on CS6; I don't know if anything has changed in and can't test on any newer versions.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme