10 Replies Latest reply on Feb 2, 2009 1:57 PM by (Olav_Kvern)

    Open Dialog doesn't open files

    Level 1
      I am using the following to browse for multiple files to open.
      var myFileMain = File.openDialog ("Select a file", "Documents:*.indd",false);

      However, when I add this line to display the files I get the error "undefined, not an object"
      var myLayoutWindow = myDocument.windows.add();

      I have even just copied the snippet from the Official Scripting Guide to see if I was causing the error with my first line but I get the same error here for the second line.
      var myDocument = app.open(File("/c/myTestDocument.indd"), false);
      var myLayoutWindow = myDocument.windows.add();

      So I tried switching the first line to true instead of false but then in testing in Indesign I get the message that no documents are open.

      Can anyone point out what I am doing wrong?
        • 1. Re: Open Dialog doesn't open files
          Level 1
          The open dialog returns a file object that you must open:

          var myFileMain = File.openDialog ("Select a file", "Documents:*.indd",false);
          var myDocument = app.open(myFileMain);

          Dave
          • 2. Re: Open Dialog doesn't open files
            Level 1
            Thank Dave, you've been a great help again.

            One question; any idea why the documentation states to add a window rather than this function?
            • 3. Re: Open Dialog doesn't open files
              Level 1
              Which documentation where?

              Dave
              • 4. Re: Open Dialog doesn't open files
                Level 1
                Sorry I wasn't clear.

                InDesignCS3_ScriptingGuide_JS.pdf from Adobe.

                I'm using the CS3 version since that is the version of ID I have.

                Thanks again,
                Matt
                • 5. Re: Open Dialog doesn't open files
                  Level 1
                  Could you give me a page reference? Or better yet quote the text that led you astray?

                  Dave
                  • 6. Re: Open Dialog doesn't open files
                    Level 1
                    Hi Matt,

                    re: "I have even just copied the snippet from the Official Scripting Guide to see if I was causing the error with my first line but I get the same error here for the second line.
                    var myDocument = app.open(File("/c/myTestDocument.indd"), false);
                    var myLayoutWindow = myDocument.windows.add();"

                    The first question--do you have a file named "myTestDocument.indd" on a drive named "c"?

                    The second parameter controls whether the document opens with a visible window or not. If you omit it or change it to true, you don't need the line that creates a new window.

                    Thanks,

                    Ole
                    • 7. Re: Open Dialog doesn't open files
                      Level 1
                      Hi Dave & Olav,

                      First to Dave; quote is below. From page 12.
                      You can choose to prevent the document from displaying (i.e., hide it) by setting the showing window
                      parameter of the open method to false (the default is true). You might want to do this to improve
                      performance of a script. To show a hidden document, create a new window, as shown in the following
                      script fragment (from the OpenDocumentInBackground tutorial script):
                      //Opens an existing document in the background, then shows the document."
                      //Youll have to fill in your own file path."
                      var myDocument = app.open(File("/c/myTestDocument.indd"), false);"
                      //At this point, you could do things with the document without showing the"
                      //document window. In some cases, scripts will run faster when the document"
                      //window is not visible."
                      //When you want to show the hidden document, create a new window."
                      var myLayoutWindow = myDocument.windows.add();

                      Second for Olav,
                      In actuality I changed the "myTestDocument.indd" to an actual file and I did try changing the false to true (didn't try omit even though I know that it will default to true).

                      The error message occurs when the next line executes. Error "No Documents are open". The snippet Dave gave above fixed the problem, but it would seem from the documentation that the above solution should work as well.

                      I hope this is clear enough. Not really a big deal for me at this point since Dave's solution worked, just wanted to know if I was missing something major in interpretation.

                      Thank you both for your time and expertise.
                      • 8. Re: Open Dialog doesn't open files
                        Level 1
                        You either didn't understand or didn't read the example well enough. You have to open the document before you can display a window. Your original code located the document file but didn't open it.

                        Dave
                        • 9. Re: Open Dialog doesn't open files
                          Hello,

                          CAn somebody help me?

                          I'm trying to open a file with the code below, but I get a security error (no access to the file) Please tell me what is wrong...

                          Code:
                          myIndesign = new ActiveXObject("IndesignServer.Application.CS3");
                          var myDocument = myIndesign.open("E:\test\tagged.indd", false);

                          Thanks,

                          Wim
                          • 10. Re: Open Dialog doesn't open files
                            Level 1
                            Hi Wim,

                            You should start a new topic, because your message has nothing to do with the thread you've posted it in.

                            To create an instance of InDesign server, use CreateObject, as shown in all of the example scripts.

                            Thanks,

                            Ole