4 Replies Latest reply on May 29, 2015 12:47 AM by BEGINNER_X

    Open multiple Files as per Trim Size

    BEGINNER_X Level 3

      Hi All,

       

      Please help for my request, this should be very urgent.

       

      Request:

      1. User Select Folder

      2. Open all Files

      3. Collect Trim Size (document width) + Document Name

      4. Sort the Document Width (lower value to higher value)

      5. Again open the Files as per minimum document width

       

      Trying Script:

       

      #target Indesign
      
      var  myFolder = Folder.selectDialog("Select the Folder contains Indesign Files");
      var myFiles = myFolder.getFiles("*.indd");
      myWidthArray = new Array();
      
      for(i=0; i<myFiles.length; i++)
      {
          app.open(myFiles[i]);
          app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;  
          
          var myDocument_Width = Math.round(app.activeDocument.documentPreferences.pageWidth);
          var myReq = myDocument_Width + app.activeDocument.name;
          
          myWidthArray.push(myReq)
          
          app.activeDocument.close();
          }
      
      alert(myWidthArray)
      var myPoints = myWidthArray;
      myPoints.sort(function(a, b){return a-b});
      alert("myPoints: " + myPoints)
      
      
      //here need help
      for(k=0; k<myPoints.length; k++)
      {
          app.open(myPoints[k].document.name)
          }
      

       

       

      Thanks

      Siraj

        • 1. Re: Open multiple Files as per Trim Size
          Chinnadk Level 4

          Hi Siraj,

           

          Is this you need?

           

          #target Indesign 

           

          var  myFolder = Folder.selectDialog("Select the Folder contains Indesign Files"); 

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

          myWidthArray = new Array(); 

           

          for(i=0; i<myFiles.length; i++) 

              app.open(myFiles[i]); 

              app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;   

               

              var myDocument_Width = Math.round(app.activeDocument.documentPreferences.pageWidth); 

              var myReq = myDocument_Width + app.activeDocument.name; 

              myWidthArray[i] = [];

              myWidthArray[i].push(myDocument_Width)

              myWidthArray[i].push(app.activeDocument.name)

              app.activeDocument.close(); 

              } 

          myWidthArray.sort(); 

           

          //here need help 

          for(k=0; k<myWidthArray.length; k++) 

              app.open(File(myFolder + "/"+ myWidthArray[k][1]));

              }

           

          Regards,

          Chinna

          • 2. Re: Open multiple Files as per Trim Size
            BEGINNER_X Level 3

            Hi Chinna,

             

            Thank you for your immediate response...

            Could you please see the alert, this should not sort correctly.

             

            For testing purpose, I created 4 files and test it.

            I alert in the provided script:

             

            var myOutput = myWidthArray.sort();

            alert(myOutput)

             

            Please look into this.

             

            Screen Shot 2015-05-29 at 12.56.41 PM.png

             

            But my need is

            40,small_tsserd.indd, 210,bbb.indd, 400,abcd.indd, 1200,large_yyyde.indd

             

            Again thanks for your support.

            • 3. Re: Open multiple Files as per Trim Size
              milligramme Level 3

              Hi try this code

               

              #target Indesign 
              
              var  myFolder = Folder.selectDialog("Select the Folder contains Indesign Files"); 
              var myFiles = myFolder.getFiles("*.indd"); 
              var myWidthArray = new Array(); 
              
              for(var i=0; i<myFiles.length; i++) 
              { 
                  app.open(myFiles[i]); 
                  app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;   
                   
                  var myDocument_Width = Math.round(app.activeDocument.documentPreferences.pageWidth);
                  // store the values as object
                  var myReq = {w:myDocument_Width, d:app.activeDocument.name};
                 
                  myWidthArray.push(myReq);
              
                  app.activeDocument.close();  
                  } 
              
              alert(myWidthArray.toSource());
              var myPoints = myWidthArray; 
              // sort by width
              myPoints.sort(function(a, b){return a.w * 1-b.w * 1});
              alert("myPoints: " + myPoints.toSource());
              
              
              //here need help 
              for(var k=0; k<myPoints.length; k++)
              {
                  // reopen documents in selected folder
                  // open with fullpath
                  app.open(new File(myFolder + '/' + myPoints[k].d));
                  }
              
              
                 
              
              

               

              thank you

              • 4. Re: Open multiple Files as per Trim Size
                BEGINNER_X Level 3

                Hi Chinna/Milligramme,

                 

                Excellent support in your busy schedule.

                 

                Milli: Your coding is working fine in my end.

                 

                Again Thanks a lot guys!!!!