4 Replies Latest reply on Jul 20, 2015 5:49 AM by Johnwhite

    How to open instanceof folder

    Johnwhite Level 1

      Hi experts

       

      I want to open the indd files which in the instance of folder.

      How can I make it works.

      my script as below, could some tell me what's wrong with the script.

       

      Regard

      John

       

       

      #target indesign

             app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;

             var folder = Folder.selectDialog ("Select the root folder");  

             var myfiles = [];  

             getsubfolderfiles(folder);  

             for(var i =0;i<myfiles.length;i++)  

                              {  

                     var docs = app.open(myfiles[i]);  

                                          for (i = docs.length-1; i >= 0; i--) {

                                              var myTables = docs[i].stories.everyItem().tables.everyItem().getElements() 

                                                  for ( t = 0; t < myTables.length; t++ ){ 

                                                          myTables[t].cells.everyItem().texts.everyItem().fillColor = "Black"; 

                                                          myTables[t].cells.everyItem().fillColor = "None"; 

                                                          myTables[t].cells.everyItem().leftEdgeStrokeColor = "None"; 

                                                          myTables[t].cells.everyItem().rightEdgeStrokeColor = "None"; 

                                                          myTables[t].cells.everyItem().topEdgeStrokeColor = "None"; 

                                                          myTables[t].cells.everyItem().bottomEdgeStrokeColor = "None"; 

                                                          } 

                                              } 

                                     }    

                                

                                

                          function getsubfolderfiles(folder)  

                                    {  

                                        var filelist = folder.getFiles();  

                                        for(var i =0;i<filelist.length;i++)  

                                        {  

                                            if(filelist[i] instanceof Folder)  

                                            {  

                                                getsubfolderfiles (filelist[i]);  

                                            }  

                                            else if(filelist[i] instanceof File)  

                                            {  

                                                if(filelist[i].name.indexOf(".indd") > -1){  

                                                    myfiles.push(filelist[i]);  

                                                }  

                                            }  

                                        }  

                                    } 

       

       

                                         

                                   var docs = app.documents;

                                       for (var i = docs.length-1; i >= 0; i--) {

                                           if(docs[i].saved == false){

                                                 docs[i].close(SaveOptions.NO);

                                               }

                                           else if(docs[i].close(SaveOptions.YES));

                                          }

                                app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

                               

                                alert("Finish.")

        • 1. Re: How to open instanceof folder
          Peter Kahrel Adobe Community Professional & MVP

          In what way does your script not work?

          • 2. Re: How to open instanceof folder
            Johnwhite Level 1

            Hi Pkahrel

             

            I want make it open all the root folder’s indd file, then change cell properties.

            or no open files but change the root folder’s indd file’s cell properties.

             

            but script as above, do nothing.

             

            Thanks

            Regard

            John

            • 3. Re: How to open instanceof folder
              Ronald63 Level 4

              Hi,

               

              Your problem is here

                    for(var i =0;i<myfiles.length;i++){

                            var docs = app.open(myfiles[i]);

                            for (i = docs.length-1; i >= 0; i--) {

                              // code

                              }

                      }  

              Try this ...

              //#target indesign
              
              var folder = Folder.selectDialog ("Select the root folder");  
              var myfiles = [];  
              
              getsubfolderfiles(folder);
              
              app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
              
              for(var i =0;i<myfiles.length;i++){  
                  var doc = app.open(myfiles[i]);  
                      var myTables = doc.stories.everyItem().tables.everyItem().getElements() 
                      for ( t = 0; t < myTables.length; t++ ){ 
                      myTables[t].cells.everyItem().texts.everyItem().fillColor = "Black"; 
                      myTables[t].cells.everyItem().fillColor = "None"; 
                      myTables[t].cells.everyItem().leftEdgeStrokeColor = "None"; 
                      myTables[t].cells.everyItem().rightEdgeStrokeColor = "None"; 
                      myTables[t].cells.everyItem().topEdgeStrokeColor = "None"; 
                      myTables[t].cells.everyItem().bottomEdgeStrokeColor = "None"; 
                      } 
                  doc.close(SaveOptions.YES);
              }    
              
              app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
              alert("Finish.")                         
              
              function getsubfolderfiles(folder){  
                  var filelist = folder.getFiles();  
                  for(var i =0;i<filelist.length;i++){  
                      if(filelist[i] instanceof Folder){  
                        getsubfolderfiles (filelist[i]);  
                      }else if(filelist[i] instanceof File){  
                          if(filelist[i].name.indexOf(".indd") > -1){  
                              myfiles.push(filelist[i]);  
                          }  
                      }  
                  }  
              } 
              
              • 4. Re: How to open instanceof folder
                Johnwhite Level 1

                thank you Ronald

                thank you so much

                 

                regard

                John