Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

New Here ,
Sep 02, 2010 Sep 02, 2010

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!

TOPICS
Scripting
11.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Sep 04, 2010 Sep 04, 2010

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.activeDocumen

...
Translate
New Here ,
Sep 02, 2010 Sep 02, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 02, 2010 Sep 02, 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…

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 02, 2010 Sep 02, 2010

Thank you for your response Muppet Mark.

While in Illustrator CS3 when I attempt to record Live Trace in an Action via File > Scripts > Live Trace I am prompted to batch Trace files in Bridge which is why I was attempting to accomplish my script using Bridge. However, conceptually, I can see how the script I am trying to create could be Scripted using Illustrator CS3 wihtout the need for Bridge at all. Practically, though, creating the script is where I need help.  I have seen the Extendscript program but I am at a loss with what the code in a script like this would look like. I would be very grateful if you or anyone can help me write the script.

Thank you for your help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 03, 2010 Sep 03, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 03, 2010 Sep 03, 2010

Okay. Thank you for the information Muppet Mark. I do prefer the idea of scripting for one program instead of two. I'll head over to the Illustrator Forum for guidance. I'll attempt to write the script myself and post my code and questions on the Illustrator Forum when I get stuck. I am brand new to writing code and I 'm not sure how to start this script but I will give it my best shot.

Any additional help you can provide would be GREATLY appreciated. Thanks again!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 04, 2010 Sep 04, 2010

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…

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 04, 2010 Sep 04, 2010

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…

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 04, 2010 Sep 04, 2010

Incredible Muppet Mark! Thank you for taking the time to create this script for me. It is fantastic!

Please help me solve the following 3 issues to finish this script.

In addition to the .AI format I would also like to save the images in the .SVG format and .PSD format so that I have other formats of the images to work with:

1) Save as an .SVG.

I tried to accomplish this by including the code written below before Line 47: close(SaveOptions.DONOTSAVECHANGES);  but nothing happens.

var svgOpt = new ExportOptionsSVG();
svgOpt.fontType = SVGFontType.SVGFONT;
svgOpt.DTD = SVGDTDVersion.SVG1_0;
svgOpt.cssProperties = SVGCSSPropertyLocation.ENTITIES;
var fileSpec = new File(traceFolder.fsName.toString() + fileName +'.svg');

2) Export the image as a .PSD to a Subdirectory (tracedPSDs) so that I do not overwrite the original .PSD files

I tried to accomplish this by including the code written below but it did not work either.

var v_doc = app.activeDocument;
var v_psFileName = v_doc.path.fsName + '/tracedPSDs/' + fileName + '.psd';

exportFileToPSD(v_psFileName);

function exportFileToPSD (dest, doc) {
    if ( app.documents.length > 0 ) {
        var exportOptions = new ExportOptionsPhotoshop();
        var type = ExportType.PHOTOSHOP;
        var fileSpec = new File(dest);
        exportOptions.resolution = 150;
        app.activeDocument.exportFile( fileSpec, type, exportOptions );
    }
}

3) I have decided to use a Photoshop CS3 Action to add the Borders that I previously referenced, so I no longer need to add them to the Illustrator Script. I prefer using the Photoshop Action to create the borders because the Action perfoms other procedures on the images as well. But now I am attempting to run the Illustrator Script in a Photoshop Action and I get prompted with the following error:

"Error 2: userInteractionLevel is undefined. :

Line: 22

->   var originalUIL = userInteractionLevel;"

Do you know how to correct this error?

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

To Summarize:

1. In addition to the .AI files produced by the Illustrator Script I would like to add procedures to save the images as .SVG files and export them as .PSD files [in a new subdirectory (tracedPSDs) so that I don't overwrite the original .PSD files]

2. I am trying to run the Script in a Photoshop Action but I keep getting the "Error 2:" code (written out above).

I will continue troubleshooting. Thanks again for your help!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 04, 2010 Sep 04, 2010

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 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();                                                    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; }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 04, 2010 Sep 04, 2010

Thanks Muppet Mark! Saving in the additional formats succeeded (coding the additional subdirectories was very helpful too)! Superb! I'll keep looking for anything I can find regarding the Photoshop error. If I find anything I'll post it.

Thank You!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 15, 2012 Apr 15, 2012

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Apr 16, 2012 Apr 16, 2012

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…

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 16, 2012 Apr 16, 2012

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!


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Apr 16, 2012 Apr 16, 2012

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…

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 16, 2012 Apr 16, 2012

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Apr 16, 2012 Apr 16, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 16, 2012 Apr 16, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Apr 16, 2012 Apr 16, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 16, 2012 Apr 16, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Apr 16, 2012 Apr 16, 2012

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…

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 16, 2012 Apr 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;

}


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Apr 16, 2012 Apr 16, 2012

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 16, 2012 Apr 16, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Apr 16, 2012 Apr 16, 2012

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines