9 Replies Latest reply on May 7, 2009 1:28 AM by René Mølsted

    [JS IDS CS4] placing Indd-files

    René Mølsted

      Hi all,

      I'm trying to place an InDesign-file via JavaScript, if the script is run from the client it works like a charm but on the server I get an error.

       

      app.documents.item(0).rectangles.itemByID(ItemID).place("Macintosh HD:Test.indd")[0];
      

      If I point to a PDF works just fine.

       

      Is IDS not capable of placing indd-files?

       

      Error:

      JavaScript Error!\n\nError Number: 45\nError String: Object is invalid\n\nFile: /Scripts/PlaceInddFile.jsx\nLine: 34\nSource: app.documents.item(0).rectangles.itemByID(ItemID).place("Macintosh HD:Test.indd")[0];
      

       

      --

      molsted

        • 1. Re: [JS IDS CS4] placing Indd-files
          Dave Saunders Level 4

          Try passing a file object rather than the name of a file.

           

          Do a test to make sure the file object exists before committing to the place.

           

          Dave

          1 person found this helpful
          • 2. Re: [JS IDS CS4] placing Indd-files
            René Mølsted Level 1

            Hi Dave

            Here's the script I'm using:

            var FilePath = "Macintosh HD:Test.indd"
            var PageNr = 2;
            
            
            //GET THE PAGEITEM
            var MyBox=app.documents.item(0).rectangles.itemByID(ItemID);
                           
            if (FilePath.exists) {
                 
                 app.importedPageAttributes.pageNumber = PageNr;
                 app.importedPageAttributes.importedPageCrop = 1131573314;
                           
                 //Place image in graphics frame
                 MyBox.place(FilePath)[0];
            }
            

             

            Can you make an example on how pass a file object rather than the name of a file?

             

            The, to me, strange part is if I point FilePath to a PDF it just works, eg.:

            var FilePath = "Macintosh HD:Test.pdf"
            var PageNr = 2;
            
            
            //GET THE PAGEITEM
            var MyBox=app.documents.item(0).rectangles.itemByID(ItemID);
                           
            if (FilePath.exists) {
                 
                 app.importedPageAttributes.pageNumber = PageNr;
                 app.importedPageAttributes.importedPageCrop = 1131573314;
                           
                 //Place image in graphics frame
                 MyBox.place(FilePath)[0];
            }

             

             

            --

            molsted

            • 3. Re: [JS IDS CS4] placing Indd-files
              Kasyan Servetsky Level 5

              MyBox = app.selection[0]; // a rectangle is selected
              var FilePath = "Macintosh HD:Test.indd";
              var myFile = new File(FilePath); // the reference to a file
              MyBox.place(myFile);

              • 4. Re: [JS IDS CS4] placing Indd-files
                Peter Kahrel Adobe Community Professional & MVP

                What Dave means is this: use

                 

                var FilePath = File ("Macintosh HD:Test.indd")

                 

                On Windows this is necessary for both PDF and InDesign. It's always better to work with objects rather than with strings.

                 

                Peter

                1 person found this helpful
                • 5. Re: [JS IDS CS4] placing Indd-files
                  René Mølsted Level 1

                  Getting closer now ...

                   

                  The script:

                  var myFile = File (scriptArguments[0]);
                  var myPageNr = parseInt (scriptArguments[1]);
                  var MyBox=app.documents.item(0).rectangles.itemByID(ItemID);
                  
                  alert ("File path: " + myFile);
                  alert ("Page to be placed: " + myPageNr);
                  alert ("Item ID: " + ItemID);
                  if (myFile.exists) {
                  
                       app.importedPageAttributes.pageNumber = myPageNr;
                       app.importedPageAttributes.importedPageCrop = 1131573314;
                                 
                       //Place image in graphics frame
                       MyBox.place (myFile);
                  }
                  

                  The log:

                  [server] File path: /Test.indd [18384]
                  [server] Page to be placed: 2 [18384]
                  [server] Item ID: 678 [18384]
                  [server] JavaScript Error!\n\nError Number: 45\nError String: Object is invalid\n\nFile: /Scripts/PlaceInddFile.jsx\nLine: 29\nSource:      MyBox.place (myFile); [18384]
                  

                  How to I tell wich object is invalid?

                   

                  The arguments are correct sent to the script, if I run the script from within ID (client) and set var myPageNr = 678; it works like a charm.

                  The script is called three times in my test, the first time things happens as expected, page 1 of the InDesign file (/Test.indd) is placed, but the other two times I get the above error. Although it's the same file I'm trying to place, just a different page.

                   

                   

                  --

                  molsted

                  • 6. Re: [JS IDS CS4] placing Indd-files
                    Dave Saunders Level 4

                    Could it be that the ItemID value is wrong?

                     

                    Put in an alert:

                     

                    alert(MyBox.constructor.name);

                     

                    what does it say?

                     

                    Dave

                    • 7. Re: [JS IDS CS4] placing Indd-files
                      René Mølsted Level 1

                      Hmmm, still getting an error

                      [server] File path: /Test.indd [18384]
                      [server] Page to be placed: 3 [18384]
                      [server] Item ID: 677 [18384]
                      [server] Constructer name: Rectangle [18384]
                      [server] JavaScript Error!\n\nError Number: 45\nError String: Object is invalid\n\nFile: /Scripts/PlaceInddFile.jsx\nLine: 31\nSource:      MyBox.place (myFile); [18384]
                      

                       

                      The thing is, if I use the ItemID listed in the log and set them as a variable it works just fine, so the ItemID must be correct?!

                       

                      var myFile = File (/Test.indd);
                      var myPageNr = 3;
                      ItemID = 677;
                      var MyBox=app.documents.item(0).rectangles.itemByID(ItemID);

                      alert ("File path: " + myFile);
                      alert ("Page to be placed: " + myPageNr);
                      alert ("Item ID: " + ItemID);
                      if (myFile.exists) {

                           app.importedPageAttributes.pageNumber = myPageNr;
                           app.importedPageAttributes.importedPageCrop = 1131573314;
                                   & nbsp;
                           //Place image in graphics frame
                           MyBox.place (myFile);
                      }

                      The above works just fine.

                       

                       

                      --

                      molsted

                      • 8. Re: [JS IDS CS4] placing Indd-files
                        René Mølsted Level 1

                        File being placed. Just replace .txt with .indd

                        • 9. Re: [JS IDS CS4] placing Indd-files
                          René Mølsted Level 1

                          If I place a pdf instead it works just fine, just by adding this:

                          app.pdfPlacePreferences.pageNumber = myPageNr;
                          app.pdfPlacePreferences.pdfCrop = PDFCrop.cropMedia;
                          

                          could it be these lines that are causing it:

                          app.importedPageAttributes.pageNumber = myPageNr;
                          app.importedPageAttributes.importedPageCrop = 1131573314;
                          

                           

                           

                          --

                          molsted