Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Moving all text frames out of containing graphic frames

Contributor ,
Aug 27, 2024 Aug 27, 2024

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?

TOPICS
Scripting
810
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 27, 2024 Aug 27, 2024

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();
    }
}
Translate
Community Expert ,
Aug 27, 2024 Aug 27, 2024

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 27, 2024 Aug 27, 2024

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

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Aug 27, 2024 Aug 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:

Screenshot 2024-08-27 at 21.16.58.png

 

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 27, 2024 Aug 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. 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Aug 27, 2024 Aug 27, 2024

I sent you a link to an extract from the file in a private message – thanks for taking a look!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 27, 2024 Aug 27, 2024

Kind of a mess:

RobertatIDTasker_1-1724788312491.png

 

but doable:

RobertatIDTasker_0-1724788302692.png

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 27, 2024 Aug 27, 2024

Here is a "raw" Text view:

RobertatIDTasker_1-1724788466760.png

 

but after sorting:

RobertatIDTasker_0-1724788448011.png

 

I can pretty much extract it as a one long Story.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 27, 2024 Aug 27, 2024

Extracted sample sent on priv.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 27, 2024 Aug 27, 2024

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();
    }
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Aug 27, 2024 Aug 27, 2024

@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…)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 27, 2024 Aug 27, 2024

@Janus Bahs Jacquet

 

But you still have to link them together manually - or move contents to a new Story.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Aug 27, 2024 Aug 27, 2024

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! 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 27, 2024 Aug 27, 2024
LATEST

You are welcome. 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines