Hi @LoveYou阿逗逼6666, there are two problems
(a) the convertAreaObjectToPointObject and convertPointObjectToAreaObject methods destroy the text frame and create a new (converted) one, so your reference "text" will be invalid after the first convert, and
(b) the convertAreaObjectToPointObject and convertPointObjectToAreaObject methods should, according to the docs (and common sense!) return a reference to the new converted text frame—but they don't; they return null.
A workaround is something like the following:
function convert(name, contentNew) {
var textFrameList = app.activeDocument.textFrames;
for (var i = 0; i < textFrameList.length; i++) {
var text = textFrameList[i];
var group = text.parent.groupItems.add();
group.move(text, ElementPlacement.PLACEBEFORE);
text.move(group, ElementPlacement.PLACEATEND);
text.convertAreaObjectToPointObject();
text = group.pageItems[0];
text.convertPointObjectToAreaObject();
text = group.pageItems[0];
text.move(group, ElementPlacement.PLACEBEFORE);
group.remove();
}
};
I put the text frame into a group, so that after it is converted, and the old item is gone, it is simple to get a reference to the new item.
- Mark
Edit 2023-11-22: removed the first example because it was bad.