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!')
}
}
2
Answers
Just for the Record: @obscures first answer edit works well. In case it doesn't work with the exact code, try adding delay after:
duplicate.exportDocument(newFile, ExportType.ILLUSTRATORPATHS, expOptions);
before closing the ps file, or just don't execute the line of code that closes the ps document.
Thanks again !
This can be done by altering the ExportOptionsIllustrator object according your needs.
To export a single path, the ExportOptionsIllustrator.path property must be set to
After that you can pick your desired path by it’s name using:
Edit:
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:
Edit2:
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.