Skip to main content
Participating Frequently
March 13, 2014
Answered

Exporting multiple paths from photoshop to multiple illustrator files

  • March 13, 2014
  • 3 replies
  • 3692 views

Hello,

I have a task that I repeat often and I know there should be a way to write a photoshop script for the same. But my tech level in scripting is zero and I hoped somebody could possibly help me?

Background: I am an artist and I convert posterized image files to paths to feed to a CNC laser cutter. The image is broken down into separate layers (which are pasted back in hardcopy) and each layer is converted to outline paths (what is to be cut by the machine). for every image that i make there are about 3 - 8 paths that i create, each named a particular name. I then manually export each path one by one to an illustrator file (using Export >Paths to Illustrator), the files are named with a prefix_<the path name>.

sometimes a single large image is made up of 25 smaller sections (each section is a separate photoshop file) each with 3-8 paths, and it all adds up to a lot of manual labor each time.

is there a way to write a script that will export each individual path from a phtoshop file to a separate illustrator file with the name prefix_<path name> in a given directory (or a foler on the desktop if that's too complicated)?

I have searched the web but did not find a result that addresses this particular need. And as i've mentioned my scripting knowledge is not good enough to create/modify myself.

Thanks in advance.....

This topic has been closed for replies.
Correct answer G_Hoffmann

Avinash,

in my opinion Photoshop is not the optimal tool for your task. I would use Adobe Illustrator,

Live Trace or Image Trace (since CS6).

The vectorization of a raster image is fully under control by many parameters. Export as EPS

shows in the text file blocks like this:

991.532 1.85205 mo
993.008 1.61035 992.592 3.26025 992.643 4.44482 cv
991.515 4.21387 990.75 3.62207 990.791 2.22217 cv
991.221 2.28271 991.45 2.14063 991.532 1.85205 cv
cp
.031373 .65098 .501961 0 cmyk
ef

mo = moveto

cv = curveto (Bézier path)

cp = closepath

cmyk = color

ef = eofill (filling mode)

Occasionally, for straight lines:

li = lineto

Ignoring color and fill mode, it should be "simple" to extract the Bézier path information. 

Why is it necessary to separate all these paths into single files?

The laser cutting can be controlled for the whole job in one flow, because moveto

and closepath are equivalent to 'move without cutting' and 'end of cutting this path'.

Of course I'm lacking knowledge of your actual task. Please consider my contribution

as a suggestion for an alternative.

Best regards --Gernot Hoffmann

3 replies

c.pfaffenbichler
Community Expert
Community Expert
March 15, 2014

i'm making a mess marking correct and helpful

Don’t sweat it, many users don’t seem to bother with those rankings at all.

G_HoffmannCorrect answer
Inspiring
March 14, 2014

Avinash,

in my opinion Photoshop is not the optimal tool for your task. I would use Adobe Illustrator,

Live Trace or Image Trace (since CS6).

The vectorization of a raster image is fully under control by many parameters. Export as EPS

shows in the text file blocks like this:

991.532 1.85205 mo
993.008 1.61035 992.592 3.26025 992.643 4.44482 cv
991.515 4.21387 990.75 3.62207 990.791 2.22217 cv
991.221 2.28271 991.45 2.14063 991.532 1.85205 cv
cp
.031373 .65098 .501961 0 cmyk
ef

mo = moveto

cv = curveto (Bézier path)

cp = closepath

cmyk = color

ef = eofill (filling mode)

Occasionally, for straight lines:

li = lineto

Ignoring color and fill mode, it should be "simple" to extract the Bézier path information. 

Why is it necessary to separate all these paths into single files?

The laser cutting can be controlled for the whole job in one flow, because moveto

and closepath are equivalent to 'move without cutting' and 'end of cutting this path'.

Of course I'm lacking knowledge of your actual task. Please consider my contribution

as a suggestion for an alternative.

Best regards --Gernot Hoffmann

Avinash VAuthor
Participating Frequently
March 14, 2014

Dear Hoffmann,

Thank you for the reply.

The image is cut scale by scale from the posterized image and then repasted back again scale by scale in hardcopy. So it's a bit like the layers in photoshop but in paper. That is why they are to be in separate files as each scale is cut on a separate sheet of paper.

What you mention is more technical than i can follow easily. I will take your suggestion and explore the possibilty of using Illustrator instead.

I apologize if the way i wrote sounds, odd or strange.

Thanking you,

Avinash.

Avinash VAuthor
Participating Frequently
March 15, 2014

I clarify my task, suggestions to automate part of the workflow would very welcome.

i use an example.... the image below is in 3 scales of grey.

my aim is to construct a piece where the image is recreated through physical layers.

for this image i require 4 physical layers (with L004 being the bottom most layer and L0001 being the top most). the parts in red are to be cut out and have to be made into paths from these source bitmaps. the unique name of the path tells me when cutting what  paper to feed and which layer i'm working on.

this is a simple example, but it can get confusing and laborious when there are more scales and layers. My problem isn't so much in converting to a path from bitmap, with an appropriate tolerance value it usually works fine. What i do is load the multiple bitmaps as layers in PS and make the paths. i just need to be able to output each of the red sections from each bitmap as separate ai files (each layer can contain several paths and contains both 'move without cutting' and 'end of cutting this path' info).

Thanks.

ps. for whatever reason i'm not good in public forums as a persona and tend to avoid speaking much as i can. sorry if you misunderstood me.

c.pfaffenbichler
Community Expert
Community Expert
March 14, 2014

This might cause issues with Vector Masks, but maybe it helps.

// export paths as ai;

// 2014, use at your own risk;

#target photoshop

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

// getting the name and location

var docName = myDocument.name;

var basename = docName.match(/(.*)\.[^\.]+$/)[1];

var docPath = myDocument.path;

// export the paths;

for (var m = 0; m < myDocument.pathItems.length; m++) {

exportIllustratorPath (myDocument, myDocument.pathItems.name, docPath, basename);

}

};

////// function to save paths //////

function exportIllustratorPath (myDocument, pathName, docPath, basename) {

// =======================================================

var idExpr = charIDToTypeID( "Expr" );

    var desc10 = new ActionDescriptor();

    var idUsng = charIDToTypeID( "Usng" );

        var desc11 = new ActionDescriptor();

        var idIn = charIDToTypeID( "In  " );

        desc11.putPath( idIn, new File( docPath+'/'+basename+"_"+pathName+".ai") );

        var idPthS = charIDToTypeID( "PthS" );

        var idPtSl = charIDToTypeID( "PtSl" );

        var idSngP = charIDToTypeID( "SngP" );

        desc11.putEnumerated( idPthS, idPtSl, idSngP );

        var idWhcP = charIDToTypeID( "WhcP" );

            var ref6 = new ActionReference();

            var idPath = charIDToTypeID( "Path" );

            ref6.putName( idPath, pathName );

        desc11.putReference( idWhcP, ref6 );

    var idIllustratorExportThisstringmakesmeunique = stringIDToTypeID( "Illustrator Export.  This string makes me unique!" );

    desc10.putObject( idUsng, idIllustratorExportThisstringmakesmeunique, desc11 );

executeAction( idExpr, desc10, DialogModes.NO );

};

Avinash VAuthor
Participating Frequently
March 14, 2014

Thank you for the help....

When executing the script I get this error for the last line of the script.

I'm on Photoshop 14.2.1 x64

Is there something i'm doing wroing?

Thanks again for the help.

Avinash VAuthor
Participating Frequently
March 14, 2014

sorry.... new to the forums, still finding my way around the interface....