4 Replies Latest reply on Apr 19, 2012 2:34 AM by BalboNicolas

    Problem with a script to remove graphics

    BalboNicolas

      Hello,

       

      I have tried to build a javascript to remove all graphics whose extension is not ".EPS" (with "EPS" really in upper cases, as it is for Mathtype equations in Word import).

      But It doesn't work and I can't understand why.

       

      Here is the script:

       

      //The script intend to remove all graphics whose extension is not ".EPS"

       

      var myDoc = app.activeDocument;

      var myGraphics = myDoc.allGraphics

       

      //Remove graphic if graphic extension is different from ".EPS"

       

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

          var myImage = myGraphics[p]

          if (CheckExtEps(myImage) != 0){

          myImage.remove ()

          }

      }

      //Compare graphic extension with ".EPS" and return myExtValue = 0 if it matches exactly

       

      function CheckExtEps(myImage) {

          var  myString = myImage.name

          myExt = myString.substr(myString.lastIndexOf( "." ))

          myExtValue = myExt.localeCompare(".EPS")

          return myExtValue

          }

       

      When I run this script, ALL the graphics are removed, ".EPS" included.

      I do have ".EPS" graphics in my document and I expected them not to be removed.

      So there is something wrong somewhere, but I don't know what to change.

       

      Any ideas?

       

      By the way, I have a more generic question as a beginner:

      I am working with ExtendScript Toolkit. How can I do to check my script step by step?

      For exemple, how can I display my variables values as "myString", "myExt", "myExtValue" at each step?

       

      Actually, this script is a step for a bigger script I intend to build to deal with Mathtype equations in Word import.

      After not-EPS graphics beeing removed, I wish to relink all remaining equation prewiews to eps in a selected folder, by consecutive order.

      But this is a big piece of scripting to swallow for me, so I'm working slowly, step by step.

       

       

      TIA

       

      Best regards

       

      Nicolas

        • 1. Re: Problem with a script to remove graphics
          TᴀW Adobe Community Professional & MVP

          Well, I can't see any semicolons in your script. Maybe that's just the

          email interface, but there should be semicolons at the ends of lines.

           

          In the ESTK, you can step through a script a line at a time. Just click

          on the downwards pointing arrow instead of the "play" arrow. Each time

          you click, the script will advance one line. In the Console window

          (Windw>Console) you can then type the name of the variable you wish to

          examine.

           

          Ariel

          • 2. Re: Problem with a script to remove graphics
            BalboNicolas Level 1

            Hello Ariel

             

            Thank you very much for your help.

             

            1. I added semicolons at the end of lines, but the script result is the same.

             

            2. Running line by line, I could see in the Console where is the problem:

            variable "myString" is always undefined.

             

            Well, I have to get more inside my script...

             

            Thank's again

             

            Best regards

             

            Nicolas

             

             

             

            Nicolas BALBO  

             

            balbon3@orange.fr

             

            22, rue d'Hauteville  75010 PARIS

            Tel : 33 (0)1 42 57 14 31

             

             

             

             

             

             

            Le 18 avr. 2012 à 17:36, Arïel a écrit :

             

            Re: Problem with a script to remove graphics

            created by Arïel in InDesign Scripting - View the full discussion

            Well, I can't see any semicolons in your script. Maybe that's just the

             

            email interface, but there should be semicolons at the ends of lines.

             

             

            In the ESTK, you can step through a script a line at a time. Just click

             

            on the downwards pointing arrow instead of the "play" arrow. Each time

             

            you click, the script will advance one line. In the Console window

             

            (Windw>Console) you can then type the name of the variable you wish to

             

            examine.

             

             

            Ariel

             

            Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4344039#4344039

            To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4344039#4344039. In the Actions box on the right, click the Stop Email Notifications link.

            Start a new discussion in InDesign Scripting by email or at Adobe Forums

            For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

             

            • 3. Re: Problem with a script to remove graphics
              [Jongware] Most Valuable Participant

              It's not myString that's undefined, but rather myImage.name. Try with myImage.itemLink.name instead; that will yield the *file* name: http://jongware.mit.edu/idcsjs5.5/pc_Image.html#itemLink

              • 4. Re: Problem with a script to remove graphics
                BalboNicolas Level 1

                Yes, it work!

                 

                Thank's a lot!

                 

                For information, what is the difference between graphic.name and graphic.itemLink.name?

                I understood that the file name is yield by itemLink.name, but what is yield by .name alone?

                 

                 

                Nicolas BALBO  

                 

                balbon3@orange.fr

                 

                 

                 

                 

                 

                 

                Le 18 avr. 2012 à 19:12, a écrit :

                 

                Re: Problem with a script to remove graphics

                created by in InDesign Scripting - View the full discussion

                It's not myString that's undefined, but rather myImage.name. Try with myImage.itemLink.name instead; that will yield the file name: http://jongware.mit.edu/idcsjs5.5/pc_Image.html#itemLink

                 

                Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4344282#4344282

                To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4344282#4344282. In the Actions box on the right, click the Stop Email Notifications link.

                Start a new discussion in InDesign Scripting by email or at Adobe Forums

                For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.