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

How to find Nested text Frames / text frames inside regular frames

Community Beginner ,
Apr 23, 2024 Apr 23, 2024

Copy link to clipboard

Copied

Hi all! 🙂 I've been cracking my head over this and couldn't find any solution neither related topic here.

I've in my hands a file from a client that (I don't undestand why) have text frames "pasted into" regular frames... I need to find all instances and set them free. 

 

Does anyone have a script to do this? I've tried with chatGPT but with no positive result.

 

Thanks all in advance!

TOPICS
Scripting

Views

247

Translate

Translate

Report

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

Guide , Apr 23, 2024 Apr 23, 2024

Hi @Mauro Acciarri 

 

I don't know of any clean method to remove a nested PageItem from its container. The code below is just a stopgap solution based on Select/Cut/PasteInPlace.

 

(function(  doc,a,t,z)
{
   doc = app.properties.activeDocument;
   if( !doc ) return;
   
   const REPL = +SelectionOptions.REPLACE_WITH;

   app.scriptPreferences.enableRedraw = false;
   // ---
   for( z=0, a=doc.allPageItems ; t=a.pop() ; )
   {
      if( 'TextFrame' != t.constructor.name ) continue;
      if( !t.pare
...

Votes

Translate

Translate
Contributor ,
Apr 23, 2024 Apr 23, 2024

Copy link to clipboard

Copied

So the textFrame object has the property of textFrames. I would think you would need to loop through the textFrames of the document checking the link of textFrames for each. If it is greater than 0, take the inner textFrame and move it to the document as the parent.

This is quick and dirty way to do it. Hopefully it will get you going in the right direction.

 

var doc = app.activeDocument;
var tFrames = doc.textFrames;
for(x=tFrames.length-1;x>=0;x--){
if(tFrames[x].textFrames.length > 0){
var inTFrames = tFrames[x].textFrames;
for(y=inTFrames.length-1;y>=0;y--){
var dProps = inTFrames[y].properties;
inTFrames[y].remove();
var newFrame = doc.textFrames.add();
newFrame.properties = dProps;
}
}
}

 

Votes

Translate

Translate

Report

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 ,
Apr 23, 2024 Apr 23, 2024

Copy link to clipboard

Copied

@John D Herzog

 

All graphic objects have TextFrame Collection.

 

In case of a TextFrame - it can't have anything "pasted into" - but its TextFrames collection returns Anchored / InLine TextFrames.

 

Unfortunately, your code won't do what @Mauro Acciarri is looking for.

 

Votes

Translate

Translate

Report

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 ,
Apr 23, 2024 Apr 23, 2024

Copy link to clipboard

Copied

@Robert at ID-Tasker 

You can paste images and other text frames into a text frame so I don't know what you mean by that.

 

Votes

Translate

Translate

Report

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 ,
Apr 23, 2024 Apr 23, 2024

Copy link to clipboard

Copied

@John D Herzog 

 

Paste and Paste Into are two different things.

 

If you select TextFrame's contents - part of the text or simply place a cursor inside the text - and execute Paste - you'll end up with Anchored or InLine graphic.

 

If you simply select TextFrame and do Paste - TextFrame will no longer be selected and new object - contents of the Clipboard - will be placed on the page and selected.

 

If you select TextFrame and do Paste Into - your TextFrame will no longer be a TextFrame - it will be converted into a Rectangle.

 

So your code is looping through Anchored / InLine TextFrames of the TextFrames - not TextFrames that were Pasted Into into other graphic objects.

 

 

There is also a flaw with your code - as you are looping from 1 to last - you might skip some Anchored / Inline TextFrames - you should loop backward.

Or better yet - loop through Stories - but still backward throught myStory.textFrames collection.

 

Votes

Translate

Translate

Report

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 ,
Apr 24, 2024 Apr 24, 2024

Copy link to clipboard

Copied

quote

So the textFrame object has the property of textFrames. I would think you would need to loop through the textFrames of the document checking the link of textFrames for each. If it is greater than 0, take the inner textFrame and move it to the document as the parent.

This is quick and dirty way to do it. Hopefully it will get you going in the right direction.

 

var doc = app.activeDocument;
var tFrames = doc.textFrames;
for(x=tFrames.length-1;x>=0;x--){
if(tFrames[x].textFrames.length > 0){
var inTFrames = tFrames[x].textFrames;
for(y=inTFrames.length-1;y>=0;y--){
var dProps = inTFrames[y].properties;
inTFrames[y].remove();
var newFrame = doc.textFrames.add();
newFrame.properties = dProps;
}
}
}

By @John D Herzog

 

If you switch your code to process pageItems of the Document - but not allPageItems - and then process allPageItems collections of those pageItems - your code should work great.

 

Unless there is a deeper "nesting" ... 

 

Votes

Translate

Translate

Report

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 Beginner ,
Apr 24, 2024 Apr 24, 2024

Copy link to clipboard

Copied

LATEST

Thank you for your help @John D Herzog ! As Robert explained for me, my problem are Text Frames pasted into a regular rectangle (an abomination). But your script will be usefull anyway as in other projects I have to deal with textFrames anchored in other textFrames.

Votes

Translate

Translate

Report

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
Guide ,
Apr 23, 2024 Apr 23, 2024

Copy link to clipboard

Copied

Hi @Mauro Acciarri 

 

I don't know of any clean method to remove a nested PageItem from its container. The code below is just a stopgap solution based on Select/Cut/PasteInPlace.

 

(function(  doc,a,t,z)
{
   doc = app.properties.activeDocument;
   if( !doc ) return;
   
   const REPL = +SelectionOptions.REPLACE_WITH;

   app.scriptPreferences.enableRedraw = false;
   // ---
   for( z=0, a=doc.allPageItems ; t=a.pop() ; )
   {
      if( 'TextFrame' != t.constructor.name ) continue;
      if( !t.parent.hasOwnProperty('paths') ) continue;
      
      t.select(REPL); // May fail due to locked items, etc
      app.selection.length && ( app.cut(), app.pasteInPlace(), ++z );
   }
   // ---
   app.scriptPreferences.enableRedraw = true;

   alert( z + ' text frames have been removed from hierarchy.')
})();

 

We obviously need a better approach… Maybe others will find it.

 

Best,

Marc

Votes

Translate

Translate

Report

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 Beginner ,
Apr 24, 2024 Apr 24, 2024

Copy link to clipboard

Copied

Thank you very much @Marc Autret ! This definitely does the trick 🙂 It's simple but effective.

Votes

Translate

Translate

Report

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 ,
Apr 23, 2024 Apr 23, 2024

Copy link to clipboard

Copied

There was a similar issue here - https://creativepro.com/releasing-inlines/#:~:text=You%20can%20select%20an%20anchored,unhinged%20fro...

 

There's a script to download and try

 

Votes

Translate

Translate

Report

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 ,
Apr 24, 2024 Apr 24, 2024

Copy link to clipboard

Copied

@Eugene Tyson

 

But OP doesn't want to release Anchored. 

 

Votes

Translate

Translate

Report

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 ,
Apr 24, 2024 Apr 24, 2024

Copy link to clipboard

Copied

They said to set them free - what does that mean? 
I've no idea.

I found a similar article and shared it - if it's not any use here then fine - if it's useful to someone else in the future then fine.

 

 

Votes

Translate

Translate

Report

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 ,
Apr 24, 2024 Apr 24, 2024

Copy link to clipboard

Copied

@Eugene Tyson

 

OP have objects with TextFrames Pasted Into them - not Anchored / InLine.

 

Yes, your code can be helpful to others when they have Objects Anchored / InLine in the text - unfortunately not in this case. 

 

Votes

Translate

Translate

Report

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 ,
Apr 24, 2024 Apr 24, 2024

Copy link to clipboard

Copied

I don't know exactly the situation being faced on every occasion.

 

I suggest we stick to the op request and if it's helpful then or not I don't know.

 

In my opinion a pasted graphic inside a text frame is anchored.

 

I didn't have the InDesign file downloaded replying on my phone.

 

Perhaps help the op further if needed 

Votes

Translate

Translate

Report

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 ,
Apr 24, 2024 Apr 24, 2024

Copy link to clipboard

Copied

quote

[...] 

In my opinion a pasted graphic inside a text frame is anchored.

[...] 


By @Eugene Tyson

 

https://community.adobe.com/t5/indesign-discussions/how-to-find-nested-text-frames-text-frames-insid...

 

 

@Marc Autret already provided solution.

 

Votes

Translate

Translate

Report

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 ,
Apr 24, 2024 Apr 24, 2024

Copy link to clipboard

Copied

If it's the solution why not mark it as correct answer? Not sure why you're focussed on my replies.

 

If a reply isn't helpful the op can move on to another reply 

 

Not sure what the issue is. 

Votes

Translate

Translate

Report

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 ,
Apr 24, 2024 Apr 24, 2024

Copy link to clipboard

Copied

@Eugene Tyson

 

It's not my thread so I don't think I can mark as correct.

 

No issues. Sorry. 

 

Votes

Translate

Translate

Report

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