Moving all text frames out of containing graphic frames
I have a terrible mess of an InDesign document created originally from a PDF file, whose structure reflects the PDF file rather too closely. Among other things, this means that most paragraphs are unthreaded, separate text frames/stories – and even worse, all text frames are embedded inside graphic frames that cover the entire page.
This is not tenable, naturally, so as a first step, I would like to get all the text frames moved out of these graphic frames (so they’re direct children of the layer), but since the document is about 300 pages, and there’s probably about four text frames per page on average, I’d prefer to script it.
But… how? In the UI, it’s a simple matter of opening the Layers panel and dragging the frame on to the layer, but in a script, I can’t figure out how to do it. If I just select an embedded text frame and try to move it to the base layer by doing this:
doc.selection[0].move(doc.layers.firstItem());
– then I get an error message saying, “Cannot move subselected items to a new layer. Ungroup the selection, or select entire group or graphic frame”, which is… less than helpful, since the selection isn’t grouped and moving the entire graphic frame is exactly what I want to avoid.
In the UI, I get the same error message if I create a second layer and try to move the text frame on to that layer, but not if I stay within the same layer; but in ExtendScript, I get the error message even when there is only one layer in the document.
How on earth does one go about moving a text frame out of its parent container and associating it directly with a layer?
