Create text frame from selected text?
Learn / Forums / InDesign Add-ons (Scripts, Scripting, and Plug-ins) / Create text frame from selected text?
- This topic has 7 replies, 6 voices, and was last updated 6 years, 9 months ago by Michael Angelo.
-
AuthorPosts
-
-
August 16, 2012 at 10:10 am #62915fred.lmMember
Hi Guys!
First of all, thank you very much for being involved in such a great community! I'm not an InDesign expert at all, and I found answers to my questions many MANY times in this forum.
However, I recently bumped into an issue that nobody seems to care about, and I hope at least one of you will be able to help me. It's probably really simple.Here is the question: is there a script to create a new text frame from a selection?
I voluntereed to create an InDesign template to more or less automatically format scientific reports (~ 10times per year, 150pages each), and this is the last thing I think I can improve. Basically, There are many in-text tables that are imported with the rest of the word document, and I'd like to create a frame for each of these tables so that I can put them wherever I want. So far, I have to select each table, cut it, create a new frame, paste it and resize the frame. With over 100 tables per report sometimes, that can be very quickly annoying…
Thank would be awesome if you could help me with that!
Cheers
Fred
-
August 20, 2012 at 6:39 am #62933David BlatnerKeymaster
Interesting problem. I don't know of any script like that. But perhaps these scripts or tips will help?
-
August 21, 2012 at 9:39 am #62953fred.lmMember
Hi David,
Thanks for the link, but unfortunately, this is not what I'm looking for… a just want to select some text and then create a new frame (using a script) that contains this selection…
Cheers ;o)
-
February 15, 2013 at 2:21 pm #64170czuckerParticipant
I've been looking for just such a script. Did anyone ever figure this out?
Thanks,
Chris
-
February 15, 2013 at 4:05 pm #64171Theunis De JongMember
Chris, I think I overlooked this question last year! It isn't very hard to script — or, maybe, the basic functionality is not. I ran into some problems when trying it on a line containing a figure, because in that case the 'baseline' — the bottom of the 'figure' line — is not what you expect. Anyway, the script automatically selects the newly created frame, so you can move it right away to a better position.
By way of bonus: the first line defines the name of the object style to be applied to this new frame. If you don't want to use this, delete the first line and the one that applies it (the 2nd line from the bottom). If your selected text ends in a hard return, it automatically deletes this, as usually you don't want that inside a text frame.
//DESCRIPTION:Create a frame from a text selection
// A Jongware script 19-Feb-2013
app.doScript(function() {
objectStyle = “Figure”;
if (app.selection.length == 1 && app.selection[0].hasOwnProperty(“baseline”) && app.selection[0].length > 0)
{
frame = app.selection[0].parentTextFrames[0].duplicate();
frame.texts[0].remove();
frame.move (undefined, [0, app.selection[0].characters[0].baseline- app.selection[0].parentTextFrames[0].characters[0].baseline]);
app.selection[0].move(LocationOptions.AT_BEGINNING, frame.texts[0]);
while (frame.texts[0].characters[-1].contents == 'r')
frame.texts[0].characters[-1].remove();
frame.fit (FitOptions.FRAME_TO_CONTENT);
frame.applyObjectStyle(app.activeDocument.objectStyles.item(objectStyle));
frame.select();
}
}, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, “Frame from Selection”);-
January 12, 2017 at 8:11 am #91202Sumit KumarMember
Dear Jong,
Can script also fit first frame and remove hard return from first frame?
Sumit
-
-
February 19, 2013 at 3:18 am #64200Theunis De JongMember
Oops. Just now I needed this script, so I copied and saved it and .. it didn't run! A couple of errors seem to have snuck in into the web-translation. Fixed right away, the above script is safe to be copied and pasted into the Extendscript Tool Editor.
-
July 1, 2017 at 2:53 am #95793Michael AngeloMember
What an another brilliant script from Jongware. This is very effective guys. More power to you.
-
-
AuthorPosts
- You must be logged in to reply to this topic.