4 Replies Latest reply on May 24, 2017 1:35 AM by [Jongware]

    Making a layer invisible

    carlosn21996940

      Hit that point where endless searching isn't helping -- as far as I can tell I'm doing the correctly but it just isn't working.

       

      I'm working on a script that exports a document as a PDF then makes a layer invisible and exports the same document as a PDF again. The problem is I can't make the layer invisible.

       

      var HideLayer = app.activeDocument.layers.itemByName("outlines");

      HideLayer.visible = false;

      redraw();

       

      I don't know if the redraw is necessary I saw it in a few examples when trying to solve this. I inserted alerts between each line of code and the script stops at the HideLayer.visible = false; line. It never gets past that.

       

      The layer I want to make invisible is called outlines in the outline panel in InDesign.

       

      It is created earlier in the script with

       

      var outlineLayer=app.activeDocument.layers.add();

      outlineLayer.name="cutlines";

       

      Can anyone point me in the right direction?

        • 1. Re: Making a layer invisible
          JustOneBren Level 1

          Hi,

           

          I'd just use:

           

          app.activeDocument.layers.itemByName("outlines").visible=false;

           

          No redraw required, hope this works for you

          • 2. Re: Making a layer invisible
            [Jongware] Most Valuable Participant

            You created the layer with the name "cutlines". You are attempting to look it up with the name "outlines". That does not work.

             

            If the part of the script where you hide the layer is in the same context as where you created it, you can re-use the variable outlineLayer again. Unless you deliberately change it to some other value elsewhere, the variable will keep on pointing to that same layer until the script end.

             

            ("Context" is key here. A good rule-of-thumb is: if you create a variable after an opening brace { then it will most likely not exist after the matching closing brace }.)

            • 3. Re: Making a layer invisible
              carlosn21996940 Level 1

              Thank you. I feel pretty stupid for not seeing that. The text at the resolution I'm using is pretty tiny so I didn't even notice.

               

              Works fine now.

              • 4. Re: Making a layer invisible
                [Jongware] Most Valuable Participant

                Glad to be of help!

                 

                Personally, I don't use the ESTK, because I'm too much used to other code editors (TextWrangler on my Mac, TextPad on my PC, and/or Sublime Text on both (!)), but I can see the advantages of using it to interactively run and debug scripts. You may want to take a look at its Preferences (under the Edit menu on Windows and likely "in the usual position" on Mac) and check the settings in "Fonts and Colors". There you can change the font size and the font itself to something better readable on your system.