Skip to main content
Participating Frequently
June 7, 2016
Question

Illustrator Script(s) for Hiding/Deleting Specific Layers

  • June 7, 2016
  • 1 reply
  • 3611 views

Hello all,

I'm in need of a working Script that is capable of hiding/deleting specific layers in an Illustrator document. I have searched quite a bit and can't seem to find anything that can be specifically applied to my needs.

The template we are working with in Illustrator is very basic and will never change. It contains the following main layers:

I need this Script to be able to perform the following steps:

1) All Layers Visible

    Export PNG @ High (300 ppi)

    Type Optimize (Hinted)

    Background: White

    Save to "Folder 1"

    Close Document (Don't Save)

2) Hide Layer: Callouts

    Hide Layer: Details

    Export PNG @ High (300 ppi)

    Type Optimize (Hinted)

    Background: White

    Save to "Folder 2"

    Close Document (Don't Save)

3) Hide Layer: Header

    Hide Layer: Callouts

    Hide Layer: Details

    Export PNG @ High (300 ppi)

    Art Optimized (Supersampling)

    Background: White

    Save to "Folder 3"

    Close Document (Don't Save)

Is it possible for a script to do all three of these things within a single Script/Action, thereby removing the "Close Document (Don't Save)" from Steps 1 and 2? What would the script look like for doing all three at once vs each step as its own individual process? If not possible, creating three separate scripts and running them three times will still be far more efficient than the system we're currently using.

*Also, if the "Hide Layer" function is not an option, could a "Delete Layer" function be used instead since I'm wanting it to close the document without saving anyways?

I also have one other thing that I need it to do, but I'm not sure it's possible. Maybe it's something that needs to be done via an Action in Photoshop after the PNG files have been created. I need to try and add the filename to the bottom right of the PNG file that is created in Step 2. I've illustrated there in the below image:

Now, these will be run in large batches on 30-100+ files at a time. I have quite a bit of experience creating/using Actions in Photoshop and to my disappointment, Actions don't seem to function anywhere nearly as well in Illustrator. What's frustrating is that this is quite possibly the easiest thing to do in Photoshop:

Create an action, start record, and it instantly reads every click you make as a step in building the action. Why Adobe hasn't built this functionality into Illustrator baffles me.

It has been years since I've even looked at anything programming related so I'm turning to you all with hopes that you can help me out.

Thank you in advance!

This topic has been closed for replies.

1 reply

Silly-V
Legend
June 7, 2016

It would be simplest and safest to run single-action scripts that can do what actions can't do, as part of batch actions.

(There appear to be some batch-related issues with the latest versions of Illustrator)

I don't have time to test right now, but try this as a menu item inserted into your batch action.

#target illustrator - 19

function test() {

    var folder_1 = Folder("/Users/.../Dest/Folder 1");

    var folder_2 = Folder("/Users/.../Dest/Folder 2");

    var folder_3 = Folder("/Users/.../Dest/Folder 3");

    function revealAllLayers(doc) {

        for (var i = doc.layers.length - 1; i >= 0; i--) {

            doc.layers.visible = true;

        }

    };

    function hideLayer(doc, name) {

        doc.layers.getByName(name).visible = false;

    };

    function exportMyPng(dest, doc, props) {

        var pngOpts = new imageCaptureOptions;

        for (var all in props) {

            if (pngOpts.hasOwnProperty(all)) {

                pngOpts[all] = props[all];

            }

        }

        doc.imageCapture(File(dest + "/" + doc.name), doc.artboards[0].artboardRect, pngOpts);

    };

    var doc = app.activeDocument;

    revealAllLayers(doc);

    exportMyPng(folder_1, doc, {

        transparency: false,

        antiAliasing: AntiAliasingMethod.TYPEOPTIMIZED

        resolution: 300

    });

    hideLayer("Callouts");

    hideLayer("Details");

    exportMyPng(folder_2, doc, {

        transparency: false,

        antiAliasing: AntiAliasingMethod.TYPEOPTIMIZED

        resolution: 300

    });

    hideLayer("Header");

    exportMyPng(folder_2, doc, {

        transparency: false,

        antiAliasing: AntiAliasingMethod.ARTOPTIMIZED

        resolution: 300

    });

};

test();

bmurfeyAuthor
Participating Frequently
June 7, 2016

I am getting this error when running that script.

bmurfeyAuthor
Participating Frequently
June 7, 2016

Oh, another typo issue, there needs to be parentheses ():

var pngOpts = new imageCaptureOptions();


It is giving the same error, even with those parentheses in place.