8 Replies Latest reply on Jun 13, 2016 10:59 PM by Ravindra_KCS

    Add script label to Inline Graphic

    sr48262525

      Hi

       

       

      I currently have a document containing 1000's of inline .eps icons that I want to tag with a script label depending on  which icon is found.

       

       

      So far I have the following that doesn't work…

       

      tell application "Adobe InDesign CC 2015"

        

         tell document 1

       

      repeat with target in (get stories's all graphics)

                

                 if target's link name contains "FileName1" then

                     set target's parent's parent's label to "FileName1"

                 end if

                

             end repeat

            

            

         end tell

      end tell

       

       

      I have this that does work but I need to test individual link names for different script tags…

       

      tell application "Adobe InDesign CC 2015"'s document 1 to repeat with target in (get stories's all graphics) --anchored objects

         set target's parent's parent's label to "FileName1"

      end repeat

      thanks

       

       

      Shane

        • 1. Re: Add script label to Inline Graphic
          Ravindra_KCS Level 1

          hi Shane;

           

          try this javascript if it work will convert the same in AppleScript.

           

          var myDoc= app.activeDocument;

          var myGraphics=myDoc.stories[0].allGraphics;;

          for(var i=0 ; i < myGraphics.length ; i++)

          {

                var myName= myGraphics[i].itemLink.name;

                      myName=myName.replace(".eps","");

                      myGraphics[i].label = myName;

          }

           

          Thanks

          Ravindra

          • 2. Re: Add script label to Inline Graphic
            sr48262525 Level 1

            Thank you! Works perfect.

             

            If it isn't too much trouble to convert to applescript as I have very little knowledge of javascript.

             

            thanks again.

            • 3. Re: Add script label to Inline Graphic
              Laubender Adobe Community Professional & MVP

              sr48262525 wrote:

              … Works perfect.

               

              Hello Shane,

              I can only help with ExtendScript (JavaScript), not with AppleScript.

               

              Nevertheless some notes on the script snippet from Ravindra from answer #1:

               

              1. The scope of the script above is the first story of the document. The story with index 0 .

              Other stories are left alone. Though, I don't know how many stories your document has…

               

              If you want to access every story, you could use app.documents[0].stories.everyitem().allGraphics .
              In ExtendScript that would create an array of arrays. Even with only one story in the document.

              So you will need another loop inside the loop to access the graphics.

              ( I don't know, if a construction like that will create a List of List objects with AppleScript. )

               

              2. If other graphics are placed in that story, that are not of image type name "EPS", they will also be labeled.

               

              And their labels will contain their suffixes. Don't know, if you want this.

              ( You did not tell why you want to label the EPS graphics )

               

              3. There is a better suffix-replace-with-nothing algorithm for file names.

              In the code above a placed graphic named "icon.epson.print365.eps" will be labeled "iconon.print365.eps".

              Why? Because the first found substring ".eps" in a file name will be replaced with nothing ( = removed).

               

              The following regular expression should do:

               

              myName = myName.replace(/\.eps$/i,"");
              

               

              But maybe you'd like to get the graphic's name plus suffix?

               

              4. Graphics in InDesign documents can be placed or copy/pasted from somewhere else. Maybe not in your document, but it could happen with documents from someone else. If a graphic was pasted, the link property has the value null in ExtendScript, Ravindra's for-loop will throw an error and will break. So you'll have to test every graphic for the value of its itemLink property. If the value is null, write something special to its label or continue the loop and do nothing with the label.

               

               

              Uwe

              • 4. Re: Add script label to Inline Graphic
                Kai Rübsamen Adobe Community Professional

                Hi Uwe,

                 

                if I test this in InDesign CC2015.2, the scripts panel is empty, but the ESTK shows, that the label is set.

                Can you confirm this? Anything that is wrong with my lines?

                 

                var graphicsList = app.activeDocument.stories.everyItem().allGraphics;
                
                for (var i = 0; i < graphicsList.length; i++) {
                  var curList = graphicsList[i];
                  for (var j = 0; j < curList.length; j++) {
                    var curGr = curList[j];
                    var iLink = curGr.itemLink;
                    if (iLink.linkType == "JPEG") {
                      var strName = iLink.name.replace(/\.JPG$/i, "");
                      curGr.label = strName;
                    }
                  }
                }
                

                thanks

                Kai

                • 5. Re: Add script label to Inline Graphic
                  Laubender Adobe Community Professional & MVP

                  Hi Kai,

                  just tested your script with InDesign CS6 v8.1.0 on OSX 10.7.5.

                  It worked as expected. Note: I used "EPS" as string for linkType instead of "JPEG".
                  But this should make no difference.

                   

                  Next will be a test with InDesign CC 2015.3.

                  Version .2 is not installed on my Mac.

                   

                  Uwe

                  • 6. Re: Add script label to Inline Graphic
                    Kai Rübsamen Adobe Community Professional

                    Hi Uwe,

                     

                    what a stupid misstake ;-) I checked the parent rectangle instead of the graphic. Now it works. Sorry for the confusion. Thanks for the explanation.

                     

                    Kai

                    • 7. Re: Add script label to Inline Graphic
                      Laubender Adobe Community Professional & MVP

                      Kai Rübsamen wrote:

                      I checked the parent rectangle instead of the graphic.

                      That's understandable…
                      I once ran into the same thing.

                       

                      Here a version where I check the itemLink for value null .
                      And wrapped into a doScript() to get one single undo for all the script's actions:

                       

                      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
                      
                      app.doScript
                      (
                         
                          writeNameOfEPStoLabel,
                          ScriptLanguage.JAVASCRIPT,
                          [],
                          UndoModes.ENTIRE_SCRIPT,
                          "writeNameOfEPStoLabel | SCRIPT"
                         
                      );
                         
                      function writeNameOfEPStoLabel()
                      {
                      
                          var graphicsList = app.activeDocument.stories.everyItem().allGraphics; 
                      
                          for (var i = 0; i < graphicsList.length; i++)
                          {
                              var curList = graphicsList[i];
                             
                              for (var j = 0; j < curList.length; j++)
                              { 
                                  var curGr = curList[j];
                                  var iLink = curGr.itemLink;
                                  if(iLink == null){continue};
                                  if (iLink.linkType == "EPS")
                                  { 
                                      var strName = iLink.name.replace(/\.EPS$/i, ""); 
                                      curGr.label = strName;
                                  } 
                              } 
                          };
                      
                      };
                      

                       

                      Uwe

                      • 8. Re: Add script label to Inline Graphic
                        Ravindra_KCS Level 1

                        Hi Uwe

                                    Very thanks.....

                         

                        Regards

                        Ravindra