22 Replies Latest reply on Mar 11, 2015 4:38 PM by rob day

    GraphicLayerCompositions not scriptable? AS

    DBLjan Level 2

      Hi there,

       

      I need to switch between graphic layer compositions, InD has a UI for that, so far so good. But also I need to switch alpha masks in my imported PSD, which isnt possible without re-importing, which is fine, because weve developed a script for that, throwing the alpha channels in a ChooseFromList, then reimporting the PSD with the choosen channel.

       

      BUT:

      How can I read out the set composition to hand it over for reimport?
      I cant imagine Adobe not implenting such a crucial feature, if a Adobe UI is there, with a dialog to change and also an import option.

      So, has anyone an idea to adress the graphic layer compiositions? I need to reimport the PSD with exact same preferences…

       

      What I could do:

      I could cycle throu all layers and save their visibilty and restore that, but for later document management I need the name of the composition. So if I go to layer comps of a reimported pic, the choosen comp is set to "last document status"…and I dont need that, changing around my picture.

       

       

      (…)

          tell curObj

              set alphaNames to alpha channel path names of clipping path

          end tell

          set MyResult to choose from list alphaNames with title "Choose Alpha" with prompt "Alpha-Kanal wählen:" OK button name "OK" default items (last item of alphaNames)

          if MyResult = false then

              error number -128

          else

              set curAlpha to MyResult as Unicode text

          end if

          place file curPath on selection with properties {image IO preferences:{alpha channel name:curAlpha}}

          set curLink to item link of graphic 1 of selection

          tell document 1

              -- neu verknüpfen

              relink curLink to file curPath

          end tell

        • 1. Re: GraphicLayerCompositions not scriptable? AS
          Laubender Adobe Community Professional & MVP

          @Jan – From my experience with ExtendScript and LayerCompositions I think, this is not scriptable.
          An oversight maybe in the scripting DOM of ExtendScript. And maybe AppleScript as well.

           

          Uwe

          • 2. Re: GraphicLayerCompositions not scriptable? AS
            DBLjan Level 2

            Since I only can access InD5.5, i cant tell if this got fixed in CC…can anyone please check? What does Adobe say about this flaw, working as intended? Then why hold this back?

             

            So importing stuff by script with graphic layer compositions (which is a Adobe patent i guess) doesnt work. Chapeu.

            • 3. Re: GraphicLayerCompositions not scriptable? AS
              Laubender Adobe Community Professional & MVP

              @Jan – This is not fixed in InDesign CS6 v8.1.0.
              Though I did not check with CC and CC-2014.2 lately…

               

              Uwe

              • 4. Re: GraphicLayerCompositions not scriptable? AS
                rob day Adobe Community Professional & MVP

                I can't test in CS5.5 but this works in CC, you don't have to reimport the image to set its alpha channel:

                 

                 

                --select an image with at least 1 channel and run:

                tell application "Adobe InDesign CC 2014"

                 

                    --get the name of every channel in the selected image

                    set alist to alpha channel path names of clipping path of selection of active document

                 

                    --apply the second channel in the list

                    set properties of clipping path of selection of active document to {clipping type:alpha channel, applied path name:item 2 of alist}

                end tell

                • 5. Re: GraphicLayerCompositions not scriptable? AS
                  rob day Adobe Community Professional & MVP

                  I just tested in CS6 and it works.

                  • 6. Re: GraphicLayerCompositions not scriptable? AS
                    Laubender Adobe Community Professional & MVP

                    @Rob – I don't think it's the alpha channels directly Jan is after. If I'm right, and I did not misunderstand him, he is after the Layer Compositions Controls you can switch on/off in PhotoShop and can handle in the UI of InDesign. I didn't find a hook on Layer Compositions in the Scripting DOM for ExtendScript of CS 5.5 and CS6.

                     

                    Here an example:

                     

                    LayerComp1.png

                    LayerComp2.png

                     

                    Of course you can tell which of the layers in the placed PhotoShop image are on or off, but cannot set the layer composition "LayerComp1" or "LayerComp2" in my example by scripting.

                     

                    Uwe

                    • 7. Re: GraphicLayerCompositions not scriptable? AS
                      DBLjan Level 2

                      Oh my, this "clipping path" is cut to true or false, based on the original alpha mask stored in the PSD, an "sim" of the real smooth mask…I dont need that.
                      So, you'll figure out that the smooth alpha channel can only be changed by selecting the channel within the import options. So…either I'll have to reimport by hand with the hassle of browsing to that image, selecting the alpha mask I want, selecting the graphic layer compsoition set, …or I could script that…wait: InD forgot about layer comps :-(

                      • 8. Re: GraphicLayerCompositions not scriptable? AS
                        DBLjan Level 2

                        Thank you Uwe, thats what I was aiming for.

                        • 9. Re: GraphicLayerCompositions not scriptable? AS
                          Laubender Adobe Community Professional & MVP

                          @Jan – Maybe you have a chance to script PhotoShop to check what each Layer Composition will exactly do.

                           

                          And save different versions of the same image with different Layer Compositions active?

                          Don't know, if this will work or even help.

                          Maybe only for very simple layer comps where only visibility of layers is stored and not positioning or "visual style" of layers.

                           

                          I know, this is really bad :-(


                          Uwe

                          • 10. Re: GraphicLayerCompositions not scriptable? AS
                            DBLjan Level 2

                            But…now that weve found out about that, what to do next?

                             

                            Bother Adobe? No way, even if I had Premium Support, i couldn't imagine that someone got a clue of this.

                            But I'd like an answer from them…why this hasnt been fixed in years…

                             

                            The workaround could be: save every visibility of each layer, then reimport and switch back on/off the layers based on last import. But then this problem comes along:

                            Lets say i have an window in the back photoshopped to summer-ish, also the decor on the table is summer flavoured. Its composed in graphic layer comp "Summer", also i have a retuched version called "Winter".

                            Now I need that image boxed-out with the summer decor.

                            I run my script, boxed out is choosen, layers get imported by visibilty…everything seems to be okay, but:

                            When I want to change the setting of my image to …lets say "Winter", i don't know which version is/was choosen, because InD default places images by script with no chance whatsoever to select this (seems to be), so my comp gets overwritten to "last used document default"…and with our vast image libary I'm lost guessing which composition was choosen before :-(

                            • 11. Re: GraphicLayerCompositions not scriptable? AS
                              Laubender Adobe Community Professional & MVP

                              @Rob – here an example from PhotoShop where LayerComp1 and LayerComp3 are preserving visibility plus position of layers.

                              In this example, if placed in InDesign, you absolutely have to know what each of the layer compositions will do or you need the exact name of layer composition turned on to get the same visual appearance after relinking.

                               

                              LayerComp1-Position.png

                               

                              LayerComp3-Position.png

                               

                              In the UI no problem. By scripting: Impossible.

                               

                              Uwe

                              • 12. Re: GraphicLayerCompositions not scriptable? AS
                                rob day Adobe Community Professional & MVP

                                Sorry, I got thrown off by the clipping path/alpha mask example in the first post.

                                • 13. Re: GraphicLayerCompositions not scriptable? AS
                                  DBLjan Level 2

                                  …impossible to do all the stuff stored in the comp.

                                  But just flimsy of Adobe not implement the choosing of the comp to be scriptable.

                                  Who can I reprehend for this?…

                                  • 14. Re: GraphicLayerCompositions not scriptable? AS
                                    Laubender Adobe Community Professional & MVP

                                    @Rob – no problem…

                                     

                                    The problem with managing Layer Compositions of placed PhotoShop images is really a bad one when it comes to scripting.

                                    There is absolutely no control for scripters, I think.

                                     

                                    And my examples here are really simple ones. You can get easily to much more complex ones with changed colors, a lot of nested layers etc.pp.

                                    For these I see no workaround at all.

                                     

                                    Hm, what I did not check: Maybe there is a 3rd party plugin around, that will make Layer Compositions available for scripters?

                                    Theoretically possible to write such a thing.

                                     

                                    Uwe

                                    • 15. Re: GraphicLayerCompositions not scriptable? AS
                                      rob day Adobe Community Professional & MVP

                                      If you left the image's Layer Comp setting as Last Document State you could have the script open the link in PS set the desired layer comp, save, close and update the link in ID. Resaving isn't ideal but seems like it might get the job done.

                                      • 16. Re: GraphicLayerCompositions not scriptable? AS
                                        rob day Adobe Community Professional & MVP

                                        This is surprisingly fast with PS in the background:

                                         

                                        tell application "Adobe InDesign CC 2014"

                                            activate

                                            --check for a selected image

                                            set s to selection of active document

                                            if s is equal to {} then

                                                display dialog "Make a Selection"

                                                return

                                            end if

                                           

                                            if class of item 1 of s is image then

                                                set i to item link of item 1 of s

                                            else

                                                try

                                                    set i to item link of image 1 of item 1 of s

                                                on error

                                                    display dialog "Please Select an Image"

                                                end try

                                            end if

                                           

                                            --edit the link original in PS. Automatically relinks

                                            edit original i

                                           

                                            tell application "Adobe Photoshop CC 2014"

                                                tell current document

                                                    --apply the comp

                                                    set lc to every layer comp whose name is "YourChosenComp"

                                                    apply lc

                                                    save

                                                    close

                                                end tell

                                            end tell

                                        end tell

                                        • 17. Re: GraphicLayerCompositions not scriptable? AS
                                          Laubender Adobe Community Professional & MVP

                                          @Rob – Still I did not try anything with your AppleScript code.

                                           

                                          I'm just musing over the PhotoShop part of it.

                                           

                                          Here we have a String, the name of a layer comp you are defining as "YourChosenComp".

                                          This name or contents of the string seems to be not a generic one.

                                           

                                          So my question is:

                                          How can we find out the name of this layer comp?
                                          Respectively the contents of that string?

                                           

                                          Uwe

                                          • 18. Re: GraphicLayerCompositions not scriptable? AS
                                            rob day Adobe Community Professional & MVP

                                            How can we find out the name of this layer comp?

                                            This gets a list of the comps and populates a dropdown dialog so you can then choose a comp to apply:

                                             

                                            ---------------------------------------

                                             

                                             

                                            tell application "Adobe InDesign CC 2014"

                                                activate

                                             

                                                --check for an image selection

                                                set s to selection of active document

                                                if s is equal to {} then

                                                    display dialog "Make a Selection"

                                                    return

                                                end if

                                                if class of item 1 of s is image then

                                                    set i to item link of item 1 of s

                                                else

                                                    try

                                                        set i to item link of image 1 of item 1 of s

                                                    on error

                                                        display dialog "Please Select an Image"

                                                    end try

                                                end if

                                             

                                                --edit original opens the link in PS

                                                edit original i

                                             

                                                --in Photoshop get every layer comp as a list

                                                tell application "Adobe Photoshop CC 2014"

                                                    set clist to name of every layer comp of current document

                                                end tell

                                             

                                                --display a dialog with the list as a dropdown

                                                activate

                                                set myDialog to make dialog with properties {name:"Layer Comps"}

                                                tell myDialog

                                                    tell (make dialog column)

                                                        tell (make dialog row)

                                                            make static text with properties {static label:"Layer Comps:"}

                                                            set compDD to make dropdown with properties {string list:clist, selected index:0, min width:300}

                                                        end tell

                                                    end tell

                                                end tell

                                                --gets the choice

                                                set myResult to show myDialog

                                                if myResult = true then

                                                    set myLayerComp to item ((selected index of compDD) + 1) of clist

                                                else

                                                    return

                                                end if

                                                destroy myDialog

                                             

                                                --apply the choice in PS and save. Note that I'm activating here.

                                                --Makes it a bit more clunky but looks like you need it to get the link to auto update

                                                tell application "Adobe Photoshop CC 2014"

                                                    activate

                                                    tell current document

                                                        set lc to every layer comp whose name is myLayerComp

                                                        apply lc

                                                        save

                                                        close

                                                    end tell

                                                end tell

                                                activate

                                            end tell

                                            • 19. Re: GraphicLayerCompositions not scriptable? AS
                                              rob day Adobe Community Professional & MVP

                                              I tested a bit more thoroughly and it looks like occasionally when you use the edit original command the PS document isn't there. Doesn't seem to relate to file size a 1GB file is working fine, so i added a try in to catch a Photoshop error.

                                               

                                              Here it is with handlers:

                                               

                                              tell application "Adobe InDesign CC 2014"

                                                  activate

                                                 

                                                  --edit original opens the link in PS

                                                  edit original my getImageLink(selection of active document)

                                                 

                                                  --in Photoshop get every layer comp as a list

                                                  tell application "Adobe Photoshop CC 2014"

                                                      activate

                                                      try

                                                          set clist to name of every layer comp of current document

                                                      on error

                                                          close current document

                                                          tell application "Adobe InDesign CC 2014"

                                                              activate

                                                              display dialog "No Layer Comps"

                                                              return

                                                          end tell

                                                      end try

                                                  end tell

                                                 

                                                  --get the layer comp choice

                                                  set myLayerComp to my getPSLayerComps(clist, "Layer Comps", "Layer Comps")

                                                 

                                                  --apply the choice in PS and save.

                                                  tell application "Adobe Photoshop CC 2014"

                                                      activate

                                                      tell current document

                                                          set lc to every layer comp whose name is myLayerComp

                                                          apply lc

                                                          save

                                                          close

                                                      end tell

                                                  end tell

                                                  activate

                                              end tell

                                               

                                              --checks that the selection (s) is an image or a frame with an image and gets the link

                                              on getImageLink(s)

                                                  tell application "Adobe InDesign CC 2014"

                                                      if s is equal to {} then

                                                          display dialog "Make a Selection"

                                                          return

                                                      end if

                                                      if class of item 1 of s is image then

                                                          return item link of item 1 of s

                                                      else

                                                          try

                                                              return item link of image 1 of item 1 of s

                                                          on error

                                                              display dialog "Please Select an Image"

                                                              return

                                                          end try

                                                      end if

                                                  end tell

                                              end getImageLink

                                               

                                              --gets the result from a dropdown menu (a list, dialog name, dropdown name)

                                              on getPSLayerComps(lst, dname, lname)

                                                  tell application "Adobe InDesign CC 2014"

                                                      activate

                                                      set myDialog to make dialog with properties {name:dname}

                                                      tell myDialog

                                                          tell (make dialog column)

                                                              tell (make dialog row)

                                                                  make static text with properties {static label:lname}

                                                                  set DD to make dropdown with properties {string list:lst, selected index:0, min width:300}

                                                              end tell

                                                          end tell

                                                      end tell

                                                     

                                                      --get the choice

                                                      set myResult to show myDialog

                                                      if myResult = true then

                                                          return item ((selected index of DD) + 1) of lst

                                                      else

                                                          return ""

                                                      end if

                                                      destroy myDialog

                                                  end tell

                                              end getPSLayerComps

                                              • 20. Re: GraphicLayerCompositions not scriptable? AS
                                                DBLjan Level 2

                                                Guy, guys, guys…

                                                If I can follow you, you suggesting open/edit image in PS, read the name of layer comps, activate it, save it, reimport in InD, last document status is the one it was before…

                                                 

                                                Theoretically this should work, but I tested and the image opens in PS always with the last status, not the one Ive choosen in InD.

                                                 

                                                So this kills the workaround, didn't it?

                                                I only wanted to change the Alpha, but if that'd worked, I loose the name of the comp in InD, so no coworker of mine could tell wich comp it is/should be

                                                 

                                                 

                                                 

                                                 

                                                Bildschirmfoto 2015-03-11 um 09.23.36.png

                                                 

                                                 

                                                 

                                                Bildschirmfoto 2015-03-11 um 09.25.17.png

                                                 

                                                 

                                                Bildschirmfoto 2015-03-11 um 09.23.55.png

                                                PS throws this, even if I open both links after another.

                                                • 21. Re: GraphicLayerCompositions not scriptable? AS
                                                  Laubender Adobe Community Professional & MVP

                                                  @Jan – of course PhotoShop would open the last saved status. If InDesign could manipulate the PhotoShop file by chosing a different layer comp would bring chaos to other placed instances of the psd file elsewhere.

                                                   

                                                  Right now I see no way out of your dilemma, Jan.

                                                   

                                                  @Rob – Yet didn't have time enough to test your scripts and thinking this through enough…

                                                   

                                                  Uwe

                                                  • 22. Re: GraphicLayerCompositions not scriptable? AS
                                                    rob day Adobe Community Professional & MVP

                                                    Theoretically this should work, but I tested and the image opens in PS always with the last status, not the one Ive choosen in InD.

                                                    Try running my sample script. We all agree that the layer comps dropdown isn't scriptable, so the sample script assumes you won't attempt to use the Image layer options at all. If we leave Layer Comps as Last Document State and allow layers to be changed on an update the current layer comps  showing in the layout can be controlled from Photoshop.

                                                     

                                                    My script picks up all of the available comps and populates a drop down, but you could also feed it a list of layer comp names. You could have 5 images all with layer comps named a, b, and c then set them all to layer comp b via Photoshop.