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!
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
...
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
You can paste images and other text frames into a text frame so I don't know what you mean by that.
Copy link to clipboard
Copied
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.
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;}}}
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" ...
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Thank you very much @Marc Autret ! This definitely does the trick 🙂 It's simple but effective.
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
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
Copy link to clipboard
Copied
[...]
In my opinion a pasted graphic inside a text frame is anchored.
[...]
By @Eugene Tyson
@Marc Autret already provided solution.
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.
Copy link to clipboard
Copied