Copy link to clipboard
Copied
Hi,
I've a document with some basic frames in them. I need to convert them into text frames.
I've tried PageItem.contentType = ContentType.TEXT_TYPE and while it changes the content type the page item still does not have insertionPoints.
If I close the document directly after changing the content type then re open, the insertionPoints are accessable.
What else do i need to do when converting the frame type?
many thanks
Richard
The problem is caused by the peculiarities of InDesign's loose typing.
You need to reevaluate the type like so:
myPageItem.contentType = ContentType.TEXT_TYPE;
myPageItem = myPageItem.getElements()[0];
Copy link to clipboard
Copied
Hi Richard,
Try this
app.activeDocument.allPageItems[0].contentType = ContentType.TEXT_TYPE app.select(app.activeDocument.allPageItems[0].insertionPoints[0])
Regards,
Shonky
Copy link to clipboard
Copied
You are correct -- there seems to be a minor lag between assigning the Content type and ID actually recognizing it as such.
I tried a few random things that did not work -- forcing "recompose" and such -- until (finally!) trying this: an explicit Select of the new object does force ID to re-evaluate the type.
r = app.activeDocument.rectangles.add();
try {
x = app.selection[0].insertionPoints.length;
alert ("Found "+x+" insertion points");
} catch (_)
{
alert ("No insertion points here");
}
r.contentType = ContentType.TEXT_TYPE;
r.select();
try {
x = app.selection[0].insertionPoints.length;
alert ("Found "+x+" insertion points");
} catch (_)
{
alert ("No insertion points here");
}
Copy link to clipboard
Copied
The problem is caused by the peculiarities of InDesign's loose typing.
You need to reevaluate the type like so:
myPageItem.contentType = ContentType.TEXT_TYPE;
myPageItem = myPageItem.getElements()[0];
Copy link to clipboard
Copied
thank you all for being so helpful,
yep in the end I set the pageitem variable to the pageitem in the document again and it fixed the problem, presume this is a Javascript bug and not Indesign itself? I guess Indesign is doing some other process behind the scenes when you change the content type and Javascript doesn't realise the object has changed. lol
thanks again.
Richard
Copy link to clipboard
Copied
I don't think it's really a bug.
InDesign keeps interactions between the scripting layer and the C++ layer to a minimum to ensure maximum performance.
You really don't want InDesign to reevaluate the object's type each time you change a property...
You are changing the object's class "behind the scripting engine's back", so the scripting layer is not aware of new properties.
Harbs
Find more inspiration, events, and resources on the new Adobe Community
Explore Now