6 Replies Latest reply on Apr 1, 2016 1:53 AM by tpk1982

    Object layer option for selective links

    tpk1982 Level 4

      Hi,

       

      I need to turn off 'shadow' layer for only selective images. I found this script from forum. But it will turn off to all graphics, not selected. I don't seem any error in his coding.

       

      Any one please help me to sort this problem.

       

       

      var myDoc = app.activeDocument;  
      var myGraphics = myDoc.links;  
      for (var i = myGraphics.length-1; i >= 0; i--){  
          var myArt = myGraphics[i];   
          var myStry = myArt.parent;  
          app.select(myStry);  
          var mySel = app.selection[0];  
          try{  
              var myGraphs  = mySel.parent.graphics[0].graphicLayerOptions.graphicLayers;  
              for (a=myGraphs.length-1; a>=0; a--){  
                  if(myGraphs[a].name =='Shadow'){//here you can as the layer name you want switch off the visibility.  
                      myGraphs[a].currentVisibility=false;  
                      }  
                   if(myGraphs[a].name =='shadow'){//here you can as the layer name you want switch off the visibility.  
                      myGraphs[a].currentVisibility=false;  
                      }  
                  }  
              }catch(e){}  
              app.selection = null;  
              }  
            
      

       

      Regards,

      Karthi

        • 1. Re: Object layer option for selective links
          tpk1982 Level 4

          This is the method i tried:

           

          var input = ['Shadow','shadow']/*Names of Layers to switch on or off*/
              var onOrOff = false /*true = visible, false = not visible*/; 
              var log="" ;
              var csv;
              var flagVisible = [];
              var fname = [];
              var fpath = [];
              main();
              function main(){
                  var currDocGraphics = app.activeDocument.allGraphics; 
                  l = currDocGraphics.length; 
                  var docname=app.activeDocument.name;
                   
                  while(l--){ 
                      currImage = currDocGraphics[l];
                      if(currImage.imageTypeName == 'Photoshop'){ 
                          i = input.length; 
                          while(i--){ 
                              try{
                                  var mylinkfile=currImage.itemLink.name;
                                  if( currImage.graphicLayerOptions.graphicLayers.itemByName(input[i]).currentVisibility==true){
                                      currImage.graphicLayerOptions.graphicLayers.itemByName(input[i]).currentVisibility = onOrOff;
                                      flagVisible.push(mylinkfile);
                                      }
                                  } catch (e){ } 
                              } 
                          } 
                      }
                 
                  if(flagVisible.length>0){
                      alert("\nShadow layer is TURNED OFF for the following files:\n\n"+flagVisible.join("\n"));
                      }
                  else
                  {
                      alert("\nNo Shadow layer TURNED OFF")       
              }
              }
          
          • 2. Re: Object layer option for selective links
            Ronald63 Level 4

            Hi,

             

            Replace line 20 to 24 by

            
            
            
            var myLayer =currImage.itemLayer;                      
             
            
            
            
            if( myLayer.name==input[i] && myLayer.visible){  
                myLayer.visible = onOrOff;  
                flagVisible.push(mylinkfile);  
            }
            
            • 3. Re: Object layer option for selective links
              tpk1982 Level 4

              Hi Ronald,

               

              Your coding is turn off the layer palette of Indesign. But the question is regarding the name available in object layer option.

               

              Screen Shot 2016-04-01 at 12.08.38 PM.png

               

              Thanks,

              Karthi

              • 4. Re: Object layer option for selective links
                Ronald63 Level 4

                Hi Karthi,

                 

                Sorry for my confusion ;-). What exactly is your problem?

                • 5. Re: Object layer option for selective links
                  tpk1982 Level 4

                  Hi Ronald,

                   

                  I need to check the name of 'Shadow' layer enabled or not in Object Layer Options. The coding what i gave is working fine and it will check and reset for all document images. But my requirement is, i need to check and do changes in only the selected images. I may select 2 or 3 images out of 20 /30 from the document.

                   

                  Hope it is clear.

                   

                  Regards,

                  Karthi

                  • 6. Re: Object layer option for selective links
                    tpk1982 Level 4

                    Hi Ronald,

                     

                    I found the result myself.

                     

                    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"){
                                alert(mySelection[n].images[0].graphicLayerOptions.graphicLayers.itemByName("Shadow").currentVisibility+"  --->"+mySelection[n].graphics[0].itemLink.name);
                            };
                        };
                    }
                    Main()
                    
                    

                     

                     

                    Thanks for your interest in this thread.

                     

                    Regards,

                    Karthi