Copy link to clipboard
Copied
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?
Does this work?
var tfs = app.activeDocument.allPageItems;
var i = tfs.length;
while(i--) {
if (tfs[i].constructor.name == "TextFrame" || tfs[i].constructor.name == "TextContainer") {
tfs[i].select();
app.cut();
app.pasteInPlace();
}
}
Copy link to clipboard
Copied
Prob a better way, but you could app.cut() the selection and app.pasteInPlace()
Copy link to clipboard
Copied
Do you have TextFrames Anchored / InLine in Stories, Grouped or Pasted InTo?
Copy link to clipboard
Copied
Honestly, I don’t quite know! They don’t appear to be anchored, since they don’t have the blue square that anchored objects have; the Layers panel doesn’t have any `<group>` elements, so they don't appear to be grouped. I don't imagine they were pasted in, since this is how the document was created when converted from the PDF file (no human was involved in the creation of the document at all).
The Layers panel looks like this:
It’s similar to how, if you open a PDF file in Illustrator, everything is embedded in a dozen levels of transparent rectangles (except at least in the InDesign document, it’s only one level deep).
Copy link to clipboard
Copied
I'm pretty sure someone here will post you a working JS code - I prefer VB - but can you share this document - on priv? Without links.
So I can play with it a bit - can send you back "fixed" version.
Copy link to clipboard
Copied
I sent you a link to an extract from the file in a private message – thanks for taking a look!
Copy link to clipboard
Copied
Kind of a mess:
but doable:
Copy link to clipboard
Copied
Here is a "raw" Text view:
but after sorting:
I can pretty much extract it as a one long Story.
Copy link to clipboard
Copied
Extracted sample sent on priv.
Copy link to clipboard
Copied
Does this work?
var tfs = app.activeDocument.allPageItems;
var i = tfs.length;
while(i--) {
if (tfs[i].constructor.name == "TextFrame" || tfs[i].constructor.name == "TextContainer") {
tfs[i].select();
app.cut();
app.pasteInPlace();
}
}
Copy link to clipboard
Copied
@brian_p_dts Surprisingly, it does! I hadn’t expected that to work (I would have assumed that pasting in place would place it back in the same rectangle). How very simple – thank you!
(I still wonder why simply moving the items refused to work, but oh well…)
Copy link to clipboard
Copied
But you still have to link them together manually - or move contents to a new Story.
Copy link to clipboard
Copied
I do, but that’s an easier task – I already have a functioning script for that.
And thank you to you too for looking through the file and offering to help! 🙂
Copy link to clipboard
Copied
You are welcome.