Copy link to clipboard
Copied
tagframe = myPage.textFrames.add();
tagframe.geometricBounds = myPage.pageItems.item(i).geometricBounds;
I don't actually need the new text frames to match up exactly on top of the reference object, but it does need to be relatively clear from their position which object they were 'based on'.
Thanks,
Josh
.pageItems wouldn’t get items inside of groups so you might try using .allPageitems and skip the group objects in the loop. Something like this:
var doc = app.activeDocument
var p= doc.allPageItems;
for (var i = 0; i < p.length; i++){
if (p[i].constructor.name != "Group") {
var gb = p[i].geometricBounds
doc.textFrames.add({geometricBounds:gb, contents:"YO", fillColor:"None"});
}
};
Copy link to clipboard
Copied
geometricBounds works the same for Groups as it does for TextFrames, so the problem is elsewhere.
What type of PageItem is your pageItems.item(i) exactly?
Copy link to clipboard
Copied
So pageItems.item(i) is just running through all pageItems on a loop. This is the issue: it runs through all the image frames, polygons, lines etc on the page OK, but for some reason doesn't apply the geometricBounds correctly for text frames or groups.
Copy link to clipboard
Copied
.pageItems wouldn’t get items inside of groups so you might try using .allPageitems and skip the group objects in the loop. Something like this:
var doc = app.activeDocument
var p= doc.allPageItems;
for (var i = 0; i < p.length; i++){
if (p[i].constructor.name != "Group") {
var gb = p[i].geometricBounds
doc.textFrames.add({geometricBounds:gb, contents:"YO", fillColor:"None"});
}
};
Copy link to clipboard
Copied
That's all useful to know, thank you – but should something running through pageItems still pick up any groups (and their geometricBounds), even if not the individual grouped items?
I guess my question is essentially: why is "myPage.pageItems.item(i).geometricBounds" behaving differently when the item in question happens to be a text frame or a group? The script is behaving as if in those cases, it returns 0 (rather than actually failing).
Copy link to clipboard
Copied
.pagetems returns a pageItem class, so you should be able to get the bounds even when the page item is a group. So here there are only 2 page items—the group is selected so I can see the bounds:
allPageItems returns 5 items including the group