Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Indesign Applescript Placed Object Layer Visibilty Override

New Here ,
Jun 26, 2014 Jun 26, 2014

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!

TOPICS
Scripting
2.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Jul 19, 2014 Jul 19, 2014

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 myLayerNameLis

...
Translate
New Here ,
Jun 30, 2014 Jun 30, 2014

Bump.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 30, 2014 Jun 30, 2014

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 30, 2014 Jun 30, 2014

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

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


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 19, 2014 Jul 19, 2014

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 19, 2014 Jul 19, 2014

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 20, 2014 Jul 20, 2014

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 20, 2014 Jul 20, 2014
LATEST

that's cool!

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

and maybe mark my answer?

have fun.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 03, 2014 Jul 03, 2014

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines