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?
Copy link to clipboard
Copied
Please give an code example, just a few lines.
Uwe
Copy link to clipboard
Copied
ok, will put it together
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];
}
}
}
Copy link to clipboard
Copied
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?