Skip to main content
Janus Bahs Jacquet
Inspiring
August 27, 2024
Answered

Moving all text frames out of containing graphic frames

  • August 27, 2024
  • 2 replies
  • 1107 views

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?

This topic has been closed for replies.
Correct answer brian_p_dts

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();
    }
}

2 replies

Robert at ID-Tasker
Brainiac
August 27, 2024

Do you have TextFrames Anchored / InLine in Stories, Grouped or Pasted InTo? 

 

Janus Bahs Jacquet
Inspiring
August 27, 2024

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).

Robert at ID-Tasker
Brainiac
August 27, 2024

@Janus Bahs Jacquet

 

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. 

 

brian_p_dts
Adobe Expert
August 27, 2024

Prob a better way, but you could app.cut() the selection and app.pasteInPlace()