10 Replies Latest reply on Oct 10, 2011 6:58 AM by Brian.T.Tanner

    [JS][CS35.5]Place a previously created item/textframe/group onto a page/into a textframe anchored

    Brian.T.Tanner

      Hi all. I'm an experienced programmer but very new to indesign scriping.  I've been working through a book and some tutorials and it's coming along pretty well.  I'm also no Javascript pro.

       

      My project is to parse some inDesign files that I have made as "templates" and fill in placeholder text I have created with data from a file.  The data can be single words or phrases or long sequences of styled paragraphs.  That's all working.  I can even do it without making the document active which is especially pleasing because it feels more automated not to have the new document open while the script is running.

       

      However, now I want to do something I did with my previous system (OpenOffice Writer + Docmosis) which is to place a little group of a textbox + icon with a drop shadow in certain parts of my document.

       

      Here is an idea of what I mean: http://fireplan.ca/images/stories/firewatch.png

       

      Since I add large amounts of text and add pages manually to flow it I need to make sure this box will stay with the text it is associated with (in this case, the fire watch paragraph).  I don't know if there is a good way to copy this element in from another document or to create it with a script or what.  My solution so far has been lame.  I create the textFrame, include subframes and graphics as I see fit, and then put it in the document with a name (InfoBox) and set it to be invisible.  Then, if I run across a situation where I want to include it, I do something like:

       

       

      ...
      var sourceTextFrame=findTextFrame("InfoBox",theDoc);
      var objectDupe=sourceTextFrame.duplicate();
      objectDupe.visible=true;
      objectDupe.name=objectDupe.name+"-placed";
      
      app.select(objectDupe);
      app.cut();
      
      app.select(theStory.paragraphs[newParagraphIndex].insertionPoints[0]);
      app.paste();
      ...
      
      /* This code an be optimized and improved I'm sure but for now it's doing the job and is not the basis of my question */     
      function findTextFrame(frameName,theDoc){
                  var allItems=theDoc.allPageItems;
                  for(var a=0;a<allItems.length;a++){
                    if(allItems[a].name==frameName){
                     return allItems[a];
                      }
                    }
                  return null;
      }
      
      

       

      Basically I paste a visible copy of the info box into my main textframe in the appropriate place.  This technique of using app.select, app.cut, and app.paste just seems lame. It also means I have to make the document the active document so I can use cut and paste.

       

      Any suggestions or ideas about how to achieve this sort of thing more cleanly?