9 Replies Latest reply on Apr 23, 2010 8:20 AM by Osinho2

    Find and delete graphic lines by geometric bounds

    Osinho2 Level 1

      Hi everybody,

       

      I am really desperate after days browsing the web and forums I still can't figure this out.

       

      I am working on InDesign CS3 on a MacBook Pro with Snow Leopard.

       

      I have a 300 page catalog put together through a data merge. Unfortunately this way I produce 2 graphic lines at the end of each page that I would rather like to delete. Since I do not want to do that manually on each page and since I will have to put together this catalog quite frequently in the future I would like to delete those lines using Applescript.

       

      Since I have about 12 more of the same lines on each page (same style, color, stroke etc) I figured the only way to tell Applescript which ones to delete is by geometric bounds because those lines are always at the same coordinates on each page.

       

      Unfortunately I cannot figure it out. I tried the following code:

       

      tell application "Adobe InDesign CS3"
           tell document 1
                repeat with oneFrame in (get graphic lines whose stroke weight = 1)
                     if geometric bounds of oneFrame is {0, 0, 0, 210} then
                          delete oneFrame
                     end if
                end repeat
           end tell
      end tell
      
      
      

      REPLY

      tell application "Adobe InDesign CS3"
           get every graphic line of document 1 whose stroke weight = 1
                --> {graphic line id 187 of page id 177 of spread id 172 of document "Untitled-16"}
           get geometric bounds of graphic line id 187 of page id 177 of spread id 172 of document "Untitled-16"
                --> {0.0, 0.0, 0.0, 210.0}
           delete graphic line id 187 of page id 177 of spread id 172 of document "Untitled-16"
      end tell
      
      
      

       

      This worked fine for the line placed at x 0mm y 0mm with a length of 210mm.

       

      I tried the same thing with a line at x 3mm y 134mm length of 210mm with the following code

       

      tell application "Adobe InDesign CS3"
           tell document 1
                repeat with oneFrame in (get graphic lines whose stroke weight = 1)
                     if geometric bounds of oneFrame is {134, 3, 134, 213} then
                          delete oneFrame
                     end if
                end repeat
           end tell
      end tell
      
      
      
      

      REPLY:

      tell application "Adobe InDesign CS3"
           get every graphic line of document 1 whose stroke weight = 1
                --> {graphic line id 213 of page id 177 of spread id 172 of document "Untitled-16"}
           get geometric bounds of graphic line id 213 of page id 177 of spread id 172 of document "Untitled-16"
                --> {134.0, 3.0, 134.0, 213.0}
      end tell
      
      

       

       

      This was my best shot. No idea if I am on the right track or totally off bounds.

       

      Any help would be highly appreciated!

       

      Thanks in advance..

       

      Osinho

        • 1. Re: Find and delete graphic lines by geometric bounds
          Mary Posner Level 3

          Your code worked for me when I made a line at those coordinates and then ran your script. I'm not on Snow Leopard, so don't know if that would make a difference.

           

          'Course, the following also worked for me, without gathering every reference to every graphic line or stepping through repeat loops:

           

          delete (every graphic line whose (geometric bounds = {134, 3, 134, 213}))

           

          I just had to make sure the ruler was set Page rather than Spread, but then it deleted everything I expected it to. You could also add in the qualifier about the stroke weight if you think there's a possibility there might be another graphic line at that location with a different weight that you *did* want to keep.

           

          Give it a try, anyway, see if it does what you want. (But try it on a duplicate document in case it doesn't!)

          1 person found this helpful
          • 2. Re: Find and delete graphic lines by geometric bounds
            Mary Posner Level 3

            Another little oddity -- I just tested it some more, and my single line of code worked with only those items on the right-hand pages, but ignored the left. But I changed the bounds to show the ".0" on each of the measurements and it worked on both sides of the spread.

            1 person found this helpful
            • 3. Re: Find and delete graphic lines by geometric bounds
              Osinho2 Level 1

              Dear Mary,

               

              Thank you very much for you replies!

              I am away from my desk (in a meeting - god bless the iPhone ).

               

              As soon as I get back I will test it and let you know...

               

              What do you think, would it be possible to just delete all lines of a certein y value, disregarding whatever x value they have?

              (its 2 lines each page with the same y values and different x values i need to get rid off)

               

              Thanks again!!!!

              • 4. Re: Find and delete graphic lines by geometric bounds
                Mary Posner Level 3

                As long as you can be absolutely 100% certain that you aren't going to accidentally delete something that you really want to keep, you could do it that way.

                • 5. Re: Find and delete graphic lines by geometric bounds
                  Osinho2 Level 1

                  H Mary,

                   

                  Thanks again!

                   

                  Just got back to my desk and will test it right now....

                   

                  Regarding the delete only lines with a certain y value.

                  How would I best do that? I'm still a newbie

                   

                  Thank you!

                  • 6. Re: Find and delete graphic lines by geometric bounds
                    Mary Posner Level 3

                    Take a look at what values are showing for the geometric bounds. Those numbers relate to your x and y coordinates, and you refer to them by their item number in the list, e.g. item 1 is the first "134.0" in your list, item 2 is the "3.0" etc. So you'd refer to "whose item 2 of geometric bounds = [whatever value you're trying to match]".

                     

                    If your document is very complicated, I think I would add in another modifier to make sure you're getting the right things, say if these lines have a color applied that isn't used on other graphic lines in the document or if their stroke weight is different, or even testing two items out of the geometric bounds list if there are two that show up consistently in all the items you want to delete -- something to make sure that you're ONLY getting references to the items you want and don't risk deleting something you need to keep.

                     

                    Good luck, and welcome to AppleScript!

                    • 7. Re: Find and delete graphic lines by geometric bounds
                      Osinho2 Level 1

                      Good Morning Mary,

                       

                      Thank you for your reply.

                       

                      I found a solid solution using a different approach.

                       

                      It seems like the geometric bounds selector is not accurate for values with decimal values like 149.267 because in reality this value is 149.266666666666666666666667 (period 6). Since some of my lines have such a pattern it just won't work (that's the only explanation I could come up with...)

                       

                      Nevertheless here my solution:

                      The lines that have to be removed are always the last 2 lines of a total of 12 lines on a page. Knowing that I incorporated a running index telling the script "please delete only the lines with index 11 and 12" once the max count of 12 per page is reached I reset the index so it starts from scratch for the next page. Works like a charm!

                      (don't get confused because I count down from 12 to 1 - this needed to be done because the loop starts at the bottom of the page rather than at the top)

                       

                      Here the code:

                      tell application "Adobe InDesign CS3"     
                           tell document 1
                                set lCount to 12
                                repeat with oneFrame in (get graphic lines whose stroke weight = 1)
                                     if (lCount is 12 or lCount is 11) then
                                          delete oneFrame
                                     end if
                                     if lCount is 1 then
                                          set lCount to 13
                                     end if
                                     set lCount to lCount - 1
                                end repeat          
                           end tell
                      end tell
                      
                      
                      

                       

                      Thank you very much for your assistance!

                      Highly appreciated!

                       

                      Have a great weekend...

                       

                      Osinho

                      • 8. Re: Find and delete graphic lines by geometric bounds
                        [Jongware] Most Valuable Participant
                        .. 149.266666666666666666666667 ..

                         

                        You are right about this; it's even worse!

                         

                        (dramatic pause for effect)

                         

                        Oh well, it's just a tiny bit -- unless you happen to need it in a script!

                        If you select one of your lines and type "149 mm" to set its position, ID will report you back the line is at 149 mm. Seems to be no problem -- except ID's internal values are measured in points, not in mm. That means that your value gets converted to points (for internal storage), and it gets converted back for display. This twice-rounded value may actually be something like 4223.62205 pts (several more insignificant decimals omitted). So (one might think) all you have to do is set your measurement to points, to get the "real" value. Err ... no. ID only displays two or three decimals after the digit -- in this case, you'd see something like "4223.62 pts". That's not good enough -- if you test if a line "is" at 4223.62 pts (or, for that matter, 149 mm), those pesky extra digits of precision will almost certainly make the test fail.

                         

                        If you are fairly certain your lines are in the neighbourhood of 149 mm, and definitely not more than 2 mm higher or lower, you can test for any in-between value like this:

                         

                        if (line.geometricBounds[0] >= 147 && line.geometricBounds[0] <= 151)

                           ... delete line ...

                         

                        That's in Javascript notation because I wouldn't know what end of an Applescript I should start reading at . The line.geometricBounds[0] stuff is to refer to the first element of the geometricsBounds array, which ought to contain the topmost y coordinate.

                        • 9. Re: Find and delete graphic lines by geometric bounds
                          Osinho2 Level 1

                          Hi Jongware,

                           

                          Thank you for looking into this.

                           

                          Yeah I was suspecting something like this...nasty little detail that!

                           

                          Great forum!

                           

                          Thanks again

                           

                           

                          Osinho