11 Replies Latest reply: May 16, 2012 6:34 PM by Kevin Parrott RSS

    Applescript: delete object from page

    ax1e2l_b3r4a5s6s Community Member

      I'm trying to remove an objects from a page with a known name.

       

      I've name the object theLine.  It's a drawn line.  Under certain conditions, I want to delete it.

       

      Other object is a placed graphic name theImage.  Under certain conditions, I want to delete it as well.

       

      Keep trying various iterations, but not even coming close. 

        • 1. Re: Applescript: delete object from page
          ax1e2l_b3r4a5s6s Community Member

          Disregarding the object and focusing on the lines, i keep trying iterations of this, but to no avail:

           

          tell application "Adobe InDesign CS5.5"

                    set theTopRule to the graphic line "SolidSigLineTop"

                    set theBottomRule to the graphic line "SolidSigLineBottom"

                    if theSigLineCount = 2 and theSigMicroPrint = "Y" then

            delete theTopRule

            delete theBottomRule

                    end if

           

          end tell

           

          results in:

           

          error "Adobe InDesign CS5.5 got an error: Can’t get graphic line \"SolidSigLineTop\"." number -1728 from graphic line "SolidSigLineTop"


          • 2. Re: Applescript: delete object from page
            Kevin Parrott Community Member

            Hi

            does this work?

             

             

            tell application "Adobe InDesign CS5.5"

                delete (every graphic line of document 1 whose label is "SolidSigLineTop")

            end tell

            • 3. Re: Applescript: delete object from page
              ax1e2l_b3r4a5s6s Community Member

              No.  No error, but no deletion.

               

              Also tried

               

              delete (every graphic line whose label is "SolidSigLineTop")

               

              and

               

              delete (graphic line "SolidSigLineTop")

               

              Still not working.

              • 4. Re: Applescript: delete object from page
                Kevin Parrott Community Member

                try this

                 

                 

                tell application "Adobe InDesign CS5.5"

                    set myDoc to active document

                    tell myDoc

                        try

                            set AllGraphicLines to {"SolidSigLineTop", "SolidSigLineBottom"} as string

                            set myGraphicline to (every graphic line whose label is in AllGraphicLines)

                            delete myGraphicline

                        on error

                            display dialog "no graphic line/s with this name exists"

                        end try

                    end tell

                end tell

                • 5. Re: Applescript: delete object from page
                  ax1e2l_b3r4a5s6s Community Member

                  got the display dialog error in the on error portion of the try statement!

                   

                  Is the line I drew on the page not a graphic line?!?!?!??!??!

                   

                  I guess the other option is that the name is not right.  I named the element under the layers, the same way I did with some Text Rectangles, etc.  Assumed that was right.

                  • 6. Re: Applescript: delete object from page
                    Kevin Parrott Community Member

                    the script assumes that you have a line/stroke on your page and that the stroke is labled in "Script Label", (window/utilities/Script Label), as we

                    are looking for it's label   "every graphic line whose label is"  .

                     

                    you say you've named the layer, very differnt.

                     

                    to label your stroke, select it, open "window/utilities/Script Label"  enter your strokes name, deslect the stroke, run the script, works fine here

                     

                    if you need to delete layers, let me no and ill alter the code for you.

                     

                    kp

                    • 7. Re: Applescript: delete object from page
                      Kevin Parrott Community Member

                      heres some code to delete specific layers

                       

                       

                       

                      tell application "Adobe InDesign CS5.5"

                          activate

                          set myDoc to active document

                          tell myDoc

                              try

                                  set AllLayers to {"SolidSigLineTop", "SolidSigLineBottom"} as string

                                  set myLayer to every layer whose name is in AllLayers

                                  delete myLayer

                              on error

                                  display dialog "no layer/s with this name exists"

                              end try

                          end tell

                      end tell

                      • 8. Re: Applescript: delete object from page
                        ax1e2l_b3r4a5s6s Community Member

                        I wasn't very clear - sorry.

                         

                        I named the item under the layer.

                         

                        Layer 1 in the layers window, expanded it, shows all the elements.

                         

                        Named the items there.  In this case, renamed the reference to the line.

                         

                        Then I can manipulate each element by it's name.

                         

                        I've used this with text rectangles tons, and it works fine.  Never heard of the script label.  Must be different for lines?

                        • 9. Re: Applescript: delete object from page
                          Kevin Parrott Community Member

                          ahh, i see, sorry, try this,  you need ot tell your doc to do what you need it ot do

                           

                          tell application "Adobe InDesign CS5.5"

                              activate

                              set myDoc to active document

                              tell myDoc

                                  set theTopRule to the graphic line "SolidSigLineTop"

                                  set theBottomRule to the graphic line "SolidSigLineBottom"

                                  delete theTopRule

                                  delete theBottomRule

                              end tell

                          end tell

                          • 10. Re: Applescript: delete object from page
                            ax1e2l_b3r4a5s6s Community Member

                            Wonderful.  Sorry about the lack of clarity.  Applescripting applications has me more than a little confused.  Works, of course, now that I explained it completely!

                             

                            What is the reference for an object placed on the page??  (tiff file added using the place command)

                             

                            I need to perform the same function to that object as well - possible deletion.

                             

                            Thanks again.  This forum is EXCELLENT!

                            • 11. Re: Applescript: delete object from page
                              Kevin Parrott Community Member

                              give this a spin

                               

                               

                               

                              tell application "Adobe InDesign CS5.5"

                                  activate

                                  set myDoc to active document

                                  tell myDoc

                                      set theTopRule to the graphic line "SolidSigLineTop"

                                      set theBottomRule to the graphic line "SolidSigLineBottom"

                                      delete theTopRule

                                      delete theBottomRule

                                     

                                      --delete graphic

                                      set PlacedImage to rectangle "TEST" -- the image is automatically place in a rectangle

                                      delete PlacedImage

                                     

                                  end tell

                              end tell