10 Replies Latest reply on Sep 25, 2013 4:52 AM by HenriqueMeuren

    Object layer options script to improve...

    JNSaraiva Level 1

      Hi guys, object layer options is a great idea, but some things drive me crazy


      The process is very repetitive and I have to close and open at all times to repeat the process in another box image.

      Is there a script that makes the object layer options more friendly?





      01 - Keep the 'Object layer options' always open

      02 - Select a box image, change the layer, apply the "ok" without closing the 'Object layer options', do the same process in another box image,and so on like a palette.



      Thank you guys,




        • 1. Re: Object layer options script to improve...
          John Hawkinson Level 5

          Scripts can't interact with dialog boxes.

          But they can perform the functions that you would use the dialog box to perform.

          So if your goal is to change object layer visiblity on a large number of images at once, then yes you can do that with a script.


          Please give a specific example of what you want to do.

          • 2. Re: Object layer options script to improve...
            JNSaraiva Level 1

            Hi John, basically the idea is to edit the boxes of images without having to open and close all the time the Object Layer Options.


            Thank you for your help.


            Best regards,



            • 3. Re: Object layer options script to improve...
              John Hawkinson Level 5

              That is not what I mean by a specific example. I want to hear something like: "I want to disable the Tree layer in all placed images on pages seven through twenty-one whose horizontal dimension is greater than 3 inches and less than 7 inches."


              As I said, scripts cannot interact with dialog boxes. They can control object attributes.

              You cannot force the dialog box to stay open while you edit. But you can do other things.


              Please give a specific example of your end goals. You can't accomplish them through the path you suggested, but you can probably accomplish them through another. But you'd need to tell us what they are.

              • 4. Re: Object layer options script to improve...
                TᴀW Adobe Community Professional & MVP

                You could try to recreate the Layes Dialog with SciptUI and add the

                functions you want to that dialog. Not a trivial challenge, though.



                • 5. Re: Object layer options script to improve...

                  John, Im just looking for a script to help solve exactly what you gave as example!

                  I have a lot of images that I have to place and all of them have exactly the same layers 1., 2., 3., 4. and the layer drawings. I want to place all of them but I want to disable all layers except the last one (drawings).


                  Do you know how I can do it?


                  Thanks in advance =)!

                  • 6. Re: Object layer options script to improve...
                    John Hawkinson Level 5

                    I seem to be running into some perverse problems in what should be a simple script. What ID version are you using?

                    • 7. Re: Object layer options script to improve...
                      HenriqueMeuren Level 1

                      Im using ID CS 5.5. I think that what you said before is really similar. I have a lot of images (all of them have the same layers name). I want to place them all with just the last layer turned on.

                      • 9. Re: Object layer options script to improve...
                        John Hawkinson Level 5

                        MeurHen: I have a solution for you.

                        (I did not have a prior script that solved this problem; I merely was indicating what was possible.)


                        This turns out to be far more complicated than it should be, because InDesign has a rather severe bug with the handling of object layers in scripting. Specifically, if you either change the visibility of an object layer, or if you test the validity of an object layer (with .isValid), or maybe other things, InDesign gets confused about the current set of object layers and you can no longer safely refer to the object layers for any object you may have stored in a variable. In fact, when it gets confusd, it confuses layers with inks, like Process Magenta, etc. It appears this is a known bug for some time, though I don't know if anyone has reported it -- Jongware, do you know?


                        The result is that the script that deals with this has to try up to N factorial times to set the layers on an object (that is, for a 5-layer object, it has to try up to 5*4*3*2*1 => 120 times) to handle the layer visibility. Though actually it probably only has to try 5 times, but it cannot know exaclty which 5.


                        I tried to write this script in a way that was clear, but I am not sure that I succeeded.


                        Here it is, tested against CS5.5:



                        var i,
                        for (i=0; i<doc.allGraphics.length; i++) {
                        function setLayers(graphicIndex) {
                            var success,
                                tries, maxTries;
                            // Every time we change the value of a layer's visibility,
                            // the entire set of layer state for that object is reset.
                            // Therefore, we have to try to set all N layers
                            // up to N times, depending on their prior state.
                            // This is a very annoying bug.
                            maxTries = doc.allGraphics[graphicIndex].
                            for (tries = 0; tries <=maxTries ; tries++) {
                                success = tryToSetLayers(doc.allGraphics[graphicIndex]);
                                if (success) {
                                        // Succeeded. All object layers are properly
                                        // set. We are done.
                                        return true;
                            // FAILURE! We tried N times and did not set all layers properly.
                            // the bugs have defeated us.
                            alert("Fatal error; inconsistent layer state");
                            return false;
                        function tryToSetLayers(graphic) {
                              j, layer, vizWanted,
                              layers = o.graphicLayers.everyItem().getElements();
                             for (j  = 0; j < layers.length; j++) {
                                layer = layers[j];
                                if (layer.name==="Drawings") {
                                    vizWanted = true;
                                else {
                                    vizWanted = false;
                                if (layer.currentVisibility !== vizWanted) {
                                        // made a change,  All bets are off.
                                        return false;       
                            return true; // Success!


                        You may need to edit the portion of the script on line 40, if (layer.name==="Drawings") {, which tests the layer name.

                        If you're having trouble figuring out what layer name to use, you can print out the layer names beforehand by adding a

                        $.writeln(layer.name) on the previous line. Or something like that.

                        This script operates on all graphic objects in the document. I guess it might fail if you have graphic objects that don't contain layers. Let me know if that's the case. I didn't test for that but should have.


                        (Again, does anyone know if this bug has been reported?)

                        • 10. Re: Object layer options script to improve...
                          HenriqueMeuren Level 1

                          John, it worked perfectly =D!

                          Thank you very much, man!