Skip navigation
Currently Being Moderated

Script to Perform Live Trace then in Illustrator Run Action... Please Help

Sep 2, 2010 9:54 AM

Hello Everyone, I am brand new to scripting and need some help... I would like to create an inter-application javascript (.jsx) file that will perform the following steps in sequence:

 

1) Target Bridge CS3 and:


a) Automatically select files (thumbnails) (the names of, and path to these files never change so scripting them is no problem). Path & Files are: C:\files\1.psd, C:\files\2.psd and C:\files\3.psd.

 

b) Run Tools > Illustrator > Live Trace [Live Trace Dialogue Box Settings (Tracing Preset: Color 16, Save & Close Results (checked), Document Profile: "Basic RGB", Width: "576", Height: "720", Units: Pixels, Destination: "C:\files\, File Naming: Document Name + .ai)].

After Live Trace finishes, C:\files\1.ai, C:\files\2.ai and C:\files\3.ai are created.

 

and then....

 

2) Target Illustrator CS3 and:

Run my Illustrator precreated Action: "Add Border". This action adds a precreated border to the files. The action is coded with the paths and file names of the .ai files as well as saving instructions.

----------------------------------------------

To summarize:

1) In Bridge, run Live Trace on precreated .psd files

2) In Illustrator run an action on the files that were live traced

 

That's it. It seems straight forward when I write it out but trying to figure out how to script it is boggling my mind.

 

