10 Replies Latest reply on Mar 14, 2011 8:39 PM by John Hawkinson

    Want to mass-delete an object

    Bill Planey Level 1

      I have a 700 page document that has thick rule objects I wish to mass-delete. I am putting them on master pages for consistency and to isolate them to their own layer. The ones I wish to delete are all locked, but are inconsistently positioned.

       

      The Find/Change dialog provides for finding objects that meet certain criteria, but I see no option to DELETE the found object, just to CHANGE it. I realize there is a certain amount of danger in such an option, but If I were to change the objects to some unique color before subsequently searching on that color and deleting them all, that would be a kind of safety step.

       

      As a safer alternative to deleting the objects automatically, I would like the option to move these found objects to their own layer, so that I could just delete the entire layer after reviewing what was placed there.

       

      Can this kind of mass deletion or mass movement to another layer be done?

        • 1. Re: Want to mass-delete an object
          John Hawkinson Level 5

          Sure. This is straightforward. What are the criteria necessary to identify the rules?

           

          Something like this:

           

          var
              i,
              doc = app.activeDocument,
              rules = doc.graphicLines;
          
          for (i=rules.length-1; i>=0; i--) {
              if (rules[i].strokeWeight > 2) {
                  rules[i].remove();
              }
          }
          

           

          That is, declare some variables, then loop over all the rules in the document, and remove those whose strokeWeight is greater than 2 (points). You'll need to check the Adobe object model viewer in the ESTK (ExtendScript Toolkit; script editor) or Jongware's scripting reference in order to determine the name of the property that describes what you want (I used "strokeWeight.").

           

          Any questions?

          • 2. Re: Want to mass-delete an object
            Bill Planey Level 1

            I assume this is javascript. Have never worked with it before. I have done stuff with AppleScript though.

             

            The strokes are 2 points thick, black, and solid (no dashes), but some have been scaled. Would this script find them if their overrides were such that without them, they might not be 2 points? (I manually cleared the overrides on some and they became 1 point.)

             

            The other variables could be that they are > x in length (there are some shorter rules I don't want to delete) and they might be horizontal or vertical, but no other angles other than 0 or 90 degrees.

            • 3. Re: Want to mass-delete an object
              John Hawkinson Level 5

              Well, why not try it? Obviously you'd want to change the "> 2" to ">= 2" or somesuch.

              That is, indeed, Javascript. You could certainly do it in applescirpt. It'd probably be slightly shorter since looping syntax in Applescript is a bit less cumbersome.

               

              Are you saying you also need to check the length as well? Or is the stroke check sufficient?

              • 4. Re: Want to mass-delete an object
                Bill Planey Level 1

                I think safely anything > 4" can be targeted.

                • 5. Re: Want to mass-delete an object
                  John Hawkinson Level 5

                  There were two yes-or-no questions in there:

                   

                  1) Are you saying you also need to check the length as well?

                   

                  2) Or is the stroke check sufficient?

                  • 6. Re: Want to mass-delete an object
                    Bill Planey Level 1

                    Yes, lengths greater than 4"

                     

                    Stroke weight is important - 2 pts. irrespective of whether it was scaled to 2 points or set at 2 points in normal fashion.

                    • 7. Re: Want to mass-delete an object
                      John Hawkinson Level 5

                      OK, here you go—it appears to be necessary to calculate the length with the Pythagorean theorem (distance formula), since InDesign just returns the corners of the bounding box surrounding the stroke.

                       

                      Also, for convenience, the commented-out lines print out some information about each rule that is operated on -- you might uncomment them and comment out the .remove() if you want to see what it is going to do first.

                       

                      var
                          i,
                          doc = app.activeDocument,
                          rules = doc.graphicLines,
                          bounds, length, x, y, g;
                       
                      for (i=rules.length-1; i>=0; i--) {
                          g = rules[i].geometricBounds;
                          x = g[3]-g[1];
                          y = g[2]-g[0];
                          length = Math.sqrt(x*x+y*y);
                          if (rules[i].strokeWeight >= 2 && length > 4) {
                              // $.writeln("Found rule "+i+" x "+x+" y "+y+" length "+
                              // length+" weight "+rules[i].strokeWeight);
                              rules[i].remove();
                          }
                      }
                      

                       

                      strokeWeight appears to give the apparent stroke weight, regardless of whether it was initially set or if the rule was scaled to get there.

                      • 8. Re: Want to mass-delete an object
                        John Hawkinson Level 5

                        Ah, also: this assumes that you have ruler units of inches. If you have picas or something, change the ruler units to inches before running the script, or change the script to use whatever your ruler units are, i.e. replace >4 with >24 for picas.

                        • 9. Re: Want to mass-delete an object
                          Bill Planey Level 1

                          I'll give it a shot. Does this also deal with rules if they are locked? that was one of my original criteria.

                          • 10. Re: Want to mass-delete an object
                            John Hawkinson Level 5

                            Why don't you test it and find out?

                             

                            Or check the reference sources that I mentioned?

                             

                            We're happy to help you out, but you should make at least a little effort to learn how to do it yourself.

                             

                            You can also test "rules[i].locked" to make sure a rule is locked.