4 Replies Latest reply on Feb 2, 2010 11:32 PM by swedenesume

    Recursive fitness




      I am trying to rebuild my script to make a recursive fitness of textframes. With a deep nested set of anchored objects (inline and custom position)


      All works well,but when i in my loop tries to first change the current textframe and directly after that change my parent I get an errror msg saying "invalid object for this request".


      I have figured out by stepping with the debugger that when i try to change one textframe twice i breaks (because a textframe can be a parent of many textframes). i think it can have something to do with "allowOverrides" set to false.



      Any help would be very appreciated!

        • 1. Re: Recursive fitness
          ramkumar.vp Level 3

          Hi Swedenesume,

          I think there is no need for the recursive, try the following code to solve your problem.


          var myDoc = app.activeDocument;


          var myItems = myDoc.allPageItems;


          for(var i=myItems.length-1;i>=0;i--)


          The above code will fit the frames for last nested frame to parent frame.


          Ramkumar .P

          • 2. Re: Recursive fitness
            swedenesume Level 1


            Very helpfull tips!!


            I have one more question about this.


            I have anchored objects. And they can be either inline or custom position. If the anchored position is custom the parent textframe cant rezise itself to the new height.


            The only way I know how to solve this is by using the geometricbounds and calculate the height of the parent.


            Is there a better way to rezise a parent textframe to a custom position anchored object then to calculate the coordinates?


            And how could that be implemented to the excellent example you gave?



            Many Many Thanks!

            • 3. Re: Recursive fitness
              ramkumar.vp Level 3

              In my document, it works well for custom anchored object also.

              I am checking & fitting the textframes only.

              Please check the code once again & do the manupulation wherever you need.


              Ramkumar .P

              • 4. Re: Recursive fitness
                swedenesume Level 1



                If the anchored object is custom and you check in the "keep whitin top/bottom bounderies" box. The fit frame to content will make room for the box, but if you have to objects anchored in the same textbox, one of them inline and one of them custom, the inline object has overflow and the other not. And you make fit frame to content on that frame it will lay itself over the other anchored frame.


                So I allways uncheck this box.


                The only way I have found to solv this is by calculating the coordinates of the parent textframe so that it resize itself accoring to the custom child object.


                But then you have to loop to all textframes so that you keep track of witch textframe is a parent and witch textframe is a child and compare there lowest points.


                Is there any other way of doing this in a better way? Or could I implement the "compare" function in your example some how?



                            var txtframebottom = frame.paragraphs.item(i).textFrames.item(j).geometricBounds[2];
                            var parentframebottom = frame.geometricBounds[2];   


                            if(parentframebottom < txtframebottom){
                                var parentframetop = frame.geometricBounds[0];   
                                var parentframeright = frame.geometricBounds[3];   
                                var parentframeleft = frame.geometricBounds[1];   
                                var oldheight = parentframebottom - parentframetop;       
                                var newheight = oldheight + txtframebottom - parentframebottom;
                                var heightprocent = 100*(newheight/oldheight);   
                                frame.geometricBounds = [0, parentframeleft, newheight, parentframeright];