3 Replies Latest reply on Apr 23, 2012 6:35 AM by Laubender

    How to access the visibility of layer comps in indesign through scripting? [JS][CS5.5]

    Mr mattaias

      Hi,

       

       

      I'm pretty new to scripting in adobe, but I thought this should be a simple one (think again...):

       

      I wanted to go over an array of all the psd-images in a selection or on a page in indesign, and then try to set their layer comp to a specific one (like "Diffuse".

      In photoshop I could make an action that would do this for me, but it seems that there are no easy ways in Indesign to do this.

       

      There also seems no way to change the layer comp or layer visibility for multiple selection...

      If anyone knows if it is possible at this moment to use layer comps in scripting (and how) or some kind of action for Indesign, I'll try to tackle the rest of the problem myself (and be forever grateful).

      If it isn't possible, I how it will be in CS6.

       

       

      Thanks to anyone interested,

       

      Mattaias

       

       

       

      ps: currently trying to solve this in JavaScript for CS5.5.

        • 1. Re: How to access the visibility of layer comps in indesign through scripting? [JS][CS5.5]
          Laubender Adobe Community Professional & MVP

          @Mattaias – see the following links to Jongware's DOM documentation of InDesign CS5.5:

           

          http://jongware.mit.edu/idcsjs5.5/pc_Image.html

          http://jongware.mit.edu/idcsjs5.5/pc_GraphicLayerOption.html
          http://jongware.mit.edu/idcsjs5.5/pc_GraphicLayer.html

           

          and play around with "currentVisibility" and "viewState" properties.

           

          To apply specific properties for multiple selection you have to loop through all single selected placed PSD files.
          Of course you have to do some checks, if a certain graphic layer is there, how the state is etc.pp.:

           

          var mySelection = app.selection;
          
          for(var n=0;n<mySelection.length;n++){
              if(mySelection[n].graphics.length === 1 && mySelection[n].graphics[0].imageTypeName === "Photoshop"){
                  //Do your stuff on the selected frame or on the individual placed PSD file:
          
                  //Just some sample code:
                  //On the frame that holds the PSD:
                  mySelection[n].fillColor = "Yellow";
          
                  //On the placed PSD itself:
                  alert(mySelection[n].graphics[0].itemLink.name);
                  };
              };
          

           

          I think that will get you on your way…

           

          If you want to change layer contents you could use BridgeTalk to start PhotoShop, altering the contents, save the result and relink again in InDesign.

           

          Uwe

          • 2. Re: How to access the visibility of layer comps in indesign through scripting? [JS][CS5.5]
            Mr mattaias Level 1

            Thanks for the information so far, but I've been looking at the links you added and haven't found anything about the scripting of layer comps...

            Here is the adjusted sample of your code:

             

            function Main() {

                var mySelection = app.selection;

             

                for(var n=0;n<mySelection.length;n++){

                    if(mySelection[n].graphics.length === 1 && mySelection[n].graphics[0].imageTypeName === "Photoshop"){

                        //Do your stuff on the selected frame or on the individual placed PSD file:

                

                        // Adjusted Sample code:

                        mySelection[n].images[0].graphicLayerOptions.graphicLayers.itemByName("Heat").currentVisib ility = true;

                        alert(mySelection[n].images[0].graphicLayerOptions.graphicLayers.itemByName("Heat").curre ntVisibility);

                    };

                };

            }

             

            but what I actually need is more like

            mySelection[n].images[0].graphicLayerOptions.graphicLayerComps.itemByName("Heat").currentVisibility = true;

             

            It seems a bit strange (or I am looking on the wrong places) but there is no way to access layer comps in Indesign.

            Do I have to change the file in PhotoShop and save to get the result I need? Looks a bit strange that there isn't a more logical way then...

            The reason I want to script this, is because when there are 100 PSD's on one page and they should al get the same Layer Comp... you have to do this manually for every image.

            I like to use this feature to build texture-atlasses and have a dynamic result, but at this moment it would take at least 10 seconds for every picture... for 3 pages, and that for 7 files (and even more in the future).

             

            If anybody has ever scripted something with LayerComps, please let me know. (and something like recording Actions in photoshop is equally usefull)

            Otherwise I guess the Adobe programmers just didn't want to share this feature yet in CS5.5.

            • 3. Re: How to access the visibility of layer comps in indesign through scripting? [JS][CS5.5]
              Laubender Adobe Community Professional & MVP

              Sorry, but it seems that "LayerComps" are left out of the scripting DOM for InDesign in JavaScript.
              Even the "ImageIOPreferences" do not mention them.

               

              Btw. you can tell if a GraphicLayer is a "layer group" in InDesign, if its property "sectionDividerLayer" is "true". Then dive into the group with a for-loop looking for "length", "name" etc.

               

              See code for getting layers inside layers of a placed PhotoShop image:

               

              var gLayers = app.selection[0].graphics[0].graphicLayerOptions.graphicLayers;
              
              for(var n=0;n<gLayers.length;n++){
              
                  $.writeln(gLayers[n].properties.toSource());
                  $.writeln(gLayers[n].name);
              
                  if(gLayers[n].sectionDividerLayer === true){
                      var subLayer = gLayers[n].graphicLayers;
                      for(var g=0;g<subLayer.length;g++){
                          
                          $.writeln("\t"+subLayer[g].properties.toSource());
                          $.writeln("\t"+subLayer[g].name);
              
                          };
                      };
                  };
              

               

              Maybe other properties besides "viewState" of a GraphicLayer do correspond with LayerComps properties in PhotoShop?
              If so maybe we could check the comps in PhotoShop, record their properties, and use that information in InDesign.

              But that is plain speculation on my side.

               

              Uwe

              1 person found this helpful