4 Replies Latest reply on Feb 3, 2010 5:53 AM by swedenesume

    Update pageitem twice

    swedenesume

      I have a problem when I loop thru objects.

       

      I start with the deepest item.

       

      but when I make changes to that items parent I will get an error when the loop comes to the parent saying "invalid object for this request".

      If the object has not been change by the child there is no problem, it seems that one item cant be change twice?

       

       

       

      What could this be?

        • 1. Re: Update pageitem twice
          Laubender Adobe Community Professional & MVP

          Please give an code example, just a few lines.

           

          Uwe

          • 2. Re: Update pageitem twice
            swedenesume Level 1

            ok, will put it together


            • 3. Re: Update pageitem twice
              swedenesume Level 1

              I am looping thru all pageitems looking for textframes.

              A text frame can contain anchored objects custom or inline.

              The first function will find all textframes and "fit frame to content". the second function will calculate the position for the parent textframe according to the geometricbounds of the child textframe. This is needed for anchored objects with custom position. but as when the value is changed with the fit frame it will break in the second function


              function adjustSize(doc){               
                  var myItems = doc.allPageItems;
                  for(var i=myItems.length-1;i>=0;i--){
                      if(myItems[i].constructor.name.toString()=="TextFrame"){
                          myItems[i].fit(FitOptions.frameToContent);
                              setGeometricBounds(myItems[i]);           
                      }
                  }   
              }


              function setGeometricBounds(txtObjSet){   
                  for (var i = txtObjSet.paragraphs.length - 1; i >= 0; i--){
                      for (var j = txtObjSet.paragraphs.item(i).textFrames.length - 1; j >= 0; j--){       
                          var child = txtObjSet.paragraphs.item(i).textFrames.item(j);   
                          var txtframebottom = child.geometricBounds[2];   
                          var parentframebottom = txtObjSet.geometricBounds[2];   
                          var parentframetop = txtObjSet.geometricBounds[0];   
                          var parentframeright = txtObjSet.geometricBounds[3];   
                          var parentframeleft = txtObjSet.geometricBounds[1];   
                          var oldheight = parentframebottom - parentframetop;       
                          var newheight = oldheight + txtframebottom - parentframebottom;
                          var heightprocent = 100*(newheight/oldheight);   
                          txtObjSet.geometricBounds = [0, parentframeleft, newheight, parentframeright];
                      }
                  }
              }

              • 4. Re: Update pageitem twice
                swedenesume Level 1


                I can solv this problem if I had another way of getting a textframes coordinates except geometricbounds.

                 

                Is there any other way to get it?