• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Update pageitem twice

New Here ,
Feb 03, 2010 Feb 03, 2010

Copy link to clipboard

Copied

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?

TOPICS
Scripting

Views

406

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 03, 2010 Feb 03, 2010

Copy link to clipboard

Copied

Please give an code example, just a few lines.

Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 03, 2010 Feb 03, 2010

Copy link to clipboard

Copied

ok, will put it together


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 03, 2010 Feb 03, 2010

Copy link to clipboard

Copied

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.constructor.name.toString()=="TextFrame"){
            myItems.fit(FitOptions.frameToContent);
                setGeometricBounds(myItems);           
        }
    }   
}


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];
        }
    }
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 03, 2010 Feb 03, 2010

Copy link to clipboard

Copied

LATEST


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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines