I am desperately trying to figure out how to write a js for photoshop, that exports only a specific path and not all of the contained paths under the "paths" tab in my PS Document to an Illustrator File. For example in the picture here:
I would like to export only the path with the Name : "2 Acryl" by using a script. I already have a working script that exports all of the paths into one AI File. I just can't figure out how to reference a single path by its name and export it.
function unSaved() {
try {
activeDocument.path;
/* Finish Unsaved Document Error Check - Part A: Try */
/* Main Code Start */
/* Based on the following topic thread:
https://community.adobe.com/t5/photoshop/exporting-all-paths-to-illustrator-error/m-p/8796143 */
var doc = app.activeDocument;
var docPath = doc.path;
var docName = doc.name.replace(/\.[^\.]+$/, '');
var newFile = File(docPath + '/' + docName + '_Paths' + '.ai');
var expOptions = new ExportOptionsIllustrator;
expOptions.path = IllustratorPathType.ALLPATHS;
doc.exportDocument(newFile, ExportType.ILLUSTRATORPATHS, expOptions);
// alert('All Photoshop paths have been exported as a single Illustrator file in:' + '\r' + docPath);
/* Main Code Finish */
/* Start Unsaved Document Error Check - Part B: Catch */
} catch (err) {
alert('An image must be both open and/or saved before running this script!')
}
}
This can be done by altering the ExportOptionsIllustrator object according your needs.
var expOptions = new ExportOptionsIllustrator;
To export a single path, the ExportOptionsIllustrator.path property must be set to
expOptions.path = IllustratorPathType.NAMEDPATH;
After that you can pick your desired path by it's name using:
expOptions.pathName = '2 Acryl';
Apparently due to a bug in Photoshop itself the export option IllustratorPathType.NAMEDPATH is simply ignored. Photoshop will always export all paths no matter what.
Here's a hacky workaround though. Photoshop script offers the PathItems object which contains a list of all the paths in the document. So the idea is this:
Here's the updated script:
try {
var doc = app.activeDocument;
var docPath = doc.path;
var docName = doc.name.replace(/\.[^\.]+$/, '');
var newFile = File(docPath + '/' + docName + '_Paths' + '.ai');
var expOptions = new ExportOptionsIllustrator;
var duplicate = app.activeDocument.duplicate('duplicate');
for(a = duplicate.pathItems.length-1; a>=0; a--)
{
if(duplicate.pathItems[a].name != '2 Acryl')
{
duplicate.pathItems[a].remove();
}
}
duplicate.exportDocument(newFile, ExportType.ILLUSTRATORPATHS, expOptions);
duplicate.close(SaveOptions.DONOTSAVECHANGES);
} catch (err) {
alert('An image must be both open and/or saved before running this script!')
}
If this still fails, there's a last resort. Photoshop has a built-in function to export paths to Illustrator. Simply go to:
File * Export * Paths -> Illustrator...
and choose your desired path in the popup dialog.