Create text frame from selected text?

Learn / Forums / InDesign Add-ons (Scripts, Scripting, and Plug-ins) / Create text frame from selected text?

Viewing 6 reply threads
  • Author
    Posts
    • #62915
      fred.lm
      Member

      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

    • #62933
      David Blatner
      Keymaster

      Interesting problem. I don't know of any script like that. But perhaps these scripts or tips will help?

      https://creativepro.com/spl…..frames.php

    • #62953
      fred.lm
      Member

      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)

    • #64170
      czucker
      Participant

      I've been looking for just such a script. Did anyone ever figure this out?

      Thanks,

      Chris

    • #64171

      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”);

      • #91202
        Sumit Kumar
        Member

        Dear Jong,

        Can script also fit first frame and remove hard return from first frame?

        Sumit

    • #64200

      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.

    • #95793

      What an another brilliant script from Jongware. This is very effective guys. More power to you.

Viewing 6 reply threads
  • You must be logged in to reply to this topic.
>