Skip to main content
Participating Frequently
September 2, 2010
Answered

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

  • September 2, 2010
  • 2 replies
  • 11714 views

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!

This topic has been closed for replies.
Correct answer Muppet_Mark-QAl63s

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…


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 instanceof File) {                                    var fileName = fileList.name.slice(0, -4);                                         var docRef = documents.add(DocumentColorSpace.RGB, 576, 720);                                         with (docRef) {                                              var thisPlace = placedItems.add();                                                   thisPlace.file = fileObjs;                                                   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…

2 replies

Participating Frequently
April 16, 2012

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?


Inspiring
April 16, 2012

Oh now I may need a rethink…

Participating Frequently
April 16, 2012

Oh no...

1000fx4uAuthor
Participating Frequently
September 2, 2010

Also, I wanted to mention that I am using Bridge CS3  to Live Trace the files because Illustrator CS3 does not support processing Live Trace on a batch of files.

Muppet_Mark-QAl63s
Inspiring
September 2, 2010

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…

Inspiring
April 16, 2012

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 instanceof File) {

              

                   

                    var fileName = fileList.name.slice(0, -4);         

                    with (docRef) {

                         var myLayer = app.activeDocument.layers.add();

                        

                         myLayer.name = fileName

                   

                         var thisPlace = placedItems.add();

                        

                         thisPlace.file = fileObjs;

                        

                         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;

}



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?