4 Replies Latest reply on Jul 19, 2017 11:19 PM by Pickory

    Placing snippets CC 2015 Mac

    Pickory Level 3



      I am placing snippets into my text by finding some text and then using place. The snippet is being placed, but the place is returning a zero length array.

      var placedStuff = found[0].insertionPoints[-1].place ( idmsFile );

      alert ( placedStuff.constructor.name ); // Array

      alert ( placedStuff.length ); // 0


      I have seen other threads where similar code is used.



      Any insight would be greatly appreciated.





        • 1. Re: Placing snippets CC 2015 Mac
          Laubender Adobe Community Professional & MVP

          Hi Pickory,

          I think, we have two cases here with placing snippets at insertion points.


          Case 1: The snippet contains one single page item at "first level" of objects.

          Then that page item will be anchored to the insertion point. It could be anything. A group of objects. One rectangle, oval, polygon, graphic line, text frame, even a guide! In this case the array returned is of length 0.


          Then you would retrieve the placed object with:

          var pageItemPlaced = found[0].parent.characters[ found[0].insertionPoints[-1].index ].pageItems[0];


          Case 2: The snippet contains several page items at "first level" of objects:

          Then InDesign will place the page items on the spread.

          In this case the array returned should contain the items.


          Just experiment with the following.

          Believe me, it's fun :-)


          // EDIT. Used the wrong version of the code. You placed at insertion points. I should do that as well.
          // So here the updated code:


              Have one text frame with some text on page 1 of the active document.
              In the folder of the document have:
              One snippet with 3 page items: "3Rectangles.idms"
              One snippet with 3 page items grouped: "1Group.idms"
              One snippet with 1 guide: "1Guide.idms"
          var textFrame = app.documents[0].textFrames[0];
          var found = [];
          found[0] = textFrame.characters.itemByRange(5,10).getElements()[0];
          var folder = File(app.documents[0].fullName).parent;
          var snippetFileName1 = "3Rectangles.idms";
          var snippetFile1 = File(folder+"/"+snippetFileName1);
          var snippetFileName2 = "1Group.idms";
          var snippetFile2 = File(folder+"/"+snippetFileName2);
          var snippetFileName3 = "1Guide.idms";
          var snippetFile3 = File(folder+"/"+snippetFileName3);
          // Will place the 3 rectangles on the spread:
              var returned1 = found[0].insertionPoints[-1].place( snippetFile1 , false );
          // Will place the group at insertion point:
              var returned2 = found[0].insertionPoints[-1].place( snippetFile2 , false );
          // OH WOW!
          // Will place the guide at insertion point:
              var returned3 = found[0].insertionPoints[-1].place( snippetFile3 , false );


          See here. Before placing snippets of sample code:



          After placing snippets of sample code:





          Wow. Never knew that one can place a guide at insertion point!


          Placed 3 rectangles on the spread selected:




          Placed group of 3 rectangles at insertion point selected:




          Placed guide at insertion point selected:






          • 2. Re: Placing snippets CC 2015 Mac
            Laubender Adobe Community Professional & MVP

            The ability to place guides at insertion points is really amazing!

            That also means: If you roatate the text frame of the insertion point where the guide is placed, the guide is rotated with the text frame. Cool. And the guide remains functional. Means, you could align page items to the guide easily etc.pp.


            Wow. I'm excited…




            ( All tests done with InDesign CS6 8.1.0 on Mac OS X 10.6.8 )

            • 3. Re: Placing snippets CC 2015 Mac
              Laubender Adobe Community Professional & MVP

              Ok. One could do placing guides at insertion points not only by scripting but also in the UI with:

              1. Selecting an insertion point and then place the IDMS file that contains a guide.

              2. Place an InDesign Library asset that contains a guide to a selected insertion point.


              The downside:

              Duplicate or copy/paste a text frame with a guide will make it "invisible"or "vanish" ( perhaps a redraw problem).

              So all this is of limited use.



              • 4. Re: Placing snippets CC 2015 Mac
                Pickory Level 3



                Thank you very much. Your expert explanation and extra insight deserve extra points!