15 Replies Latest reply on Jan 27, 2015 2:51 PM by Davin Salo

    Place snippet script

    nicoboss76 Level 1

      Hi all,

       

      I am working on a script that is asking InDesign to place a snippet into the slug of whatever document is created. The problem is I don't seem to have control over the placement coordinates of the snippet: it always place it at exact same coordinates than where it was placed when I created it ...

       

      Any idea about how to get around this problem would be greatly appreciated:

       

      - Placing in a slug

      - maybe the script would set margin to zero at the bottom trim of any document created and the snippet would be placed at a 0, 1" coordinate

      - maybe the script coordinate would be x:0, y:(myDocumentHeight + 1)

       

      I just don't know....

       

      Thank you!

        • 1. Re: Place snippet script
          nicoboss76 Level 1

          ok got it.

           

          just need to ask the script to place the snippet - it will place it at the same location as the one it was at when the snippet was made. If you're good with it then no problem.

          If, like me, the snippet position will depend on the size of the document, then you need to ask the script to select whatever the snippet is made out of (my snippet is a group so the script I made reffers to it as group1) and move it to whatever location.

           

          In my case, I want to place my snippet in my slug area.

           

          My script looks like this:

           

          ......

          set myPage to page 1 of myDocument
                          tell myPage
                              set myPlacedSnippet to place "Macintosh HD:Untitled.idms"
                          end tell
                          set mypageitems to group 1 of myPage
                          tell mypageitems
                              move to {0, (myHeight + myVerticalBleed)}
                          end tell
                      end tell

           

           

          et voila!

          • 2. Re: Place snippet script
            nicoboss76 Level 1

            in other words, and as far as I know (which is not that far, btw) APPLESCRIPT DOESN'T KNOW WHAT A SNIPPET IS.

            You have to define your snippet by whatever it is made of .

            • 3. Re: Place snippet script
              Harbs. Level 6

              Once a snippet is placed in a document, the "snippet" ceases to exist as a "snippet" -- it's not linked to the external file; it's just some generic page items.

               

              So, it's not a matter of InDesign not knowing what a snippet is. It's a matter of understanding what a snippet is!

               

              Harbs

              • 4. Re: Place snippet script
                nicoboss76 Level 1

                yeah - it's actually what I ended up gessing – so it was more about me understanding what a snippet is - and understanding how Applescript works.

                 

                One step at a time

                 

                Actually I am proud to say that I have been able to integrate my *raw* applescript in my workflow - and it is REALLY helping me !

                 

                Love it!

                 

                Now let's refine and add options.

                • 5. Re: Place snippet script
                  ellishumphres Level 1

                  For future generations:

                   

                  indesign preferences/file handling/snippet import[position at original location vs. position at cursor location]

                   

                  This, naturally, will require user input as to where to place the snippet once invoked, but the preference certainly has bearing in the thought process when scripting.

                  • 6. Re: Place snippet script
                    Vera Kapinos

                    My problem is absolutely opposite: I want my snippet to go to the same place as in a document it was created - but InDesign places it at the left top corner of the page.

                    And yes, in preferences I have "Position at Original Location" Snippet Import option.

                    Any idea, please?

                    • 7. Re: Place snippet script
                      John Hawkinson Level 5

                      The normal solution is to simply move the snippet after it is placed, programattically in your script. Is there a reason that is a problem?


                      • 8. Re: Place snippet script
                        Vera Kapinos Level 1

                        It's a problem for me - I have to figure out how to define whatever I placed, how to measure where to move... Yes, it's doable, I guess, but complicated comparing to drag&drop by hand. I was just thinking that if the author of that post had this behavior - Script placing a snippet to the original position - it's possible to make a Script somehow to do it, just need to know some preference or whatever...

                        • 9. Re: Place snippet script
                          John Hawkinson Level 5

                          The place() method returns an array of items that it placed...

                          • 10. Re: Place snippet script
                            nicoboss76 Level 1

                            My original post was not accurate. I believe that when you create a script that is calling out for the placecement of a snippet, iD will center on your screen by default. In other words it will place your snippet randomly.

                            In order to control the placement of your snippet on your page, you have to define coordinates.

                            It makes a much more complicated script that you would think.

                             

                            That is my understanding of how it works in CS2, 3 & 4 - I don't know for CS5.

                             

                            By digging into scripting language, I don't see why you would not be able to have the script take advantage of the "maintain placement" option mentionned in this conversation.

                             

                            For my part, I'd rather specify coordinate so that I can customize placement as document size change (my script actually reads the size of the document and place my snippet precisely in the slugg area, not matter what.)

                             

                            Here is an abstract:

                             

                            set myPage to page 1 of myDocument
                                        tell myPage
                                            set myPlacedSnippet to place "Macintosh HD:PrintSlugforscript.idms"
                                        end tell
                                        set mypageitems to group 1 of myPage
                                        tell mypageitems
                                            move to {0, (myHeight + (myVerticalBleed * 3))}
                                        end tell

                             

                            In this instance, I got the script to understand what "myHeight" is (height of the document) and what "myVerticalBleed" is.

                            As a result, my slug (my snippet) is always positionned along my vertical trim line and fare enough away from my bleed (3 times whatever bleed there is around my document)

                             

                            Just have to understand that a snippet is nothing but a group of objects. It's like a bundle you inport in your document. The only way I found to use and move my snippet automatically is to import it in my document before anything else, then have the script look for whatever group of objects it finds in the document "group 1"  and move it to precise coordinates.

                             

                            This is kind of complicated so I'd understand that under certain circumstances you'd rather do it manually. For me it works because importing and positionning the snippet is only a small part of what the script is doing.

                             

                            Hope this helps!

                            • 11. Re: Place snippet script
                              Vera Kapinos Level 1

                              Yes, I finally figured everything out.

                              Because I have a lot of other stuff on the page, in order to move my snippet to the desired place I put it in a separate layer, make it active and tell layer to move it (when I make a snippet I group everything, just in case, so "page item 1" works for me fine). My problem is that the documents I place it in may have coordinates 0 point in different places, so it may be problematic to point to exact place where to move it...

                              • 12. Re: Place snippet script
                                charanseeram Level 1

                                Hi ,

                                 

                                - I have to select mutiple snippets (.idms) files from my search list of plugin and drag those on to ID document should place  one over the other as an offset .

                                - Code below is fine to provide x,y for snippets on the page . But here am in need to place this x,y for snippets over paste borad instead of page .

                                 

                                var arr:Array = [snippetX,snippetY];

                                                        if(myDocument.groups.length == 0){                       

                                                            arr = [10,20];

                                                            snippetX +=10;

                                                            snippetY +=10;

                                                           

                                                        }else{

                                                            arr=[snippetX,snippetY];                           

                                                            snippetX +=10;

                                                            snippetY +=10;                       

                                                        }                                       

                                                       

                                                        myDocument.pages.item(0).place(air,arr);

                                 

                                 

                                Can i place snippets on pastebord instead of page.

                                • 13. Re: Place snippet script
                                  nicoboss76 Level 1

                                  your code seems to be javascript, not applescript (I did all my script using Applescript) - so I will not be able to give you much code here.

                                   

                                  But the concept must be the same:

                                  You cannot tell InDesign to paste on "the pasteboard" specifically. But you can make sure your pasted item is always on the pasteboard by doing the following:

                                  Say you have a document 8" tall – and that you want to place your snippet 2" bellow the page (on the pasteboard)

                                  If your origin point is at the upper left corner of the document, you will need to place your snippet at y=10"

                                   

                                  Programatically you'd have to setup the following:

                                  - make sure your zero point is set at the origin of the document (upper left corner)

                                  - define "myHeight" to the document height

                                  - define the slug vertical placement to "myHeight" + 2in

                                   

                                  Same goes for horizontal placement.

                                   

                                  Hope this help!

                                  • 14. Re: Place snippet script
                                    charanseeram Level 1

                                    Am sorry for late reply , thanks that worked , i passed file and  duplicate frame to send geometric bounds and then assinged same geometric bounds to group which fixed my problem .

                                     

                                    public function PlaceSnippetInFrame(file:File,_frame:Object):void{

                                                try{               

                                                    myDocument.pages.item(0).place(file);               

                                                    var myGroupObject:com.adobe.indesign.Group=myDocument.groups.item(0);   

                                                    myGroupObject.geometricBounds =_frame.geometricBounds;   

                                                    _frame.remove();            

                                                }catch(e:Error){

                                                    trace("Error:"+e.toString());

                                                    myLogger.error(e.message);

                                                }

                                            }

                                    • 15. Re: Place snippet script
                                      Davin Salo

                                      I searched for a long time for the answer to this and found it on this forum:

                                      Placing InDesign snippets on a page - Adobe InDesign Scripting

                                       

                                      Copy this line for the javascript to insert your snippet above the document (replace the file path,):

                                      var mySnippet = app.activeDocument.pages.item(0).place(File("/c/test/snippet1.inds"), [0, -1.75]);

                                       

                                      Where [0, -1.75] is [left, top] or [x, y]

                                       

                                      No need to define your snippet at all unless you plan on moving it from the original location. I have a default slug area on my document presets, and set my units by default to inches, so I can automatically point my script to place the snippet at [0, -1.75] to get the snippet to place straight into my slug at the top left, in the slug at the top of the document. Because the height of a document is always varied for me, I can use a variable for the width & height.

                                       

                                      In addition to that I can set a few variables when saving my snippet to autocomplete by placing Text Variables "DocHeight" and "DocWidth" and updating those variables with the width and height of the document (in this case done in inches in the "pagesize" and "pagesize.variableOptions" section).

                                       

                                      Copy below this point for the script to insert the snippet below your document:

                                       

                                      var doc = app.activeDocument;

                                      var w = doc.documentPreferences.pageWidth;

                                      var h = doc.documentPreferences.pageHeight;

                                       

                                      doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.INCHES;

                                      doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.INCHES;

                                       

                                      app.activeDocument.pages.item(0).place(File("~/desktop/AdProof.idms"), [0, (h+0.25)]);

                                       

                                      pagesize = app.activeDocument.textVariables.itemByName("DocHeight");

                                      pagesize.variableOptions.contents = h + " in";

                                      pagesize = app.activeDocument.textVariables.itemByName("DocWidth");

                                      pagesize.variableOptions.contents = w + " in";