Copy link to clipboard
Copied
Here's a Peter Kahrel script to create text frame from selected text:
(function(){
var width = app.selection[0].endHorizontalOffset - app.selection[0].horizontalOffset;
var frame = app.selection[0].textFrames.add();
app.selection[0].move (LocationOptions.AFTER, frame.insertionPoints[0]);
var gb = frame.geometricBounds;
gb[3] = gb[1]+width
frame.geometricBounds = gb;
}());Is it possible to have a script to reverse this situation? So this is the starting point:
and this should be the final one:
Thanks.
Hi Kremisi,
yes of course.
First select the text that contains the anchored text frames, then run the script code:
// Select the text that contain the anchored text frames:
var selectedText = app.selection[0].texts[0];
var anchoredTextFrames = selectedText.textFrames.everyItem().getElements();
var frameLength = anchoredTextFrames.length;
for( var n=frameLength-1; n >= 0; n-- )
{
anchoredTextFrames[n].texts[0].move
( LocationOptions.AFTER , anchoredTextFrames[n].parent.insertionPoints[0] )...
If you are really need to go with object style only, then in first script instead of assigning label apply an object style.
frame.appliedObjectStyle = app.documents[0].objectStyles.item('inlineFrameForCharacter');
And then find object with that object style names and reverse the process:
app.findObjectPreferences = NothingEnum.NOTHING;
app.findObjectPreferences.appliedObjectStyles = 'inlineFrameForCharacter';
var allInlineFrame = app.documents[0].findObject();
for(var i = 0; i < allInlineFrame.l...
Copy link to clipboard
Copied
Hi Kremisi,
yes of course.
First select the text that contains the anchored text frames, then run the script code:
// Select the text that contain the anchored text frames:
var selectedText = app.selection[0].texts[0];
var anchoredTextFrames = selectedText.textFrames.everyItem().getElements();
var frameLength = anchoredTextFrames.length;
for( var n=frameLength-1; n >= 0; n-- )
{
anchoredTextFrames[n].texts[0].move
( LocationOptions.AFTER , anchoredTextFrames[n].parent.insertionPoints[0] );
anchoredTextFrames[n].parent.contents = "";
};
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Uwe,
it runs like a charm! Thank you. Is there a way to select by scripting the text containing the frame, if the frame has an object style?
Copy link to clipboard
Copied
Instead while adding these frame, add a script lable for this reverse process.
////////////////////////////////////////////////////////////////////////////////
(function(){
var width = app.selection[0].endHorizontalOffset - app.selection[0].horizontalOffset;
var frame = app.selection[0].textFrames.add();
frame.label = "inlineFrameForCharacter";
app.selection[0].move (LocationOptions.AFTER, frame.insertionPoints[0]);
var gb = frame.geometricBounds;
gb[3] = gb[1]+width
frame.geometricBounds = gb;
}());
////////////////////////////////////////////////////////////////////////////////
//~ Reverse process
////////////////////////////////////////////////////////////////////////////////
var allStories = app.documents[0].stories;
for(var st = 0; st < allStories.length; st++){
var textFrames = allStories[st].textFrames;
for(var tf = 0; tf < textFrames.length; tf++){
if(textFrames[tf].label == 'inlineFrameForCharacter'){
textFrames[tf].texts[0].move(LocationOptions.AFTER, textFrames[tf].parent.insertionPoints[0]);
textFrames[tf].remove();
textFrames = allStories[st].textFrames;
tf = -1;
}
}
}
////////////////////////////////////////////////////////////////////////////////
Best
Sunil
Copy link to clipboard
Copied
Sunil,
I'm not able to see any results running the script! I'm surely doing something wrong... Thanks anyway!
Copy link to clipboard
Copied
I think you are running entire script altogether.
My post has two script.
1. Peter kahrel's script (which you already have), just added lable to the frames which is getting added to make it inline.
2. Reverse process: which then for reversing whole thing altogether, finding all stories and textframes inside the stories because all are anchored, then checking for the label which we added in first process. If found then move it's text out side and remove that frame.
You can apply any choosen object style instead of label on that frame while adding those inline frame.
And find them using find object and reverse that process.
I choose label to avoid any kind of object style because I don't want to put effort on creating object style instead assigning a unique label doesn't change anything.
P.S. Do not run entire code altogether, they are two different codes.
Best
Sunil
Copy link to clipboard
Copied
Sunil,
I've got the point, if I run your script in a fresh doc, I mean, select the text > perform the 1st script and > perform the second script everything is ok. The problem is that the script runs on text frames created by it, it does not run on text frames with a given object style I can find in a document.
So this line:
if(textFrames[tf].label == 'inlineFrameForCharacter'){returns a textFrame named 'inlineFrameForCharacter', right? Your script does not recognize the text frames with a (previous) given object style. Maybe the problem is that I do not know what is the difference between label and objectStyle... Thank you again!
Copy link to clipboard
Copied
Hi Kremisi,
wrong. Name is a different property.
If an object would be named you would be able to see the name in the Layers Panel.
Whereas the label holds the text that you can see with the Scripts Label Panel in InDesign if you e.g. select an object on the page and go to: Window > Utilities > Script Label
https://helpx.adobe.com/indesign/using/scripting.html
Regards,
Uwe Laubender
( ACP )
// EDITED
Copy link to clipboard
Copied
If you are really need to go with object style only, then in first script instead of assigning label apply an object style.
frame.appliedObjectStyle = app.documents[0].objectStyles.item('inlineFrameForCharacter');
And then find object with that object style names and reverse the process:
app.findObjectPreferences = NothingEnum.NOTHING;
app.findObjectPreferences.appliedObjectStyles = 'inlineFrameForCharacter';
var allInlineFrame = app.documents[0].findObject();
for(var i = 0; i < allInlineFrame.length; i){
allInlineFrame[i].texts[0].move(LocationOptions.AFTER, allInlineFrame[i].parent.insertionPoints[0]);
allInlineFrame[i].remove();
app.documents[0].recompose();
allInlineFrame = app.documents[0].findObject();
}
Best
Sunil
Copy link to clipboard
Copied
Thank you Sunil,
that's the perfect solution! Best, K.
Copy link to clipboard
Copied
Kremisi said:
Is there a way to select by scripting the text containing the frame, if the frame has an object style?
Hi Kremisi,
all doable by scripting. Even giving the script a user interface where you can choose the object style etc.pp.
But, I think, all this is out of the scope of the InDesign User Forum.
You could hire a scripter.
Or you could learn how to script and come back with some code, if you are in trouble.
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Yes, you're right! Anyway thanks again, your answer was very precious for me! K.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now