3

I’ve been working with Illustrator CC 2014 on a floor map for a ~400 rooms building. To allow visitors to find rooms more quickly, I wanted to generate a series of images with highlighted rooms. The rooms are mostly rectangles with their object name corresponding with their room number.

In short, I need some sort of procedure that does the following tasks:

  1. Change colour of object
  2. Export to PNG using the object name within the file name
  3. Change colour back
  4. Go on to the next object

I have no problem with steps 1, 3 and 4 using Automating tasks, but cannot figure out how to do step 2.

floor map

5
  • You will need scripting.
    – Scott
    Commented Aug 19, 2014 at 15:23
  • aunm @Scott now they can not get the specific script for this usecase. And i would have had it of the shelf.
    – joojaa
    Commented Aug 20, 2014 at 4:18
  • @Joojaa just answer the duplicate...
    – Scott
    Commented Aug 20, 2014 at 4:58
  • @Scott its not the same case. Computers are a bit more pedantic than you or I.
    – joojaa
    Commented Aug 20, 2014 at 6:12
  • Okay @joojaa .. reopened.
    – Scott
    Commented Aug 20, 2014 at 6:13

1 Answer 1

2

I have done this exact same thing here's my script:

#target illustrator

var path_prefix=("d:/temp/floormap_")
var layer = app.activeDocument.layers.getByName("rooms");

function exportFileToPNG8(dest) {
    if ( app.documents.length > 0 ) {
        var exportOptions = new ExportOptionsPNG8();
        var type = ExportType.PNG8;
        var fileSpec = new File(dest);
        exportOptions.colorCount = 32;
        exportOptions.transparency = false;
        app.activeDocument.exportFile( fileSpec, type, exportOptions );
    }
}

for (var i=0; i < layer.pageItems.length; i++){
    var item = layer.pageItems[i];
    if(item.typename === "GroupItem"){
       var room_name = item.pageItems[0].contents;
       item.pageItems[1].hidden = false;
       exportFileToPNG8(path_prefix+room_name+".png")
       item.pageItems[1].hidden = true;
    }
}

In order to use you must ensure that you have a layer named rooms and under rooms you have a group for each room with the name of the room topmost and the layer to show hide after that hidden. Remeber to rename the path prefix.

organization

Image 1: example of layer organization

The script is a bit fragile so if text is not first and the group has no second item it will fail. Here is the general outline of how the script works:

how it works

Image 2: state diagram of script

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.