Skip to main content
Participating Frequently
March 13, 2014
Answered

Exporting multiple paths from photoshop to multiple illustrator files

  • March 13, 2014
  • 3 replies
  • 3703 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.

Inspiring
March 15, 2014

Hello,

so sorry.... that was a very misleading example.....

my work is for a purely visual effect and has no practical function. I've been making digital artwork with a lot of layer masks and layers, flattening them and getting an inkjet output. at a certain point i wondered if it was possible to recreate the layer masks physically on paper too, and layer them one on top of the other like i would do in softcopy.

so from this source:

it looks like this in hardcopy on paper (just as a example).

to avoid floating islands of the image from falling off the image edge when cut, a friend of mine helped me write some java code to break the image into layers that are connected always to the edge of the frame. it outputs bitmaps like this.... a four grayscale image can output many layers depending on how many 'islands' there are.

the red indicates which parts of the image need to get cut on each layer. once i have all the layers cut on paper, i just glue them all back one by one in the same order to achive the preview image above.

it's a lot of work, just for a visual effect and has no practical purpose.

i guess my initial question was basic which i didn't state well. in the PS scripts there is one for 'export layers to file'. i just wondered if it was possible to have a similar one for 'export paths to files'. pehaps this can be done via illustrator better and that is something i haven't looked into well enough.

the production of each image can take a long time and is very repetivie. just wanted to try and automate some parts of the workflow if i can....

thanks for taking the time to reply. and sorry about the misleading example.

Avinash.


Thanks for the clarification and further information. This will hopefully enable

the scripting and layer mask experts here to help you further, and as well me

concerning the application of Illustrator.

There is one issue which I'm still not understanding: how do you decide which

parts of the graphic belong to one layer?

Meanwhile you may have a look here, an application of Live Trace by Illustrator:

http://docs-hoffmann.de/casamunsell24062012.pdf

3 MBytes. Explanation in German and English on the first pages.

Best regards --Gernot Hoffmann

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