8 Replies Latest reply on Jul 20, 2014 8:46 AM by chris breu

    Indesign Applescript Placed Object Layer Visibilty Override

    ingywoo Level 1

      Hi, trying to programmatically control layer visibility of placed objects (either AI or other ID files) in a multi-page Indesign document.  Have looked all over the dictionary but can't seem to figure a way to reference the layers.

       

      Would someone have an example of how to do this in Applescript?  (Please, not javascript, will convert one day but for now am staying with AS.)

       

      Thanks!

        • 2. Re: Indesign Applescript Placed Object Layer Visibilty Override
          Kevin Parrott Level 2

          Hi

          I am not sure if this is what your after, but this toggles layer visibility.

           

          tell application "Adobe InDesign CC 2014"

              activate

              tell document 1

                  set Flaplayer to "TEST"

                  --set myLayer to layer Flaplayer

                  --set the properties of myLayer to {locked:true}

                  --set active layer to Flaplayer

                  set visible of layer Flaplayer to false

              end tell

          end tell

          • 3. Re: Indesign Applescript Placed Object Layer Visibilty Override
            Mary Posner Level 3

            I think you're looking for something like this....

             

              set current visibility of graphic layer "myLayer" of graphic layer options of myGraphic to false


            • 4. Re: Indesign Applescript Placed Object Layer Visibilty Override
              chris breu Level 1

              Hi

               

              Here a little code snippet – hope it can help.

               

              tell application "Adobe InDesign CC 2014"

                  set myRectangle to make new rectangle of active document with properties {geometric bounds:{20, 20, 70, 70}}

                  set myLayer to item layer of myRectangle

                  set visible of myLayer to false

              end tell

               

               

              Have fun!

              • 5. Re: Indesign Applescript Placed Object Layer Visibilty Override
                ingywoo Level 1

                Thanks, Mary, your suggestion has put me on a good path, but I'm still having some trouble.

                 

                I have several similar documents, each having multiple pages with one placed item per page that are linked, not embedded.  Each of those placed items may or may not have a layer with a specific name.  I'm trying to iterate through the links and toggle visibility of the layers within the placed objects as needed.

                 

                Ultimately the script would:

                    Cycle through all links in the target doc.

                        Get a list of all layers in the current link of the cycle.

                        Cycle through a list of layer names to check.

                            Set the desired layer to visible, all others in the list to not visible.

                            (This could be with a string var that was the same as the desired entry in the list, or a numeric index var to compare with where the counter was in its cycle)

                 

                Here's a verbose example of what I've got so far.  It assumes the target document is already open...

                 

                # With which app are we working?

                tell application "Adobe InDesign CC 2014"

                   

                    # With which document are we working?

                    set theDocName to "My Indesign Document"

                   

                    # Which layer do we want to be visible?   

                    set theDesiredLayer to "My Desired Visible Layer"

                   

                    # Set the Document ID of the chosen document

                    set theDocID to document named theDocName

                   

                    # Work with the chosen document

                    tell theDocID

                       

                        # Create an object of all links of the chosen document

                        set theDocLinks to links of theDocID

                       

                        # Set the count of all links in the chosen document

                        set theDocLinksCount to count of theDocLinks

                       

                        # Cycle through all the linked objects

                        repeat with i from 1 to theDocLinksCount

                           

                            # Create an object of the current link

                            set theCurLink to item i of theDocLinks

                           

                            # Set the name of the current link

                            set theLinkName to name of theCurLink

                           

                            # Create an object of the parent of the current link

                            set theLinkParent to parent of theCurLink

                           

                            # Create an object of the graphic layer options of the parent of the current link

                            set theGraphicLayerOptions to graphic layer options of theLinkParent

                           

                            # Get a count of the layers in the current link

                            set theLayerCount to count of graphic layers of theGraphicLayerOptions

                           

                            # Cycle through the layers in the current link

                            repeat with j from 1 to theLayerCount

                               

                                # Create an object of the current layer

                                set theLayer to item j of graphic layers of theGraphicLayerOptions

                               

                                ######################################

                                # THIS FAILS

                                set theLayerName to name of theLayer

                                log "Layer: '" & theLayerName & "' ~ Visible: '" & current visibility of graphic layer theLayerName of theOptions

                                ######################################

                               

                                ######################################

                                # THIS WORKS ONLY UNDER CERTAIN CONDITIONS

                                set current visibility of graphic layer theDesiredLayer of theGraphicLayerOptions to true

                                ######################################

                 

                            end repeat

                        end repeat

                    end tell

                end tell

                 

                The part that works does so only when I let it act on specific links (based on theLinkName).  If the link has no such layer, it bombs (as expected).

                 

                I'd really rather just iterate through the layers of each link and take action based on whether or not my target layer exists in that link.  For that to happen, I need to be able to access the name of the layer.

                 

                When cycling through the layers,

                   

                    set theLayer to item j of graphic layers of theGraphicLayerOptions

                 

                *should* return a graphic layer object, which has a name property that I could then use for comparison.  But that always fails.

                 

                I've also tried other properties of the graphic layer object such as parent, object reference, etc. It always bombs out when I try to work with the layer object.

                 

                The obvious conclusion is that I'm not really creating a graphic layer object, but according to the dictionary it seems this should work.

                 

                Any ideas what I'm doing wrong?

                 

                Thanks!

                • 6. Re: Re: Indesign Applescript Placed Object Layer Visibilty Override
                  chris breu Level 1

                  sorry for my last answer, I missunderstood.

                  hope this helps.

                   

                  have fun.

                   

                   

                  # here you can list layernames to set visible

                  set myLayerNameList to {"Layername 1", "Layername 2"}

                   

                  tell application "Adobe InDesign CC"

                       set theDocLinks to links of active document

                   

                       repeat with i in theDocLinks

                            set theGraphicLayers to name of graphic layers of graphic layer options of parent of i

                   

                            repeat with j from 1 to count theGraphicLayers

                   

                                 if item j of theGraphicLayers is in myLayerNameList then

                                      set current visibility of graphic layer j of graphic layer options of parent of i to true

                                 else

                                      set current visibility of graphic layer j of graphic layer options of parent of i to false

                                 end if

                   

                            end repeat

                       end repeat

                  end tell

                  • 7. Re: Indesign Applescript Placed Object Layer Visibilty Override
                    ingywoo Level 1

                    Wow, that was so easy!  Thanks for the tip.

                     

                    Took about 30 seconds for a 36 page document with 3 layers to check per link.

                     

                    Had planned to use a list when everything was working.  Here's the final:

                     

                    tell application "Adobe InDesign CC 2014"

                       

                        # With which document are we working?

                        set theDocName to "My Indesign Document.indd"

                       

                        # Create a list of layer names to check

                        set theLayersList to {"My Layer 1", "My Layer 2", "My Layer 3"}

                     

                        # Which layer do we want to be visible?   

                        set theDesiredLayer to item 2 of theLayersList

                       

                         ######################

                         # No need to edit below... #

                         ######################

                     

                        # Create an object of all document links in the chosen document

                        set theDocLinks to links of document named theDocName

                       

                        # Cycle through the links

                        repeat with i in theDocLinks

                           

                            # Create an object of all the graphic layer names of the current link

                            set theGraphicLayers to name of graphic layers of graphic layer options of parent of i

                           

                            # Cycle through the layers

                            repeat with j from 1 to count theGraphicLayers

                               

                                # Set the current layer name

                                set theCurLayer to item j of theGraphicLayers

                               

                                # Is this a layer to check?

                                if theCurLayer is in theLayersList then

                                   

                                    # Is it the layer I wish to be visible?

                                    if theCurLayer is theDesiredLayer then

                                        # YES - Set visibility to true

                                        set current visibility of graphic layer j of graphic layer options of parent of i to true

                                    else

                                        # NO - set visibility to false

                                        set current visibility of graphic layer j of graphic layer options of parent of i to false

                                    end if

                                   

                                end if

                               

                            end repeat

                           

                        end repeat

                       

                    end tell

                    • 8. Re: Indesign Applescript Placed Object Layer Visibilty Override
                      chris breu Level 1

                      that's cool!

                       

                      can you please set the status of your question to answered?

                      and maybe mark my answer?

                       

                       

                      have fun.