4 Replies Latest reply on Feb 18, 2016 7:56 AM by ypsillon

    How to use "fit" method to only RECTANGLES containing any type of graphics?

    ypsillon Level 1

      Hi,

      I want use : fit(FitOptions.FRAME_TO_CONTENT) to only rectangles having placed an image of any type, not to touching other rectangles

       

      I' don't know how to do it.

       

      Many thanks for suggestions :-)

       

      Marcin

        • 1. Re: How to use "fit" method to only RECTANGLES containing any type of graphics?
          milligramme Level 3

          Hi,

          try this snippet.

           

           

          var doc   = app.documents[0];
          var rects = doc.rectangles;
          
          
          for (var i=0, len=rects.length; i < len ; i++) {
            var rect = rects[i];
            var include_img = rect.graphics.length > 0 ||
                              rect.images.length > 0;
            if (include_img) {
              $.writeln(rect.id);
              rect.fit(FitOptions.FRAME_TO_CONTENT);
            }
          };
          

           

          if you want to specify graphic type, use rect.epss.length instead of rect.graphics.length for example.

           

          thankyou

          mg

          • 2. Re: How to use "fit" method to only RECTANGLES containing any type of graphics?
            Laubender Adobe Community Professional & MVP

            Hi Marcin,

            if you also want to catch graphics, that are nested (in groups, anchored graphics, graphics in cells, pasted inside graphics) we could also use the allGraphics array of the document. Then the question is: would you like to dismiss graphics on locked layers, graphics that are locked, graphics that are placed on the pasteboard * ?

             

            // Fit graphics, if parent is Rectangle object
            // Dismiss locked rectangles and locked layers
            
            var doc = app.documents[0];
            var allGraphicsArray = doc.allGraphics;
            
            
            for(var n=0;n<allGraphicsArray.length;n++)
            {
            
                var container = allGraphicsArray[n].parent;
               
                if(
                    // 1. Container is a Rectangle object:
                    container.constructor.name == "Rectangle"
                    // 2. It's layer is not locked:
                    && container.itemLayer.locked === false
                    // 3. Container is not locked:
                    && container.locked === false
                    )
                {
                  allGraphicsArray[n].parent.fit(FitOptions.FRAME_TO_CONTENT);
                };
            
            };
            

             

            * If only placed graphics of the pages should be affected, we could loop through the pages.

             

            What could go wrong?
            The container of the graphic is inside overset text or is part of a table cell's overset.

             

            Uwe

            • 3. Re: How to use "fit" method to only RECTANGLES containing any type of graphics?
              ypsillon Level 1

              many thanks milligrame

              it looks like needed !!

              I will try tommorow in practice

               

              thank you Laubender

              tommorow I will try it

              • 4. Re: How to use "fit" method to only RECTANGLES containing any type of graphics?
                ypsillon Level 1

                many, many many thanks Launder :-)

                your snippet looks and work brilliant !!!!

                it gave me also a "new" look of "what" I should search first :-)

                thanks again

                 

                regards Marcin