9 Replies Latest reply on Nov 14, 2012 1:47 AM by mrgum6y

    Accessing importedPageAttributes.pageNumber

    mrgum6y

      Hi

      I have used CS since forever (FH4 even ;P) but only now have reason to delve into Indesign scripting (CS5.5),

       

      For my new project i am trying to script changing the order of placed indesign and illustrator objects.

       

      To expand I have a multi paged indesign file that are placed so many to a page in a "containing" Indesign file.

      The illustrator files also have multiple artboards, similare size and are also placed on pages of the "containing" file.

       

      I have see scripts (like the brilliant Zanelli multiPage Importer) that use loops to set importedPageAttributes.pageNumber

      so that placed material is taken from the correct page.

      e.g.

      var myRec = tempdoc.rectangles.add({geometricBounds:[a,b,c,d]});

      app.importedPageAttributes.pageNumber = 2; //Import  page 2 not 1

      myRec.place(docFile,false);

       

      I have seen scripts that query properties of these linked objects by using the links[] object:

      (This example returns the name of layer[j] of the linked object [i])

      e.g.

      links = doc.links;

      MyLayer = links[i].parent.graphicLayerOptions.graphicLayers.item(layernames[j]) ;

       

      If you return the filepath of the linked objects the pages are referenced as

      "some/path/myContentFile.indd,some/path/myContentFile.indd:2,some/path/myContentFile.indd: 3"

      so the :number obviously refers to the document page.

       

      But...

      How in a script can I query the page number of a placed object?

      Is it by reading the importedPageAttributes.pageNumber?

      HOw is this done for linked objects.

      or is there another way?

       

      Many thanks for your time and comments,

        • 1. Re: Accessing importedPageAttributes.pageNumber
          mrgum6y Level 1

          OK, found a solution,

          What i needed was someone to tell me about pdfAttributes.

           

          EXAMPLE, when :

          var myLinks;

          myLinks = app.activeDocument.links;

          var tempLink = myLinks[i];

           

          then

          tempLink.parent.parentPage.name;

          will return the page number that the linked object has been paced on in the current document.

           

          BUT

          tempLink.parent.pdfAttributes.pageNumber;

          will return the page number the object is on in the linked document.

          (Which is what i was after.)

           

          Can anybody offer advise about how reliable this is? (for placed both indesign and illustrator files)

           

          Are there any alternative methods to evaluate the page number of the object in the linked document?

           

          Thanks.

          • 2. Re: Accessing importedPageAttributes.pageNumber
            Jump_Over Level 5

            Hi,

            As far as I know, you could use it for placed indesign and PDF files (placing .ai means linkType is PDF).

             

            But be awared with:

            - tempLink.parent.parentPage.name gives you a name (string) which can be fully editable by user and many often differ to page number;

            - to get a number (page index starting from 0) use tempLink.parent.parentPage.documentOffset;

            - tempLink.parent.pdfAttributes gives you error with linkTypes others then "InDesign Format Name" and "Adobe Portable Document Format (PDF)"

                 cause not every graphic (link parent) has this ( pdfAttributes ) property.

             

            rgds

            • 3. Re: Accessing importedPageAttributes.pageNumber
              mrgum6y Level 1

              Cheers rgds, thats a good tip about using documentOffset instead.

               

              The parent.pdfAttributes.pageNumber is the important bit.

               

              In my script I will test for the document type before i query the pdfAttributes.pageNumber as i realise not all document types support multiple pages/artboards, and its not too much of a worry as the project material is going to be all either indesign or illustrator. (so far)

               

              But it still seemed a bit of a flakie and back door method to retrive the page number of a placed object in a linked document.

              • 4. Re: Accessing importedPageAttributes.pageNumber
                grodma

                Also keep in mind that pdfAttributes is read only.

                I'm struggling to devise a way to change the page number of a all placed pdfs to match the Indesign page they're on and that is a hurdle.

                • 5. Re: Accessing importedPageAttributes.pageNumber
                  mrgum6y Level 1

                  cheers grodma, yeah it's read only, how to read it was the unknown.

                   

                  A quick plan for my script is to :

                  make a note of the file and page number of all the links by populating some array,

                  remove the placed links to be moved, from the current document,

                  then import them again placing them again on which page i want by setting app.importedPageAttributes.pageNumber before the import.

                  Also add some geometric bounds in there too, to control position on the page.

                   

                  Ive seen a few scripts that create new documents,

                  but not many that handle reordering or manipulating the contents of an existing one.

                   

                  I think you could have a script to push a placed object around the page that it is on but cannot see how you could move it from one page to another without removing it and importing it again to where it is wanted.

                  Hence this line of quesions.

                  • 6. Re: Accessing importedPageAttributes.pageNumber
                    Jump_Over Level 5

                    Hi,

                     

                    • use app.PDFPlacePreference.pageNumber for placing chosen PDF (.ai also) page;
                    • use app.importedPageAttributes.pageNumber for placing chosen indesign page;

                     

                    To move, say, rectangle to page "myPage" use rectangle.move(myPage)

                    To move it to some coordinates use .move() method with "to" or "by" parameters:

                    rectangle.move([x,y]) will move rec to x,y position on current Spread;

                    rectangle.move(undefined, [x,y] ) will move rec by x,y regarding current position on current Spread;

                     

                    hope...

                    • 7. Re: Accessing importedPageAttributes.pageNumber
                      mrgum6y Level 1

                      OK here is the first go, close but no cigar .. ..

                      //*********************CODE****************

                      // for indesign 5.5  javescript

                      // original file "ReorderCurrentContent.jsx"

                      // Reorder Current Content Script

                      // By John Ardley (mrgum6y@hotmail.com)

                      // Last modified 8/11/12

                      // Status - knackered... :^(

                       

                      Main();

                       

                      function Main()

                      {

                          // get links

                          var myLinks;

                          myLinks = app.activeDocument.links;

                          // count links

                          var numberOfLinks;

                          numberOfLinks = myLinks.length;

                          // read links

                          var linkPath = [];

                          //var placedOnPage = []; // to demonstrate myLinks[f].parent.parentPage.documentOffset;

                          var linkedToPage =[];

                          var linkType = [];

                       

                          //read and store the links info

                           for(f=0;f<numberOfLinks;f++){

                               linkPath[f] =  myLinks[f].filePath;

                               //placedOnPage[f] = myLinks[f].parent.parentPage.documentOffset; // this returns page it is placed on

                               linkedToPage[f] = myLinks[f].parent.pdfAttributes.pageNumber; // this returns page it is on of linked doc.

                               linkType[f] = myLinks[f].linkType;

                           }

                       

                          // create dialog string

                          var linksText=[];

                          var f=0;

                          for(f=0;f<numberOfLinks;f++){ linksText[f] = f; }

                       

                          // create dialog

                          //description: Title and list of current links, label and list of new links.

                          var ilDialog = app.dialogs.add({name:"Show image links", canCancel:true});

                      with (ilDialog){

                                      with(dialogColumns.add()){

                                          with(dialogRows.add()){ staticTexts.add ({staticLabel:"Index of linked items."}); }

                                          with(dialogRows.add()){ var currentOrderText = textEditboxes.add({editContents:linksText.toString(),minWidth:200}); }

                                          with(dialogRows.add()){ staticTexts.add ({staticLabel:"New order of linked items."}); }

                                          with(dialogRows.add()){ var newOrderText = textEditboxes.add({editContents:linksText.toString(),minWidth:200}); }

                                      }

                              }

                       

                          // show dialog then action

                          if(ilDialog.show() == true){

                       

                              // new link order held in newOrder[]

                              var newOrder = [];

                              newOrder = newOrderText.editContents.split(",");       // add check the array length

                       

                              var g="";

                              var changedLinkCounter =0;

                              //place new links

                              for(f=0;f<numberOfLinks;f++)

                              {

                                  g = (newOrder[f]); //number

                                  if(f!=g){

                                      //Test linkType

                                    if( (linkType[f].indexOf("PDF")) !=-1 ){

                                          app.pdfPlacePreferences.pageNumber = linkedToPage[g]; //

                                    }else{

                                          app.importedPageAttributes.pageNumber = linkedToPage[g];

                                    }

                                    myLinks[f].parent.place(linkPath[g]);

                                    changedLinkCounter++;

                                  }

                              }

                              alert(changedLinkCounter + " links changed.");

                          }

                          else{

                             alert("Action cancelled.");

                          }

                      }//end main

                      //*********************END CODE**************

                       

                      The above is broken! doesnt work!

                       

                      app.PDFPlacePreference.pageNumber 

                      doesn't work I think its a class name and not an instance

                       

                      app.pdfPlacePreferences.pageNumber = linkedToPage[g];

                      doesn't work.... dont know why

                       

                      Any ideas anyone?

                      • 8. Re: Accessing importedPageAttributes.pageNumber
                        Laubender Adobe Community Professional & MVP
                        app.pdfPlacePreferences.pageNumber
                        

                         

                        should work. It is returning a Number that is not based on index 0, but starts with 1.

                         

                        In using

                         

                        app.pdfPlacePreferences.pageNumber = linkedToPage[g];
                        

                         

                        you are using the 0 based documentOffset. And you cannot apply 0 as a pageNumber to the pdfPlacePreferences.
                        Before that you have to add 1 to to your Number you obtain with documentOffset.

                         

                        Maybe it's enough to add 1 like that:

                         

                        app.pdfPlacePreferences.pageNumber = linkedToPage[g] + 1;
                        


                        Be careful with the your variable names. "linkedToPage" should get a more discriptive name.

                        Maybe "pageDocumentOffsetNumber" or something…

                         

                        Uwe

                        • 9. Re: Accessing importedPageAttributes.pageNumber
                          mrgum6y Level 1

                          Thanks for taking the time to comment,

                           

                          //var placedOnPage = []; // to demonstrate myLinks[f].parent.parentPage.documentOffset;

                          is actually commented out just to show it was considered, these values could be read, but were not in this case.

                           

                          The page the linked item is on is found by using

                            myLinks[f].parent.pdfAttributes.pageNumber

                          which in the few small tests I've done seems to return the correct values for both indeisgn and illustrator placed documents,

                          My problem now lies in that

                             app.pdfPlacePreferences.pageNumber = linkedToPage[g];

                          doesnt work as well as

                            app.importedPageAttributes.pageNumber = linkedToPage[g]

                           

                          Thanks for the ideas