16 Replies Latest reply on Mar 7, 2012 7:05 AM by MarkWalsh

    Questions creating a document, placing eps files

    MarkWalsh Level 4

      I haven't done much scripting with InDesign (I mostly script Illustrator and Photoshop), and I need a little help getting a few simple details correct. I am creating a script which will create a new document, and place EPS files from a folder into new pages, and resize and center them.

       

      1. How do I create a document of a specific size determined in the script (e.g. 1004 pixels x 768 pixels, or 10.6667 inches x 13.9444 inches). I am creating a document with 'app.documents.add()', but it's the default 8.5 x 11, and I don't know exactly how to create the document at the exact required size (or change it once it is created).

       

      2. I am placing the eps files using 'var pic = myPage.place(theFile)' and that is working properly, but I don't know how to resize the picture - it needs to be resized to the height of the page (the width will be larger than the page size) then center the image on the page. I'm not sure what class 'pic' is at this point, and it doesn't have a 'height' property for me to access. I tried accessing it's 'parent' property to see if that was the graphic's frame, but I didn't have any luck at that point either.

       

      I might have other questions as I progress, but any assistance with these 2 issues would certainly get me well on my way.

        • 1. Re: Questions creating a document, placing eps files
          MarkWalsh Level 4

          btw, forgot to mention that I'm using Javascript.

          • 2. Re: Questions creating a document, placing eps files
            Muppet Mark Level 5

            Mark there are a couple of ways you could go about this… I would set the document prefs so that new content auto centres & scales…

             

             

            #target indesign
            
            var f = File( '~/Desktop/Classeq_Logo.ai' ); // NOT a fan of EPS so I have an AI graphic file…
            
            var doc = app.documents.add(); // Either use a named preset or pass an object for properties…
            
            doc.frameFittingOptions.autoFit = true;
            doc.frameFittingOptions.fittingOnEmptyFrame = EmptyFrameFittingOptions.FILL_PROPORTIONALLY;
            doc.frameFittingOptions.fittingAlignment = AnchorPoint.CENTER_ANCHOR;
            
            var box = doc.spreads[0].pages[0].rectangles.add(); // there has to be 1 spread containg 1 page??
            
            box.geometricBounds = doc.spreads[0].pages[0].bounds;
            
            box.place( f ); // Auto scales…
            
            
            • 3. Re: Questions creating a document, placing eps files
              MarkWalsh Level 4

              Thanks, Mark. I'll look into that. That looks like it might do what I need.

               

              As for my first query, I believe I have found out how to make the document at the size I need. I was having problems understanding the DocumentPresets, and one of the issues I had was that the information I had listed it as DocumentPresets (with a capital D), but with testing, it wasn't working until I changed it to app.documentPresets. That seems to be working, although I still need to check through the rest of the properties to make sure I'm setting them correctly before creating the document.

               

              Appreciate the assistance.

              • 4. Re: Questions creating a document, placing eps files
                Muppet Mark Level 5

                I know what you mean about the documentation… Drives me nuts some times is it PDFBlahBlah, pDFBlahBlah or pdfBlahBlah… Do search this forum for Jong's helpers… There is ID & AI ones…

                • 5. Re: Questions creating a document, placing eps files
                  MarkWalsh Level 4

                  Thanks again. I tested your code, and it does exactly what I need it to do. I have a few more tweaks to do to get everything working perfectly, but I'm in the home stretch right now.

                   

                  One of my other issues with the documentation is that some of the method parameters I was looking up requuire a particular enumerated value, but nowhere in the document could I find the actual enumerations. Very frustrating, I don't recall these issues in working with the Photoshop or Illustrator references. It seems their PDFs are better laid out (including the methods and properties added to the PDF's index)

                   

                  Also, I couldn't find a Javascript reference PDF for CS5 (or, I think CS4), I've been using the one from CS3. I found a 'Tutorial' PDF and a 'Javascript Guide' for CS5, but not the Javascript Reference.

                   

                  Thanks again, I appreciate the help.

                  • 6. Re: Questions creating a document, placing eps files
                    Muppet Mark Level 5

                    Mark, for the other suite app's you can get PDFs of the scripting model… I don't know why but the last ID one I have is CS2. You can use the OMV in the toolkit… comm+/ or you can get these which I mentioned in the above post… Theres a mirror too somewhere but I don't have that link bookmarked… I think everyone uses these…

                     

                    http://www.jongware.com/idjshelp.html

                    • 7. Re: Questions creating a document, placing eps files
                      [Jongware] Most Valuable Participant

                      There are enough subtle--and not-so-subtle--differences between CS3 and newer versions to make old references practically useless.

                       

                      There hasn't been a Reference PDF by Adobe since CS3. You can find the modern version in all of its Flash interactivity inside the ExtendScript Toolkit Editor (look in the Help menu) but I don't like it, and could care even less about the ESTK editor as well. I prefer TextWrangler / TextPad, and use my own version of the very same help files: http://www.jongware.com/idjshelp.html

                       

                      Those are downloadable files; you can also browse them on-line, thanks to a generous bandwidth donation, at http://jongware.mit.edu/ -- for CS5.5 you would use http://jongware.mit.edu/idcsjs5.5/

                      • 8. Re: Questions creating a document, placing eps files
                        [Jongware] Most Valuable Participant

                        Hi Mark!

                         

                        Actually, I find myself accessing John's link more and more convenient -- mainly on other people's computers. Even at home now (having an after dinner iPad session of idly browsing round a bit) it's one of my bookmarks.

                        • 9. Re: Questions creating a document, placing eps files
                          Muppet Mark Level 5

                          iPad I daren't get one… You can't have something throwable while scripting… can you? my phone would say no… must just be me…

                           

                          Photo on 2012-03-02 at 19.48.jpg

                          • 10. Re: Questions creating a document, placing eps files
                            MarkWalsh Level 4

                            Thank you both. You've been very helpful.

                             

                            [Jongware] wrote:

                             

                            There are enough subtle--and not-so-subtle--differences between CS3 and newer versions to make old references practically useless.

                             

                            There hasn't been a Reference PDF by Adobe since CS3. You can find the modern version in all of its Flash interactivity inside the ExtendScript Toolkit Editor (look in the Help menu) but I don't like it, and could care even less about the ESTK editor as well. I prefer TextWrangler / TextPad, and use my own version of the very same help files: http://www.jongware.com/idjshelp.html

                             

                            Those are downloadable files; you can also browse them on-line, thanks to a generous bandwidth donation, at http://jongware.mit.edu/ -- for CS5.5 you would use http://jongware.mit.edu/idcsjs5.5/

                            I actually had come across these when I was looking for info, googling 'DocumentPresets' or whatever it was I was looking for at the time; hadn't looked into it too much, I'lll bookmark the link, and check out the downloads.

                             

                            Still having a problem I can't seem to solve, simple though it should be. Once I create the document, I am trying to save it. I try using 'docTemplate.save(filePath)' where 'filePath' is various attempts at building a filepath (including using the original document's fullname and adding a character to the end) - I get an error 'Cannot find the folder...' I can't believe I am this unable to do something as blatantly simple as saving a document; can you clue me in on what I may be doing wrong here?

                             

                            My only other feature I will be adding would be an export to PDF in a specific format once the file is saved, but I think I can get that working with a little time spent on it.

                            • 11. Re: Questions creating a document, placing eps files
                              MarkWalsh Level 4

                              Muppet Mark wrote:

                               

                              You can't have something throwable while scripting… can you?

                               

                               

                              That quote is now circulating my office!

                              • 12. Re: Questions creating a document, placing eps files
                                Muppet Mark Level 5

                                Mark, saving just requires a vaild file path… This should work on either OS Folder.desktop is a generic path… If your document is script created it will have NO path / file object until saved…

                                 

                                var savePath = File( Folder.desktop + '/SomeName.indd' );
                                
                                doc.save( savePath );
                                
                                doc.close( SaveOptions.NO );
                                

                                 

                                If you need some where in particular you would need to give some details… yeah phone circulated my house and garden…

                                • 13. Re: Questions creating a document, placing eps files
                                  MarkWalsh Level 4

                                  The document I am creating is based on another document (I am saving out the EPS files from elements of that document), and that document has been saved and has a valid filePath (I don't allow my script to even run if the current document has not been saved). I have tried saving using that original file's fullpath + "_test", "_Test.indd"; using the original file's filePath + '/Test.indd", 'Test.indd" and other combinations. My intent is to put it in the same directory with the original file, so I figure that using the filePath + a new filename should work, but it doesn't. I even used the same file path that the exported EPS files were using since it didn't have a problem with that filepath, but even that didn't seem to work. No matter what filepath I give it, I seem to get the same message ''Cannot find the folder...'

                                   

                                  Just noticing that there are spaces in one of the folders in the filepath, so I am getting '%20' in the filepath; would this cause any issues saving the file? It doesn't seem to mind the spaces during the 'Export' function (which is in a subdirectory of the parent directory of the original document).

                                   

                                  Also, I'm working on a Mac if that makes any difference.

                                  • 14. Re: Questions creating a document, placing eps files
                                    Muppet Mark Level 5

                                    If you are writing the files back to the console then %20 is nothing to worry about URI escaping? Don't know the proper terminology for this… If your doc is saved and unmodified these may help with working with file strings…

                                     

                                    doc = app.activeDocument;
                                    
                                    if ( doc.saved && ! doc.modified ) {
                                    
                                              $.writeln( decodeURI( doc.fullName ) );
                                              $.writeln( decodeURI( doc.filePath ) );
                                              $.writeln( doc.name );
                                    
                                              $.writeln( unescape( doc.fullName ) ); // Do NOT use I wasted a day of my life cos of this…
                                              $.writeln( doc.fullName.fsName ); // I use this one the most
                                    };
                                    
                                    • 15. Re: Questions creating a document, placing eps files
                                      MarkWalsh Level 4

                                      Thanks, I don't know if I'll get a chance to test that tonight, I'll look into it again on Monday.

                                      • 16. Re: Questions creating a document, placing eps files
                                        MarkWalsh Level 4

                                        I finally got this working; the reference I had checked stated that the save command took a filepath, not a file reference, as it's parameter. I was providing just the filepath to the 'save' command, and that wasn't working (although the same filepath worked for the 'export' command). Creating a file reference using 'File(filePath)' fixed the problem. I knew it was something stupid-simple like that, but it's so frustrating trying to find the answer when the documentation seems to indicate something different from reality.

                                         

                                        Thanks to all.