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

enter image description here

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?

  • 1
    Can't you just make the roundel and the arrow two separate objects and then recombine them in the app, webpage or whatever and add the rotation to just the arrow?
    – Westside
    Feb 28, 2017 at 10:10
  • @Chris I did think about that but sadly as this is a Google Maps application often with over 100 markers, doubling up and doing as you suggest would create 200 markers which creates performance problems
    – jskidd3
    Feb 28, 2017 at 10:47

2 Answers 2


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


 * 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:

enter image description here

Run the script and you should get something like this:

enter image description here

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

  • @jskidd3 noticed you tagged svg and png so updated to export both
    – Cai
    Feb 28, 2017 at 11:30
  • Hmm. I followed your advice with regards to adding the invisible rectangle but my arrows are still rotating around the centre of the arrow itself. Any ideas? i.imgur.com/AHMzvjE.png
    – jskidd3
    Feb 28, 2017 at 11:59
  • You need to group the invisible rectangle and the arrow.
    – Cai
    Feb 28, 2017 at 12:03
  • Like this? When I run the script now it doesn't do anything. Sorry I'm new to Illustrator (but oddly fluent in JS) i.imgur.com/JTgoblr.png
    – jskidd3
    Feb 28, 2017 at 12:06
  • 1
    No prob, glad to help
    – Cai
    Feb 28, 2017 at 12:13
  1. 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.
  2. Select and group the bounding box and the objects you’d like to rotate (but not the objects you’d like to keep fixed).
  3. Choose ObjectTransformTransform Each, and rotate and move as required. I’ve used 5º and 20px in this example. Click Copy to translate a new copy.
  4. Press ⌘D 71 times to create the transformed duplicates.

Adobe Illustrator transform

  1. Press A to select the direct selection tool.
  2. Click on one of the bounding box objects.
  3. Choose SelectSameFill Color to select all the bounding box objects.
  4. Press delete.
  5. Select the other objects you’d like to duplicated (but not rotated).
  6. Choose ObjectTransformTransform Each, and move as required. Click Copy to translate a new copy.
  7. Press ⌘D 71 times to create the transformed duplicates.

Adobe Illustrator transform

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.