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!
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.
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.
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!
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…
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!
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;
}
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.
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…
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!
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;
}
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… ![]()
![]()
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;
}
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?
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… ![]()
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...![]()
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();
};
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… ![]()
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;
}
North America
Europe, Middle East and Africa
Asia Pacific