Thank you for your help!

 
Replies
  • Currently Being Moderated
    Sep 2, 2010 2:28 PM   in reply to 1000fx4u

    In what way does scripting Illustrator NOT support this? The menu item of which you are talking is extendscript all it does is pass the thumbnail file objects from Bridge to Illustrator to work with. You could batch a list of file objects just the same direct in Illustrator…

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 3, 2010 2:19 AM   in reply to 1000fx4u

    Hello, the 'Illustrator Tools' Live Trace Utility that you are wanting to 'run' is a script that was created by someone at Adobe using the ESTK. You can't access the clicking of checkboxes or entering of values into the the supplied scripts dialog from another script. The work flow in the stages that you originally posted would not be doable as a single script process because of this. What you actually require is a script that uses your 'values' and 'presets' then processes the files. There would be no need for any dialog and depending on how you wanted the process to run then there is no need for any app interaction. It would be easier to script it to run straight out of Illustrators scripts presets folder…

     

    Illustrator can't play out actions from ExtendScript either. So what your action does later to add the borders would need to be done via script too. Actions in script can only be done when using VB or AppleScript.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 4, 2010 12:49 AM   in reply to 1000fx4u

    I have posted in that forum once before about scripting 'Live Trace' meantime I will take a look at what I think you are wanting… I will need to get back to you about the borders thing…

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 4, 2010 2:16 AM   in reply to Muppet Mark-QAl63s

    OK, I've had a little time this morning to take a look at this for you and here is what I have… It is working just fine for me but you will be required to make 1 or 2 little typo changes yourself…

     

    In line 7… You need to change the folders path string…

     

    var traceFolder = new Folder ('~/Desktop/Live Trace/');

     

    In line 71… You may want to change the save options to 13 for CS3 compatibility…

     

    compatibility = Compatibility.ILLUSTRATOR13;

     

     

    #target illustrator
     
    while (app.documents.length) {
      app.activeDocument.close(SaveOptions.PROMPTTOSAVECHANGES);
    }
     
    var traceFolder = new Folder ('~/Desktop/Live Trace/');
     
    var fileList = traceFolder.getFiles(/\.psd$/i);
     
    if (fileList.length > 0) {
         main(fileList);
    } else {
         alert('This Folder contained NO Photoshop PSD files!');
         return;
    }     
     
    function main(fileObjs) {
     
         with (app) {
         
              var orginalUIL = userInteractionLevel;
              
              userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
              
              for (var i = 0; i < fileObjs.length; i++) {
              
                   if (fileList[i] instanceof File) {
                   
                        var fileName = fileList[i].name.slice(0, -4);
                        
                        var docRef = documents.add(DocumentColorSpace.RGB, 576, 720);
                        
                        with (docRef) {
                        
                             var thisPlace = placedItems.add();
                             
                             thisPlace.file = fileObjs[i];
                             
                             var thisImage = placedItems[0].trace();
                             
                             redraw();
                                                           
                             thisImage.tracing.tracingOptions.loadFromPreset('Color 16');
     
                             thisImage.tracing.expandTracing();
                             
                             redraw();
                             
                             /*///////////////////////////////////
                             We need to add your border here…
                             *////////////////////////////////////
                             
                             var aiOptions = saveAsAiFile();
                             
                             newFilePath = new File(traceFolder.fsName.toString() + '/' + fileName + '.ai');
                             
                             saveAs(newFilePath, aiOptions);
                             
                             close(SaveOptions.DONOTSAVECHANGES);                         
                        }
                   }
              }
              userInteractionLevel = orginalUIL;
         }
    }
     
    function saveAsAiFile() {
         var aiOptions = new IllustratorSaveOptions();
         with (aiOptions) {
              compatibility = Compatibility.ILLUSTRATOR12;
              compressed = true;
              embedICCProfile = true;
              embedLinkedFiles = true;
              flattenOutput = OutputFlattening.PRESERVEAPPEARANCE;
              fontSubsetThreshold = 0;
              overprint = PDFOverprint.PRESERVEPDFOVERPRINT;
              pdfCompatible = true
         }
         return aiOptions;
    }
    

     

     

    As is, the script is looking for all files in the target folder that have the '.psd' file extension…

     

    If this works for you then get back and I will see what can be done about the border thing…

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 4, 2010 9:38 AM   in reply to 1000fx4u

    I will go check that error meantime try this… The Photoshop export looks OK to me but I have no idea about SVG files as I don't use them… This should be getting closer… You will need to make the same 2 typo changes…

     

    #target illustrator
     
    while (app.documents.length) {
      app.activeDocument.close(SaveOptions.PROMPTTOSAVECHANGES);
    }
     
    var traceFolder = new Folder ('~/Desktop/Live Trace/');
     
    var fileList = traceFolder.getFiles(/\.psd$/i);
     
    if (fileList.length > 0) {
     
         var svg = new Folder(traceFolder.fsName+'/SVG Files');
         if (!svg.exists) svg.create(); 
     
         var psd = new Folder(traceFolder.fsName+'/PSD Files');
         if (!psd.exists) psd.create();
     
         var ai = new Folder(traceFolder.fsName+'/AI Files');
         if (!ai.exists) ai.create();
         
         main(fileList);
         
    } else {
     
         alert('This Folder contained NO Photoshop PSD files!');
         
    }     
     
    function main(fileObjs) {
     
         with (app) {
         
              var orginalUIL = userInteractionLevel;
              
              userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
              
              for (var i = 0; i < fileObjs.length; i++) {
              
                   if (fileList[i] instanceof File) {
                   
                        var fileName = fileList[i].name.slice(0, -4);
                        
                        var docRef = documents.add(DocumentColorSpace.RGB, 576, 720);
                        
                        with (docRef) {
                        
                             var thisPlace = placedItems.add();
                             
                             thisPlace.file = fileObjs[i];
                             
                             var thisImage = placedItems[0].trace();
                             
                             redraw();
                                                           
                             thisImage.tracing.tracingOptions.loadFromPreset('Color 16');
     
                             thisImage.tracing.expandTracing();
                             
                             redraw();
                             
                             var svgOptions = exportAsSVGFile();
                             
                             svgFilePath = new File(svg.fsName + '/' + fileName + '.svg');
                             
                             exportFile(svgFilePath, ExportType.SVG, svgOptions);
                             
                             var psdOptions = exportAsPSDFile();
                             
                             psdFilePath = new File(psd.fsName + '/' + fileName + '.psd');
                             
                             exportFile(psdFilePath, ExportType.PHOTOSHOP, psdOptions);
                             
                             var aiOptions = saveAsAiFile();
                             
                             aiFilePath = new File(ai.fsName + '/' + fileName + '.ai');
                             
                             saveAs(aiFilePath, aiOptions);
                             
                             close(SaveOptions.DONOTSAVECHANGES);                         
                        }
                   }
              }
              userInteractionLevel = orginalUIL;
         }
    }
     
    function exportAsSVGFile() {
         var svgOptions = new ExportOptionsSVG();
         with (svgOptions) {
                compressed = true;
              coordinatePrecision = 3;
              //cssProperties = SVGCSSPropertyLocation.ENTITLES;
              documentEncoding = SVGDocumentEncoding.UTF16
              //DTD = SVGDTDVersionSVG1_0;
              embedRasterImages = true;
              fontSubsetting = SVGFontSubsetting.ALLGLYPHS;
              fontType = SVGFontType.CEFFONT;
              includeFileInfo = false;
              includeVariablesAndDatasets = false;
              optimizeForSVGViewer = true;
              preserveEditability = true;
              slices = true;
              sVGAutoKerning = true;
              sVGTextOnPath = true;
         }
         return svgOptions;
    }
     
    function exportAsPSDFile() {
         var psdOptions = new ExportOptionsPhotoshop();
         with (psdOptions) {
              antiAliasing = true;
              compatibility = PhotoshopCompatibility.PHOTOSHOP8;
              editableText = true;
              embedICCProfile = true;
              maximumEditability = true;
              resolution = 150;
              warnings = true;
              writeLayers = true;
         }
         return psdOptions;
    }
     
    function saveAsAiFile() {
         var aiOptions = new IllustratorSaveOptions();
         with (aiOptions) {
              compatibility = Compatibility.ILLUSTRATOR12;
              compressed = true;
              embedICCProfile = true;
              embedLinkedFiles = true;
              flattenOutput = OutputFlattening.PRESERVEAPPEARANCE;
              fontSubsetThreshold = 0;
              overprint = PDFOverprint.PRESERVEPDFOVERPRINT;
              pdfCompatible = true
         }
         return aiOptions;
    }
    

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 15, 2012 5:15 PM   in reply to Muppet Mark-QAl63s

    Hello Muppet Mark,

     

    I was searching for a solution for this for long time and I wondering if I could use your help too.

    I'm also new to scripting and I think I understand most of what you've done, but for sure not enough to make changes to fit it for what I want to do.

    I have a folder with 22 subfolders, each containing 360 PNG's.

    I want to batch trace and expand PNGs into one Illustrator file (one for every subfolder) by a trace preset that I saved in illustrator.

    And If there is a way to add to it a path/simplify action with Straight Lines and 0 Angle Threshold it would be incredible.

     

    I would appreciate it greatly if you could help.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 16, 2012 1:57 AM   in reply to Z_lot

    Hello, It's been some time since I posted that script… I had a quick look at what you want and my thoughts are…

     

    A script would help you with… Select a folder, process files of sub directories to an AI file for each, Live Trace the placed content & save the file…

     

    Middle grey area… 360 PNG's… Thats a lot to put in the one AI file you could NOT have an artboard for each… ( 100 max ) are you going to layer them up for something else AE or Flash ( some rotation I guess )

     

    A script would NOT be able to do… Script can not call this plug-ins functions ( you would need to write all the processing methods in script ) Serious heavy bézier math and way over my head…

     

    You may be able to run an action to do the last request but that would have to been done after the script has gone about its business…

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 16, 2012 3:02 AM   in reply to Muppet Mark

    Hello Muppet Mark,

     

    Thank you for the quick response!

     

    Well, I've been using the Bridge Illustrator Trace tool to mass trace these PNG's into one layered AI. (Like you said, 360 rotation of a rendered C4D )

    Its working but it gets really slow and inefficient as it reaches the hundreds.

     

    Now I'm working with thousands of PNG's in one file ,so dividing it to sub directories , something that the Bridge script doesn't do, I think will make it much faster.

     

    I was thinking if there is a way to create a loop that expands the trace before it imports the next PNG file, maybe it will make it less heavy.

     

    As for the simplify, I can do it manually, it's the really the easier part.

     

    And if there is a way to take all the saved AI files and combine them to one AI divided to artboards it will make even better.

     

    Thank you again!

     

     


     
    |
    Mark as:
  • Currently Being Moderated
    Apr 16, 2012 3:41 AM   in reply to Z_lot

    A better AI placer n tracer has been on my todo list for some time… I would certainly want to be expanding the trace result on each itteration… This could be done with script from either Bridge or straight out of AI…

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 16, 2012 4:32 AM   in reply to Muppet Mark

    when you said "Script can not call this plug-ins functions ( you would need to write all the processing methods in script ) Serious heavy bézier math and way over my head…" you were referring to the simplify or the expand command?

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 16, 2012 4:51 AM   in reply to Z_lot

    Expanding the live trace is NO problem… That would be some math… Phew? I did mean the path cleaning function…

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 16, 2012 5:01 AM   in reply to Muppet Mark

    so what do I need to do to make it work?

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 16, 2012 6:05 AM   in reply to Z_lot

    I will take a look but I do have a day job and Im in the middle of that just now…

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 16, 2012 6:13 AM   in reply to Muppet Mark

    Well this is where I got so far.

     

    I changed the script that you wrote to import to single Ai file and it's working!

    now I need to add the sub directories division

     

    #target illustrator
     
    while (app.documents.length) {
      app.activeDocument.close(SaveOptions.PROMPTTOSAVECHANGES);
    }
     
    var traceFolder = new Folder ('~/Desktop/Live Trace/');
     
    var fileList = traceFolder.getFiles(/\.png$/i);
     
    if (fileList.length > 0) {
     
         var ai = new Folder(traceFolder.fsName+'/AI Files');
         if (!ai.exists) ai.create();
         
         main(fileList);
         
    } else {
     
         alert('This Folder contained NO Photoshop PNG files!');
         
    }     
     
    function main(fileObjs) {
     
         with (app) {
         
              var orginalUIL = userInteractionLevel;
              
              userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
              
              var fileName = fileList[0].name.slice(0, -4);          
     
     
              var docRef = documents.add(DocumentColorSpace.RGB, 576, 720);
              
              for (var i = 0; i < fileObjs.length; i++) {
              
                   if (fileList[i] instanceof File) {
                   
                        
                        
                        with (docRef) {
                        
                             var thisPlace = placedItems.add();
                             
                             thisPlace.file = fileObjs[i];
                             
                             var thisImage = placedItems[0].trace();
                             
                             redraw();
                                                           
                             thisImage.tracing.tracingOptions.loadFromPreset('Wave');
     
                             thisImage.tracing.expandTracing();
                             
                             redraw();
                        }
                   }
              }
              with (docRef) {
                             var aiOptions = saveAsAiFile();
                             
                             aiFilePath = new File(ai.fsName + '/' + fileName + '.ai');
                             
                             saveAs(aiFilePath, aiOptions);
                             
                             close(SaveOptions.DONOTSAVECHANGES);             
         }
         }
    } 
    function saveAsAiFile() {
         var aiOptions = new IllustratorSaveOptions();
         with (aiOptions) {
              compatibility = Compatibility.ILLUSTRATOR12;
              compressed = true;
              embedICCProfile = true;
              embedLinkedFiles = true;
              flattenOutput = OutputFlattening.PRESERVEAPPEARANCE;
              fontSubsetThreshold = 0;
              overprint = PDFOverprint.PRESERVEPDFOVERPRINT;
              pdfCompatible = true
         }
         return aiOptions;
    }
     
    
     
    |
    Mark as:
  • Currently Being Moderated
    Apr 16, 2012 6:18 AM   in reply to Muppet Mark

    I'll try getting as far as I can by myself. sorry if I was to pushy.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 16, 2012 10:50 AM   in reply to Z_lot

    Hello Im at home now thats much better… A quick blast of the old calculator and 7,920 live traces in the one AI file… Im NOT supprised you experience a slow down…? Thats a lot of tracing of cause I have no idea of the complexity of the actual trace result… It's been some time since that script was done and I would prefer to re-hash it even though it worked… Do you mind if its done as an AI script like above… Making it a Bridge script is doable but requires additional time… I have to bridgetalk stuff and its not so easy…

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 16, 2012 11:34 AM   in reply to Muppet Mark

    I tried figuring out how to make a loop over the sub directories, but without any success .

    mean while I add few things, I'm sure there is a better way to do it

     

    1. a prompt to select folder (if there is a way to select multiple folders and/or files it might make it even more flexible)

    2. each PNG is imported to a new layer with the name of the PNG. (but when i run it on my PC I get the space as in the file name as %20)

    3. a Beep at the end of the script that lets you know it is finished. (I'm working on a different computer so it's very useful)

    4. Import to single Ai file as I mentioned before.

     

    and another thing, I'm using the Adobe ExtendScript Toolkit, and I couldn't find any way to auto format the script so it looks very messy, can you recommend me of another program or you know a way to do it?

     

    AI Script will be perfect! THANK YOU so much for your help!

     


    #target illustrator
     
    while (app.documents.length) {
      app.activeDocument.close(SaveOptions.PROMPTTOSAVECHANGES);
    }
     
    var traceFolder =  Folder.selectDialog( 'Select folder for PNG files.', '~' );
    if (traceFolder != null) {
    var fileList = traceFolder.getFiles(/\.png$/i);
     
     
    if (fileList.length > 0) {
     
         var ai = new Folder(traceFolder.fsName+'/AI Files');
         if (!ai.exists) ai.create();
         
         main(fileList);
         
    } else {
     
         alert('This Folder contained NO PNG files!');
         
    }     
     
    function main(fileObjs) {
     
         with (app) {
         
              var orginalUIL = userInteractionLevel;
              
              userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
              
              
              var docRef = documents.add(DocumentColorSpace.RGB, 576, 720);
              
              for (var i = 0; i < fileObjs.length; i++) {
              
                   if (fileList[i] instanceof File) {
                   
                        
                        var fileName = fileList[i].name.slice(0, -4);          
     
     
                        with (docRef) {
                             var myLayer = app.activeDocument.layers.add();
                             
                             myLayer.name = fileName
                        
                             var thisPlace = placedItems.add();
                             
                             thisPlace.file = fileObjs[i];
                             
                             var thisImage = placedItems[0].trace();
                             
                             redraw();
                                                           
                             thisImage.tracing.tracingOptions.loadFromPreset('Wave');
     
                             thisImage.tracing.expandTracing();
                             
                             redraw();
                        }
                   }
              }
              with (docRef) {
                             var aiOptions = saveAsAiFile();
                             var fileName = fileList[0].name.slice(0, -8);
                             aiFilePath = new File(ai.fsName + '/' + fileName + '.ai');
                             
                             saveAs(aiFilePath, aiOptions);
                             
                             close(SaveOptions.DONOTSAVECHANGES);
                     
         }
         }
    beep()
    } 
    }else{beep()}
    function saveAsAiFile() {
         var aiOptions = new IllustratorSaveOptions();
         with (aiOptions) {
              compatibility = Compatibility.ILLUSTRATOR12;
              compressed = true;
              embedICCProfile = true;
              embedLinkedFiles = true;
              flattenOutput = OutputFlattening.PRESERVEAPPEARANCE;
              fontSubsetThreshold = 0;
              overprint = PDFOverprint.PRESERVEPDFOVERPRINT;
              pdfCompatible = true
         }
         return aiOptions;
    }
     
    

     

     


     
    |
    Mark as:
  • Currently Being Moderated
    Apr 16, 2012 11:44 AM   in reply to Z_lot

    l have a go… Im NOT going to create 8k pngs to test with though… May be 20ish in a couple of folders and the rest is up to you… Beep might be a smoke alarm depending on what your using… What way up the layer stack? All folders 360 png files each?

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 16, 2012 12:11 PM   in reply to Muppet Mark

    For now It's 360 each.. it will probably change.

    The first file (in an alphabetic way) is in the lowest layer. it doesn't mater lowest or highest just to keep it alphabetic.

    I don't want to cause a fire so If you can use the system noises instead of the beep

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 16, 2012 12:28 PM   in reply to Z_lot

    The number of layers and their names will be determined by the files in the first sub-folder? Number of artboards will be determined by sub-folders in the chosen folder that OK? Are the files in each sub named the same way?

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 16, 2012 12:58 PM   in reply to 1000fx4u

    it goes like this but the names(A,J,R....) are different:

     

    ~/Desktop/Live Trace/A/A 000.png

    ~/Desktop/Live Trace/A/A 001.png

    ~/Desktop/Live Trace/A/A 002.png

     

    ~/Desktop/Live Trace/J/J 000.png

    ~/Desktop/Live Trace/J/J 001.png

    ~/Desktop/Live Trace/J/J 002.png

     

    ~/Desktop/Live Trace/R/R 000.png

    ~/Desktop/Live Trace/R/R 001.png

    ~/Desktop/Live Trace/R/R 002.png


    and the number of files wouldn't be always equal in all directories, Is it a problem?


     
    |
    Mark as:
  • Currently Being Moderated
    Apr 16, 2012 1:23 PM   in reply to Z_lot

    Oh now I may need a rethink…

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 16, 2012 1:25 PM   in reply to Muppet Mark

    Oh no...

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 16, 2012 1:45 PM   in reply to Z_lot

    Im not saying it can't be done… Just that Im going to have to go back and swap some stuff about… What I was thinking was 360 layers in the document and all artboards sharing these ( layers are document wide not artboard ) to have a layer for every placed file Im now going to need 1000's never seen a file with this before ( eeeek ) I do hope no one has to scroll these…

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 16, 2012 2:05 PM   in reply to Muppet Mark

    If some one will need to scroll these it will be me

    I know when you copy layers from one file to another you can check the "Paste remembers layers" option in the layers menu. after that you if you can select the layers and, again from the layers menu, you select the "Colect in new layer".

    I don't know if it helps in scripting...

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 16, 2012 2:22 PM   in reply to Z_lot

    Those functions offered by the flyouts are NOT available to script… I have to do that… You can't set paste remember layers by script either… It help scriping no AI offers much less to work with that some of the other apps… Theres more to scripting ID's prefs than the whole of AI…

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 16, 2012 2:32 PM   in reply to Muppet Mark

    than let's keep it as it was.

    I'll do the last part manualy.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 16, 2012 2:47 PM   in reply to Z_lot

    Oh ya too late now… I've got to say it slows down here with no where near the files you have… A lot will be down to the trace complexity so test as you like… I don't know if some saves would be a good idea that could free up some memory may be… This worked with 4 sub-folders of a dozen files each… Do test with less files and let me know if it does what you want…

     

     

    #target Illustrator
     
    threeSixtyArtboards();
     
    function threeSixtyArtboards() {
      
              var fileList, i, inFolder, subFiles;
     
              inFolder = Folder.selectDialog( 'Please choose your Parent Folder…?' );
      
              if ( inFolder != null ) {
      
                        fileList = Array();
     
                        inFiles = inFolder.getFiles();
     
                        if ( inFiles.length > 0 ) {
      
                                  for ( i = 0; i < inFiles.length; i++ ) {
      
                                            if ( inFiles[i] instanceof Folder ) {
      
                                                      subFiles = Folder( inFiles[i].fsName ).getFiles( /\.png$/i )
      
                                                      fileList.push( subFiles );
      
                                            };
     
                                  };
      
                                  placeAndTrace( fileList );
     
                        };
     
              };
     
    };
     
     
    function placeAndTrace( allFiles ) {
      
              var doc, i, j, lay, thisPlace, thisImage, uIL;
     
              uIL = userInteractionLevel;
              
              app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
      
              app.coordinateSystem = CoordinateSystem.ARTBOARDCOORDINATESYSTEM;
      
              doc = app.documents.add(
                        DocumentColorSpace.RGB,
                        width = 720,
                        height = 576,
                        numArtboards = allFiles.length,
                        DocumentArtboardLayout.GridByCol,
                        artboardSpacing = 72,
                        artboardRowsOrCols = Math.round( Math.sqrt( allFiles.length ) )
              );
     
              for ( i = 0; i < allFiles.length; i++ ) {
     
                        doc.artboards.setActiveArtboardIndex( i );
      
                        for ( j = 0; j < allFiles[i].length; j++ ) {
     
                                  lay = doc.layers.add();
      
                                  lay.name = decodeURI( allFiles[i][j].name );
      
                                  thisPlace = doc.placedItems.add();
                             
                                  thisPlace.file = allFiles[i][j];
      
                                  thisPlace.position = [ 0, 0 ];
      
                                  redraw();
                             
                                  thisImage = thisPlace.trace();
                             
                                  redraw();
                                                           
                                  thisImage.tracing.tracingOptions.loadFromPreset( 'Color 6' );
     
                                  thisImage.tracing.expandTracing();
                             
                                  redraw();
     
                        };
     
              };
     
              doc.layers.getByName( 'Layer 1' ).remove();
     
    };
    
     
    |
    Mark as:
  • Currently Being Moderated
    Apr 16, 2012 3:25 PM   in reply to Muppet Mark

    Thank You!!!

    Well it works perfect!

    is there a reason for the redraw(), it seems to work faster without it.

    I'm working now with a very simple trace and with 1024 * 1024 pngs so it's not that slow. I'll try to figure out the saves like you say, it will probably make faster.

    Thank you again!

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 16, 2012 3:41 PM   in reply to Z_lot

    Yep you are correct redraw() will force the GUI to refresh the window… This will slow the script down so you are free to comment/remove those. I use them so I can see where the test script is at… If the main part is OK correct number of layers and artboards then the rest is just cosmetic tinkering have fun… Don't forget to add the beep() do get back and let me know how many files you have this chew over…

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 16, 2012 4:53 PM   in reply to Muppet Mark

    I ran this on two full folders and it's beutiful !!!

    I'll run this tonight on all 22 folders and I'll let you know.

    Thank you again, you made my next weeks so much easier!

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 17, 2012 6:41 AM   in reply to Z_lot

    Well it was running all night (9 hours) and it seems like the saving doesn't help it to go faster.

    It completed 15 folders while the first folder was done in 3 min. so I decided to stop the script.

    The file is to heavy to work with and reopening it took too much time.

    So I did a little mix and match between all the scripts so it will save each folder to a separate file in the main folder and close it.

    It works like magic! after about an hour it Was all finished.

     

    Here is the final script I used:

     

     

    #target Illustrator
     while (app.documents.length) {
      app.activeDocument.close(SaveOptions.PROMPTTOSAVECHANGES);
    }
    Main();
     
    function Main() {
      
              var fileList, i, inFolder, subFiles;
     
              inFolder = Folder.selectDialog( 'Please choose your Parent Folder…?' );
     
              if ( inFolder != null ) {
      
                        fileList = Array();
     
                        inFiles = inFolder.getFiles();
     
                        if ( inFiles.length > 0 ) {
      
                                  for ( i = 0; i < inFiles.length; i++ ) {
      
                                            if ( inFiles[i] instanceof Folder ) {
      
                                                      subFiles = Folder( inFiles[i].fsName ).getFiles( /\.png$/i )
      
                                                      fileList.push( subFiles );
      
                                            };
     
                                  };
                                                           
                                  placeAndTrace( fileList , inFolder );
                        };
              };
     
    };
     
     
    function placeAndTrace( allFiles , inFolder) {
      
              var doc, i, j, lay, thisPlace, thisImage, uIL;
     
              uIL = userInteractionLevel;
              var orginalUIL = app.userInteractionLevel     
              app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS; 
     
              for ( i = 0; i < allFiles.length; i++ ) {
                        
                        doc = app.documents.add(DocumentColorSpace.RGB,1024,1024);
                        
                        for ( j = 0; j < allFiles[i].length; j++ ) {
     
                                  lay = doc.layers.add();
      
                                  lay.name = decodeURI( allFiles[i][j].name );
      
                                  thisPlace = doc.placedItems.add();
                             
                                  thisPlace.file = allFiles[i][j];
                           
                                  thisImage = thisPlace.trace();
                                                                    
                                  thisImage.tracing.tracingOptions.loadFromPreset( 'Wave' );
     
                                  thisImage.tracing.expandTracing();
                                                           
                        };
                        
                         with (doc) {
                         
                               layers.getByName( 'Layer 1' ).remove();
                               
                               var aiOptions = saveAsAiFile();
                               
                               var fileName =  allFiles[i][1].name.slice(0, -10);
                               
                               aiFilePath = new File(inFolder.fsName+'/' +fileName+'.ai'); 
                               
                               saveAs(aiFilePath, aiOptions);
                               
                               redraw();
                               
                               close(SaveOptions.DONOTSAVECHANGES);
                               
                         }
                     
                         beep() // 
              };
          
          userInteractionLevel = orginalUIL;          
     
    };
    function saveAsAiFile() {
         var aiOptions = new IllustratorSaveOptions();
         with (aiOptions) {
              compatibility = Compatibility.ILLUSTRATOR12;
              compressed = true;
              embedICCProfile = true;
              embedLinkedFiles = true;
              flattenOutput = OutputFlattening.PRESERVEAPPEARANCE;
              fontSubsetThreshold = 0;
              overprint = PDFOverprint.PRESERVEPDFOVERPRINT;
              pdfCompatible = true
         }
         return aiOptions;
    }
     
    
     
    |
    Mark as:
  • Currently Being Moderated
    Apr 17, 2012 7:24 AM   in reply to Z_lot

    Glad you got it sorted… I did state earlier on that I thought you were pushing things… I would have NOT been happy if you'd sent me the result… It's Illustrator

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points