11 Replies Latest reply on Oct 5, 2015 5:32 PM by dinomachino

    How can I batch a huge bunch of wmf to ai in multiple subfolders?

    hf@fscb.de Level 1

      Hi,

       

      I have a couple of thousand old cliparts in .wmf format that I have to convert to .ai.  What I need to do is simply open the .wmf, store it as .ai in exactly the same location.

       

      Actions didn´t work because the files are in mutliple folders and subfolders. "Actions" keeped saving all the ai-files in the same folder. Which is kinda weird since this doesn´t happen when using the same action in PS.

       

      Sure, there are some quality issues with converting wmf to ai - but for what we´re plannning the quality is sufficient.

       

      CarlosCantos script at http://forums.adobe.com/message/5378444#5378444  looked like the thing to do. Loaded it in apple script,  patched the lines to open .wmf  and saved it in the Illustrator script folder, but all I got was a bunch of error messages, so I´m pretty clueless :-/ guess I´m not a script guy...

       

      Any help is greatly appreciated

       

      HF

        • 1. Re: How can I batch a huge bunch of wmf to ai in multiple subfolders?
          Larry G. Schneider Adobe Community Professional & MVP

          It's likely it was an ExtendScript (the Adobe version of Java). Just looked and I'm right.

          From Applications/Utilities/Adobe Utilities folder open the ExtendScript application, do a File>New and paste the copied text. Save with a .jsx file extension. Place it in Applications/Adobe Illustrator CSX/Presets/en_US/Scripts and restart AI.

           

          // script.name = makeAiFilesPDFcompatible.jsx;

          // script.description = opens and resaves Ai files with PDF compatibility checked (Folder Batch);

          // script.requirements = none

          // script.parent = CarlosCanto // 06/4/2013;

          // script.elegant = false;

          // script.forumPost = http://forums.adobe.com/thread/1224874?tstart=0

           

           

          var folder = Folder.selectDialog("Select Source Folder..."); // select folder

           

           

          if (folder==null) {

                              alert("Good Bye");

          }

           

           

          else {

              var files = find_files (folder, ['.wmf']);

                    var fileCount = files.length; // count them

           

           

                    if (fileCount>0) {

                              for (i=0; i<fileCount; i++) {

                      var idoc = app.open(files[i]);

                      var saveOpts = new IllustratorSaveOptions();

                      saveOpts.pdfCompatible = true;

                      idoc.saveAs( files[i], saveOpts );

                      idoc.close();

                              }

                  alert(fileCount + ' file(s) processed');

                    }

                    else {

                              alert("There are no Illustrator files in this folder.");

                    }

          }

           

          // recurse subfolders - Peter Kharel

          function find_files (dir, mask_array){

              var arr = [];

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

                  arr = arr.concat (find_files_sub (dir, [], mask_array[i].toUpperCase()));

              }

              return arr;

          }

           

          function find_files_sub (dir, array, mask){

              var f = Folder (dir).getFiles ( '*.*' );

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

                  if (f[i] instanceof Folder){

                      find_files_sub (f[i], array, mask);

                  } else if (f[i].name.substr (-mask.length).toUpperCase() == mask){

                      array.push (f[i]);

                  }

              }

              return array;

          }

           

          I just tried this with some .emf files (since I didn't have any .wmf handy) and it worked fine.

          • 2. Re: How can I batch a huge bunch of wmf to ai in multiple subfolders?
            hf@fscb.de Level 1

            Hi Larry,

             

            1000 kudos! :-) Works like a charm. Many many thanks! You realy helped me a lot!

            • 3. Re: How can I batch a huge bunch of wmf to ai in multiple subfolders?
              hf@fscb.de Level 1

              Hi Larry,

               

              is there any way to include "crop to artworks bound" In this script?

               

              I fiddled around with ArtClippingOption.OUTPUTARTBOUNDS but somehow I don´t get how to do it right...

               

              Thanks in advance :-)

               

              HF

              • 4. Re: How can I batch a huge bunch of wmf to ai in multiple subfolders?
                CarlosCanto Adobe Community Professional & MVP

                this script only has options as if you do SaveAs... in the user interface, artClipping is an ExportOptionsFlash only.

                1 person found this helpful
                • 5. Re: How can I batch a huge bunch of wmf to ai in multiple subfolders?
                  Larry G. Schneider Adobe Community Professional & MVP

                  But if the OP is using CS6 or CC he could use an action to use the menu item Object>Artboards>Fit to Artwork Bounds.

                  • 6. Re: How can I batch a huge bunch of wmf to ai in multiple subfolders?
                    CarlosCanto Adobe Community Professional & MVP

                    correct, I was trying to say that "fit to artwork bounds" is not an option of the IllustratorSaveOptions() object, regardless of Ai version one could resize the artboard to fit the art, before saving.

                    1 person found this helpful
                    • 7. Re: How can I batch a huge bunch of wmf to ai in multiple subfolders?
                      hf@fscb.de Level 1

                      I`m running OSX 10.9 and CS5. So I guess that means I can´t include "clip to artwork bounds" in the script? Strange I was pretty sure this is possible. But I don´t know s.... about scripts.

                       

                      Thanks a million anyway, you guys realy helped me

                       

                      HF

                      • 8. Re: How can I batch a huge bunch of wmf to ai in multiple subfolders?
                        Larry G. Schneider Adobe Community Professional & MVP

                        You can by setting up an Action in AI and then using the doScript call to perform that action (available in CS6 and above in ExtendScript and in earlier versions in AppleScript and VisualBasic)

                        1 person found this helpful
                        • 9. Re: How can I batch a huge bunch of wmf to ai in multiple subfolders?
                          hf@fscb.de Level 1

                          Ah Ok.

                           

                          So out of curiosity I created a new actionset called "Crop" and a new action called  "CropToArt". Next inserted the line

                           

                          var doScript (action: CropToArt, from: Crop, dialogs: bool=false);

                           

                          at this point (marked fat) in the script. Didn´t work though. I deleted "var", toggled bool to false and true = zippo.  Is it because I´m running CS5? Or do I have to create a Javascript (how do I do that...?)

                           

                          else {

                              var files = find_files (folder, ['.wmf']);

                                    var fileCount = files.length; // count them

                           

                           

                                    if (fileCount>0) {

                                              for (i=0; i<fileCount; i++) {

                                      var idoc = app.open(files[i]);

                                       var doScript (action: CropToArt, from: Crop, dialogs: bool=false);

                                      var saveOpts = new IllustratorSaveOptions();

                                      saveOpts.pdfCompatible = true;

                                      idoc.saveAs( files[i], saveOpts );

                                      idoc.close();

                                              }

                                  alert(fileCount + ' file(s) processed');

                                    }

                                    else {

                                              alert("There are no Illustrator files in this folder.");

                                    }

                          }

                           

                          Thanks guys

                           

                          HF

                          • 10. Re: How can I batch a huge bunch of wmf to ai in multiple subfolders?
                            CarlosCanto Adobe Community Professional & MVP

                            yes, doScript was introduced in CS6...check artboardRect property in the documentation, that will let you change the artboard bounds to your needs.

                            • 11. Re: How can I batch a huge bunch of wmf to ai in multiple subfolders?
                              dinomachino Level 1

                              So, this is a super old thread, but it came up in google almost at the top for what I was looking for, and it put me on the right track immediately, so I'm going to post the script I cobbled together that got all this done.

                               

                              I have like... 10,000 wmf files? Somewhere in that range. These suck and you can't preview them in finder, so no one thinks to go through them (opening 1 by one), so this time when I was charged with finding some clipart, I decided to see if I could find a way to convert them all to .ai so finder can give me neat little previews.

                               

                              Larry's script worked perfectly, but then, like OP, I was left unsatisfied by the artboard's size. Carlos knew exactly what he was wanting and artboardRect was definitely the way to go, but he didn't spell out how to use it. So I went to hunting again.

                               

                              Knowing no extendscript and my js skills limited to query, I somehow managed to cobble together a working script by adding in the 1 and only answer from this stack overflow post. And so here it is. Enjoy! If it breaks, I honestly can't help...

                               

                              (additions in bold, comments from stack overflow user)

                               

                              // script.name = makeAiFilesPDFcompatible.jsx;

                              // script.description = opens and resaves Ai files with PDF compatibility checked (Folder Batch);

                              // script.requirements = none

                              // script.parent = CarlosCanto // 06/4/2013;

                              // script.elegant = false;

                              // script.forumPost = http://forums.adobe.com/thread/1224874?tstart=0

                               

                               

                              var folder = Folder.selectDialog("Select Source Folder..."); // select folder

                               

                               

                              if (folder==null) {

                                                  alert("Good Bye");

                              }

                               

                               

                              else {

                                  var files = find_files (folder, ['.wmf']);

                                        var fileCount = files.length; // count them

                               

                               

                                        if (fileCount>0) {

                                                  for (i=0; i<fileCount; i++) {

                                          var idoc = app.open(files[i]);

                               

                                          var doc = app.activeDocument; 

                               

                                          // Select all objects on the artboard

                                          doc.selectObjectsOnActiveArtboard();

                               

                                          // Get the size of the art

                                          doc.artboards[0].artboardRect = [0, doc.selection[0].height, doc.selection[0].width, 0];

                               

                                          // Get the active Artboard index

                                          var activeAB = doc.artboards[doc.artboards.getActiveArtboardIndex()];

                                          var artboardBottom = activeAB.artboardRect[3];

                                          activeAB.position = (doc.selection[0].position[0], doc.selection[0].position[1]); 


                                          // Get the active Artboard index

                                          var activeAB = doc.artboards[doc.artboards.getActiveArtboardIndex()];

                               

                                          // Get the Height of the Artboard

                                          var artboardBottom = activeAB.artboardRect[3];

                               

                                          // The page item you want to move. Reference it how you will. This just

                                          // obviously grabs the first pageItem in the document.

                                          var myPageItem = doc.pageItems[0];

                               

                                          // Here is where the magic happens. Set the poition of the item.

                                          // [0,0] would be at the top left, so we have to compensate for the artboard

                                          // height. We add myPageItem's height for offset, or we'd end up BELOW

                                          // the artboard.

                                          myPageItem.position = [0, artboardBottom + myPageItem.height];

                                         

                                          var saveOpts = new IllustratorSaveOptions();

                                          saveOpts.pdfCompatible = true;

                                          idoc.saveAs( files[i], saveOpts );

                                          idoc.close();

                                                  }

                                      alert(fileCount + ' file(s) processed');

                                        }

                                        else {

                                                  alert("There are no Illustrator files in this folder.");

                                        }

                              }

                               

                              // recurse subfolders - Peter Kharel

                              function find_files (dir, mask_array){

                                  var arr = [];

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

                                      arr = arr.concat (find_files_sub (dir, [], mask_array[i].toUpperCase()));

                                  }

                                  return arr;

                              }

                               

                              function find_files_sub (dir, array, mask){

                                  var f = Folder (dir).getFiles ( '*.*' );

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

                                      if (f[i] instanceof Folder){

                                          find_files_sub (f[i], array, mask);

                                      } else if (f[i].name.substr (-mask.length).toUpperCase() == mask){

                                          array.push (f[i]);

                                      }

                                  }

                                  return array;

                              }