7 Replies Latest reply on Jun 4, 2011 3:08 AM by maphiom

    [JS][CS3]how to get refrence for source file

    Mac_06 Level 2

      Hi All

       

      I am new and learning javascript Gradually Could any one help on this as i do have a code for load style but don't know how to get refrence for "source file" and "targetDoc"

       

      targetDoc.importStyles(charImport, sourceFile, clashPolicy);
      targetDoc.importStyles(paraImport, sourceFile, clashPolicy);

       

      Can any one figure it out

       

      Many Thanks

        • 1. Re: [JS][CS3]how to get refrence for source file
          Thomas B. Nielsen Level 3

          Untested, but should get you going:

           

          var targetDoc = app.activeDocument; // the current active document
          var myFile = File.openDialog("Choose a File"); // a file from the file system

           

          targetDoc.importStyles(charImport, sourceFile, clashPolicy);
          targetDoc.importStyles(paraImport, sourceFile, clashPolicy);

           

          --

           

          Thomas B. Nielsen

          http://www.lund-co.dk

          • 2. Re: [JS][CS3]how to get refrence for source file
            Mac_06 Level 2

            Thanks Thomas for quick responce, but could you clearify that "myFile" would be a "sourceFile" and as i have over 100 files to load the styles so how could i use this refrence as a loop.

            • 3. Re: [JS][CS3]how to get refrence for source file
              Thomas B. Nielsen Level 3

              I'm not sure what you are trying to achieve, could you please elaborate?

               

              Do you want to load all the styles from one document into all 100 documents, or do you want all the styles from the 100 documents into 1 document or what is the goal?

               

              The following will let you choose a folder of files, open each of the files in it and import the styles from source document. It is not a complete script, make sure to test and modify before running on anything else than test files :-)

               

              var MyFolderWithFiles = Folder.selectDialog ("Choose a folder");
              var sourceFile = File.openDialog("Choose the styles source");

               

              var myFiles = MyFolderWithFiles.getFiles("*.indd");

               

              for(i = 0; i < myFiles.length; i++) {
                  theFile = myFiles[i];
                  app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
                  var targetDoc = app.open(theFile, true);
                  app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
                  targetDoc.importStyles(ImportFormat.CHARACTER_STYLES_FORMAT, sourceFile, GlobalClashResolutionStrategy.LOAD_ALL_WITH_OVERWRITE);
                  targetDoc.importStyles(ImportFormat.PARAGRAPH_STYLES_FORMAT, sourceFile, GlobalClashResolutionStrategy.LOAD_ALL_WITH_OVERWRITE);
                  targetDoc.close(SaveOptions.YES);
              }

               

              --

               

              Thomas B. Nielsen

              http://www.lund-co.dk

              • 4. Re: [JS][CS3]how to get refrence for source file
                Mac_06 Level 2

                Sorry for my slack one

                 

                 

                It's great Thomas it's working like charm, You might not know that you have saved my tons of hours.

                 

                • 5. Re: [JS][CS3]how to get refrence for source file
                  maphiom Level 1

                  Hi guys,

                   

                  Sorry for reopening this old, closed topic, but I was just wondering...

                  This script is particularly useful for updating several *.indd files. But how would you go about updating *.indt files? I have a massive (50+) template folder where I would like to bring the new styles I created, but when I run the script, InDesign wants to save the files in *.indd form, asking me for a name for each file. Any ideas?

                   

                  Thanks for your time

                   

                  Matteo

                  • 6. Re: [JS][CS3]how to get refrence for source file
                    John Hawkinson Level 5

                    Well, this is really not a safe operation, so copy the whole folder first.

                     

                    But probably  (untested) you can change

                     

                     targetDoc.close(SaveOptions.YES);

                     

                    to

                     

                     targetDoc.close(SaveOptions.YES, theFile);
                    

                     

                    and of course you must have changed *.indd to *.indt.

                    • 7. Re: [JS][CS3]how to get refrence for source file
                      maphiom Level 1

                      It seems to work fine !

                      Thanks a lot, John