7 Replies Latest reply on Mar 4, 2011 6:28 AM by rajasgh

    default path


      Hi there


      I need a script to open a "place dialog box" with "desktop" as default location everytime. This helps in my experiment. One of the main concept is to make avoid Place navigation to last located point. I started with below. Please help in correcting and completing it. I use CS3.


      var thisDoc = app.activeDocument;
      var pathDefaults = app.activeDocument.place("~/Desktop/");



      Many Thanks,



        • 1. Re: default path
          Kasyan Servetsky Level 5
          var myFolder=Folder("~/Desktop"); 
          var myFile=myFolder.openDlg("Select Files To Place", undefined, true);
          • 2. Re: default path
            vvskpk Level 1

            Hey Kasyen


            Thanks for reply. Well, I actually tried that. But I am able to browse BUT unable to place the selected file in the page.


            I tried with different trial replacing .openDlg with .placeDlg. Can you put more light on this??


            Thanks a Ton!!!



            • 3. Re: default path
              vvskpk Level 1

              I am still doing trials but not getting successful. Please correct this. I need a place dialog box always locating to desktop by default and also should place the file when browsed and selected. Here is my "errored script" I mixed it up with many experiments. Please correct it. Again, i'm using CS3.


              I believe there will be a simplest way...


              var myPath = File.openDialog("Choose a File");

              if((myPath != ""){
              var myDocument, myPage;
              myDocument = myChooseDocument();

              myPage = myDocument.pages.item(0);
                myDocument = app.documents.add();
                      myPage = myDocument.pages.item(0);
                  myImport(myDocument, myPage, myPath);
              function myChooseDocument(){
                  var myDocumentNames = new Array;
                  myDocumentNames.push("New Document");
                  for(var myDocumentCounter = 0;myDocumentCounter < app.documents.length; myDocumentCounter++){
              var myImportFile;
              function myImportFile(myDocument, myPage, myPath){
                myImportFile = myPage.place(File(myPath), [0,0]);



              V V

              • 4. Re: default path
                Kasyan Servetsky Level 5

                Here is a very basic example with comments:

                var doc = app.activeDocument;
                var folder = new Folder("~/Desktop");
                // you can use a mask to filter file formats
                var mask = "All formats:*.*, JPEG:*.jpg, TIFF:*.tif, PSD:*.psd, EPS:*.eps, AI:*.ai";
                // the 3rd parameter is multiSelect  - if set to true you can select several files
                var file = folder.openDlg("Select Files To Place", mask, false);
                // if you selected a file
                if (file != null) {
                     var firstPage = doc.pages[0];
                     // place method returns an array of page items which can be image, PDF, EPS, ImportedPage, etc
                     // that's why I use [0] at the end
                     // the 2nd parameter (Optional) is placePoint - I'm using centimeters so this means X:1 cm, Y:2 cm
                     // the 3rd parameter (Optional) is destinationLayer
                     var image = firstPage.place( file, [1, 2], doc.layers.item("Layer 1") )[0];
                     // you can get the reference to the frame containing the image and do something with it
                     // for example, change its size, fit image, etc 
                     var frame = image.parent;
                • 5. Re: default path
                  vvskpk Level 1

                  WOW! Superb!!!!! It is really working.


                  I made little modifications inside to that for placing in the current active page.


                  var doc = app.activeWindow.activePage;

                  var image = doc.place( file);


                  THANKS A LOT for giving the main structure.




                  • 6. Re: default path

                    Hey Kasyan..really awesome work!!! I am actually for something like this. But would also want that to get added to selected frame box so that it pushes directly into that. Can we add that too here...that helps me a lot!!!



                    Many Thanks



                    • 7. Re: default path

                      Thanks for the script Kasyan its really helpful.


                      Thanks Prasant