2 Replies Latest reply on Jun 15, 2012 9:55 AM by Vamitul

    Two scripts for easier threading/unthreading text

    Vamitul Level 4

      so.. i'we got this project that consists mostly of fixing tons of threaded text, eventualy for exporting it to rtf.

      i'we wrote this two scripts the first one for beaking the thread at the beginning of the current frame

      wich is working excelent.


      #target "InDesign"
      #targetengine "session"
      //var contextMenu = app.menus.itemByName("$ID/RtMouseText");
      //contextMenu.menuItems.add(breakframe(),LocationOptions.AFTER,"Break Frame");
       var myBreakFameScriptAction=app.scriptMenuActions.add("Break Frame");
       var myEventListener=myBreakFameScriptAction.eventListeners.add("onInvoke", function () 
      myText=myChar.parentStory.characters.itemByRange (myChar.index, app.selection[0].parentStory.characters[-1].index);
      catch (myerror){alert("Invalid Frame. Mabye tabel?");}
      },undefined,undefined,UndoModes.entireScript,'Break Frame');
      try {
              var myBreakScriptMenuItem=app.menus.item("$ID/RtMouseText").menuItems.item(
      "Break Frame");
      catch (myError){
      var myBreakScriptMenuItem = app.menus.item("$ID/RtMouseText").menuItems.add(myBreakFameScriptAction);

      the second one is for threading text in the selected textframes, like the "linkster" tool in Quark 9.2 but it works a wierd, instead of linking them in the selected order it links them in .. don't really know what order (I understand that it should work in CS6, but i need it in CS5). Can someone give me a idee how can i fix it?



      function linkster(mySelection){
      try {
      if ((mySelection.length>0)& (testConstr (mySelection)))
          for (var i=0; i<mySelection.length; i++){
                  if (i>0){
                         if (mySelection[i].previousTextFrame==null)
      }catch (e) {alert (e.message + "\r(line " + e.line + ")\rInvalid Selection")};
      function testConstr(mySelect){
          for (var i=0; i<mySelect.length; i++){
              if (mySelect[i].constructor.name!="TextFrame") return false;
          return true;
        • 1. Re: Two scripts for easier threading/unthreading text
          Laubender Adobe Community Professional & MVP

          @Vamitul – it's all about the index order of your selection. That changed with InDesign CS5.5. In InDesign CS5.5 the index of selected objects is the order you made the selection. That is also true with InDesign CS6.


          I know it's not very helpful to you since you rely on InDesign CS5.


          That means you need a method to "tag" the right order of the text frames before threading them. A little bit cumbersome, though…


          One method: would be to insert a unique label with the "insertLabel()" function, a string that represents a counting number. Every time you insert such a label to a single selected text frame you could insert a label with the actual number to the actual document and use that value for inserting the next label to the next single selection.


          After that you could loop through the overall selection and thread the text frames together processing their labeled strings with the extractLabel() method.


          Or: you use the geometric approach with your selected objects, going through their geometricBounds and looking for an geometric order you want to thread the frames.


          Or: you're using Rorohikos' APID (Active Page Item Developer) with scripting. You should find the wanted functionality there:


          With APID It should be possible to establish an "observer" that checks in what order you have selected your objects…
          But ask Rorohiko first before buying ;-)



          1 person found this helpful
          • 2. Re: Two scripts for easier threading/unthreading text
            Vamitul Level 4

            Thank you.

            I'we taken a look at Rorohikos' APID, but i'm quite sure that my firm won't pay for it.

            However the tagging ideea is actualy even better (for what i need to do). i have to define the order in witch the text needs to be exported (and maby even add a few bells with tagging for headings etc).

            about the second script i was thinking if it was possible to create a startup script with a event listener for selection changes. The problem is... i'we never worked with event listeners before.