2 Replies Latest reply on Feb 10, 2017 7:01 AM by arekh2792424

    Trying to make a script that will select page items the script places.

    arekh2792424 Level 1

      Hello everyone,

           I am fairly new to InDesign scripting and I feel I am probably midding something pretty basic and fundamental, but here is the situation. I am trying to create a script that will prompt the user to select a file, then place that file 2UP on a 12x18 sheet, then select the placed objects. I have done a lot of research and I feel like I cant find anything because I am missing something so obvious that nobody else is asking. How do you select things with a script? I can do the prettying up and polishing for errors later, but the part of the script I could use some help with is:

      FilePlace();

      function FilePlace() {

          var selectedFile = File.openDialog("Choose a PDF File");

          var placeFile1 = app.documents.item(0).pages.item(0).place(selectedFile, ["0.36in","0.5in"])[0];

          var placeFile2 = app.documents.item(0).pages.item(0).place(selectedFile, ["9.14in","0.5in"])[0];

           HERE

      }

      Where I typed HERE I have tried a MULTITUDE of things including:

       

      app.documents.item[0].pages.item[0].pageItems[0,1].select([SelectionOptions.REPLACE_WITH]) ;

       

      app.documents.item[0].pages.item[0].pageItems[placeFile1, placeFile2].select([SelectionOptions.REPLACE_WITH]);

       

      app.activeDocument.pages.item[0].allPageItems.select([SelectionOptions.REPLACE_WITH]);

       

      app.activeDocument.pages.item[0].pageItems.selectAll([SelectionOptions.REPLACE_WITH]);

       

      and a whole laundry list of other things.

       

      To sum it up, I dont understand what happens after the files are placed because all of these come up as "undefined" and I just get an error. Do the variables placeFile1&2 just point to the raw file and not the instance of it that it places on the page? If so what does it refer to these items as, and can I cange this reference? How can I make this work? Any help will be much obliged!

        • 1. Re: Trying to make a script that will select page items the script places.
          Jump_Over Level 5

          Hi,

           

          placeFile1 is a good reference, so

          placeFile1.select();
          

           

          should work BUT

          notice that placeFile1 is a PDF object it means a content of graphic frame ==> so you cant select placeFile1 and placeFile2 at once ==> however you can select their parents

           

          Jarek

          • 2. Re: Trying to make a script that will select page items the script places.
            arekh2792424 Level 1

            THANK YOU SO MUCH! This was massively helpful. I figured I was overcomplicating it, just wasnt sure to what extent. This is the chunk of code I created that ended up working as intended and is a workaround for the parent issue as well!

             

            ..............

                    //Place the file 2UP.

                    var placeFile1 = app.documents.item(0).pages.item(0).place(selectedFile, ["0.36in" ,"0.5in"])[0];

                    var placeFile2 = app.documents.item(0).pages.item(0).place(selectedFile, ["9.14in" ,"0.5in"])[0];

                   

                    //Make references to parent objects of placed pdfs.

                    var placeFile1Parent = placeFile1.parent;

                    var placeFile2Parent = placeFile2.parent;

             

                     //Select the placed file instances.

                     placeFile1Parent.select(SelectionOptions.REPLACE_WITH);

                     placeFile2Parent.select(SelectionOptions.ADD_TO);

            ...............

            I really appreciate the help!