6 Replies Latest reply on Dec 17, 2012 4:09 AM by Harbs.

    Delete Rectangle Measurement box

    BEGINNER_X Level 3

      Hi All,

       

      I am a beginner. Learning through "InDesignCS3_ScriptingGuide_JS" and forum only.

       

      REQUIREMENT:

       

      I want to delete all rectangle measurement box in my active document. I have script got from forum only. But if any measurement box is locked, that script not run well.

       

      At the same time if the compositor applying any color, text wrap etc... to the measurement box,  the script not want to delete that box.

       

       

      TRYING SCRIPT:

       

      var myDocument = app.activeDocument;

       

           for (var i = myDocument.rectangles.length-1; i >= 0; i--) {

       

                if (myDocument.rectangles[i].allGraphics == '' ) {

       

                     myDocument.rectangles[i].remove();

                }

       

           }

       

       

      Can anyone give solution for me if you willing.

       

       

       

      Thanks in advance

       

      BEGINNER

        • 1. Re: Delete Rectangle Measurement box
          BEGINNER_X Level 3

          Hi ALL,

           

          SORRY FOR WRONGLY POSTED.....

           

          Any solution or update for above mentioned question?

           

          Thanks

          BEGINNER

          • 2. Re: Delete Rectangle Measurement box
            Marc Autret Level 4

            Hi BEGINNER,

             

            Try this:

             

            // ==============================================
            // Unlock and try to remove any direct rectangle
            // that does not contain graphic obj
            // ==============================================
            
            var recs = app.activeDocument.rectangles.everyItem().getElements(),
                i = recs.length,
                r;
            
            while( i-- )
                {
                r = recs[i];
                if( r.graphics.length ) continue;
                r.locked && (r.locked=false);
            
                // try..catch block in case removing still
                // fails for any reason
                // ---
                try{ r.remove(); }catch(_){}
                }
            

             

            @+

            Marc

            • 3. Re: Delete Rectangle Measurement box
              TᴀW Adobe Community Professional & MVP

              @Marc,

               

              I've noticed you often use the AND operator to serve as an if statement.

              It's certainly a cool way of doing things, and is probably quicker (?),

              but is it safe to rely on the Javascript interpreter in this way? What

              if one day Adobe updates things and gets its interpreter to start

              evaluating such lines from right to left (or simultaneously)? Or is that

              inconceivable?

               

              Ariel

              • 4. Re: Delete Rectangle Measurement box
                Marc Autret Level 4

                Arïel wrote:

                 

                What if one day Adobe updates things and gets its interpreter to start

                evaluating such lines from right to left (or simultaneously)? Or is that

                inconceivable?

                 

                ExtendScript/JS is an implementation of ECMA-262 (+E4X) standard. As long as it is true, the way logical operators are evaluated must follow the specification: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf?#page=95

                 

                I think we can be confident on such very fondamental point, although I agree we must remain vigilant on more peripheral rules—ES is not fully E4X-compliant, for example—not to mention RegExp bugs, etc.

                 

                @+

                Marc

                • 5. Re: Delete Rectangle Measurement box
                  sundar_r Level 1

                  Hi Marc, I'm also a beginner.

                   

                  The Beginner X also mentioned the below option too. I am also trying the same, but no results so far.

                   

                  "At the same time if the compositor applying any color, text wrap etc... to the measurement box,  the script not want to delete that box."

                   

                  I had tried this below codes, but not included textwraps and graphics. Correct me if I'm wrong.

                   

                  var mydoc=app.activeDocument;

                  var objects=mydoc.rectangles.everyItem().getElements();

                  var graphicsList = mydoc.allGraphics;

                   

                   

                  for (i=0;i<objects.length;i++){

                      object=objects[i];

                     

                      if (object.fillColor.hasOwnProperty&&object.strokeColor.hasOwnProperty("colorValue")){

                          break

                          }

                      else {object.remove()}

                      }

                   

                  Thanks

                  • 6. Re: Delete Rectangle Measurement box
                    Harbs. Level 6

                    Arïel wrote:

                     

                    but is it safe to rely on the Javascript interpreter in this way? What

                    if one day Adobe updates things and gets its interpreter to start

                    evaluating such lines from right to left (or simultaneously)? Or is that

                    inconceivable?

                    It's inconceivable. This is an integral part of the ECMAScript spec as well as the spec for many other languages (such as C++). Changing something as basic as that would break an incredible amount of code.