6 Replies Latest reply on Jun 5, 2015 7:12 AM by BEGINNER_X

    Move Master Page to Destination_Doc and Applied Master for Respective Page

    BEGINNER_X Level 3

      Hi All,

       

      My Current Request:

      1. i.e., Folder files having around 20 files

       

      2. All files(20 files) having same master spreads ("A-Master")

       

      3. Current Script, move all files in the "Destination_Doc", with the same master spreads ("A-Master")

       

      4. But my Requirement, all are rename in different master spreads.("A-Master", "B-Master", "C-Master" etc....)

       

       

      Please refer screenshot.. (Look at both screenshot differences)

       

      Below Script COding Output:

       

      Screen Shot 2015-06-02 at 10.28.20 AM.png

       

      Needed Output:

       

      Screen Shot 2015-06-02 at 10.27.50 AM.png

       

      Final coding:

      #target indesign
      var destination_doc = app.activeDocument;
      var sourceFolder = Folder.selectDialog("Select a folder with source InDesign files.");
      
      var fileList = sourceFolder.getFiles(/\.indd$/i);
      fileList.sort();
      
      // run through each file
      for ( var i = 0; i < fileList.length; i++ ) {
          var source_file = fileList[i];
              app.open(source_file);
              var source_doc = app.documents.item(source_file.name);
              var sourcePages = source_doc.spreads.item(0);
              sourcePages.duplicate(LocationOptions.AFTER, source_doc.spreads.item(0));
              sourcePages.move(LocationOptions.AFTER, destination_doc.spreads.item(-1));
              app.activeDocument.close(SaveOptions.NO);
      }
      
      
      
      

       

       

      Thanks in Advance

      Siraj

        • 1. Re: Move Master Page to Destination_Doc and Applied Master for Respective Page
          BEGINNER_X Level 3

          Hi All,

           

          Is there any possibilites to change Numbers into Alphabets?????

           

          Kindly look at line 13 in coding.

           

          var destination_doc = app.activeDocument;
          
          var sourceFolder = Folder.selectDialog("Select a folder with source InDesign files.");
          
          var fileList = sourceFolder.getFiles(/\.indd$/i);
          fileList.sort();
          
          // run through each file
          for ( var i = 0; i < fileList.length; i++ ) {
              var source_file = fileList[i];
                  app.open(source_file);
                
                  app.activeDocument.masterSpreads.item("A-Master").namePrefix = String(i);   //this is the code
          
                  var source_doc = app.documents.item(source_file.name);
                  var sourcePages = source_doc.spreads.item(0);
                  sourcePages.duplicate(LocationOptions.AFTER, source_doc.spreads.item(0));
                  sourcePages.move(LocationOptions.AFTER, destination_doc.spreads.item(-1));
                  app.activeDocument.close(SaveOptions.NO);
          }
          
          
          

           

           

          Screenshot is like as below:

           

          Screen Shot 2015-06-03 at 9.03.45 AM.png

          • 2. Re: Move Master Page to Destination_Doc and Applied Master for Respective Page
            Sajeev Sridharan Level 4

            Try this,

             

            Change line 13 like below:

             

            app.activeDocument.masterSpreads.item("A-Master").namePrefix = String.fromCharCode(66 + i);   //this is the code

            • 3. Re: Move Master Page to Destination_Doc and Applied Master for Respective Page
              BEGINNER_X Level 3

              Hi Sajeev(vandy)

               

              After long time.....

               

              Your coding is working like a charm...

               

              A-Z handled rename for only 26 files.

               

              But for my request is handling more than 50 files...

               

              Any possibilities, after complete A-Z, rename into "AA-Master", "BB-Master", CC etc.. (or any other better way)

               

              or

               

              A1-Master, B2-Master etc...

               

              Thanks

              • 4. Re: Move Master Page to Destination_Doc and Applied Master for Respective Page
                Sajeev Sridharan Level 4

                Try this,

                 

                var destination_doc = app.activeDocument;  
                var sourceFolder = Folder.selectDialog("Select a folder with source InDesign files.");  
                var fileList = sourceFolder.getFiles(/\.indd$/i);  
                var j=0, k=1;
                fileList.sort();  
                // run through each file  
                for ( var i = 0; i < fileList.length; i++ ) {  
                    var source_file = fileList[i];  
                    app.open(source_file);  
                    if(i<25){app.activeDocument.masterSpreads.item("A-Master").namePrefix = String.fromCharCode(66 + i);}
                    else{j++; app.activeDocument.masterSpreads.item("A-Master").namePrefix = String.fromCharCode(64+j) + String(k);if(j==26){j=0; k++;}}
                    var source_doc = app.documents.item(source_file.name);  
                    var sourcePages = source_doc.spreads.item(0);  
                    sourcePages.duplicate(LocationOptions.AFTER, source_doc.spreads.item(0));  
                    sourcePages.move(LocationOptions.AFTER, destination_doc.spreads.item(-1));  
                    app.activeDocument.close(SaveOptions.NO);  
                }  
                
                • 5. Re: Move Master Page to Destination_Doc and Applied Master for Respective Page
                  BEGINNER_X Level 3

                  Hi Sajeev,

                   

                  Sorry for the delayed response ...

                   

                  Finalize Request is, after complete A-Z, rename into "AA-Master", "BB-Master", CC etc.. (after that AAA, BBB etc...)

                   

                  Using Your code, I modified as below:

                  (Is there any better coding??) (so handle any number of files)


                  var x=0, y=1;  
                  var z=0;
                  if(k<26){
                      app.activeDocument.masterSpreads.item("A-Master").namePrefix = String.fromCharCode(65 + k);
                      }  
                  else if(k>25 && k<52){
                      x++; 
                         app.activeDocument.masterSpreads.item("A-Master").namePrefix = String.fromCharCode(64+x) + String.fromCharCode(64+x);
                      }  
                  else if(k>51 && k<78){
                  z++; 
                     app.activeDocument.masterSpreads.item("A-Master").namePrefix = String.fromCharCode(64+z) + String.fromCharCode(64+z) + String.fromCharCode(64+z);
                  }  
                  //etc..
                  


                  Thanks in Advance