Skip to main content
Inspiring
April 23, 2024
Answered

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

  • April 23, 2024
  • 3 replies
  • 2166 views

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!

This topic has been closed for replies.
Correct answer Marc Autret

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

3 replies

Community Expert
April 24, 2024
Robert at ID-Tasker
Legend
April 24, 2024

@Eugene Tyson

 

But OP doesn't want to release Anchored. 

 

Community Expert
April 24, 2024

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.

 

 

Marc Autret
Marc AutretCorrect answer
Legend
April 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.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

Inspiring
April 24, 2024

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

John D Herzog
Inspiring
April 23, 2024

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

 

Robert at ID-Tasker
Legend
April 23, 2024

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

 

John D Herzog
Inspiring
April 23, 2024

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