Copy paths from one document to another
Hi there,
There've been several discussions about this on ps-script.com and the Adobe forums.
But none of the supplied scripts did really satisfy my needs...
As sending files to Asia for clipping purposes becomes more and more common I think this could help a lot of people that don't want to spend their day copying paths from their JPG 5 compressed image to their own non-compressed TIF file or whatever...
So I have two images of identic canvas size, resolution,... and i want to transfer all paths from the one image to the other.
I've seen this script from Michael Hale and Christof Pfaffenbichler going around that basically copies every single path-point into an array that you can copy into your other image..
function extractSubPathInfo(pathObj){
var derpfad = new Array();
var pl = pathObj.subPathItems.length;
for(var s=0;s<pl;s++){
var pArray = new Array();
for(var i=0;i<pathObj.subPathItems.pathPoints.length;i++){
pArray = new PathPointInfo;
pArray.kind = pathObj.subPathItems.pathPoints.kind;
pArray.anchor = pathObj.subPathItems.pathPoints.anchor;
pArray.leftDirection = pathObj.subPathItems.pathPoints.leftDirection;
pArray.rightDirection = pathObj.subPathItems.pathPoints.rightDirection;
};
derpfad[derpfad.length] = new Array();
derpfad[derpfad.length - 1] = new SubPathInfo();
derpfad[derpfad.length - 1].operation = pathObj.subPathItems.operation;
derpfad[derpfad.length - 1].closed = pathObj.subPathItems.closed;
derpfad[derpfad.length - 1].entireSubPath = pArray;
};
return derpfad;
};
That's a nice solution but also a very very slow one if you work with larger images that contain many anchorpoints.. (I usually have to deal with 60x40cm @ 300dpi - about 7000x5000px if you're non-metric
and 5-10 paths on it that have estimated 500(?) anchor points.. this is just a guess.. but I think you know what i mean)
So copying every anchor point into this array takes about 20 seconds (2x3.2GHz QuadCore Intel Xeon.. so no, its not cause my Mac is too slow
)
In addition to this (which wouldn't be THAT big problem... at least I don't have to do it all by myself...) the script seems to sometimes not recognize the whole path.. Some parts are just missing after copying the path to the other image..
So I tried to workaround the whole thing and not copy the paths into the other image - I wanted to copy the layers of the TIF file into the JPG (the one with the paths) and overwrite the TIF.
This is pretty fast, everything seemed to be ok, until I realized that my script couldn't handle Layersets.
This is it (it's not very smoothly written, but it does the job..)
var docRef = app.activeDocument;
var docJPG= app.activeDocument;
// Here I open the TIF that has the same name as the JPG but in a /TIF/ subdirectoy
var jpg = docRef.name;
var fname = docRef.name.split(".");
var fname1 = "";
for (var k = 0; k <= fname.length - 2; k++) {
fname1 = fname1 + fname+ ".";
}
var fname2 = "TIF";
var fnamenew = fname1 + fname2;
var newpath = docRef.path + "/TIF/" + fnamenew;
var docRef = app.activeDocument;
var TIF = newpath;
var TIFShortcut = new File(TIF);
var docTIF = open(TIFShortcut);
// Check if the TIF is 16-bit - and change the JPG to that...
if(docTIF.bitsPerChannel != docJPG.bitsPerChannel) {
app.activeDocument = docJPG;
docJPG.bitsPerChannel = docTIF.bitsPerChannel;
app.activeDocument = docTIF;
}
// Transfer the layers from the TIF to the JPGfor(var i = docTIF.artLayers.length-1; i >= 0; i--){
docTIF.artLayers.duplicate(docRef);
}
// Close the TIF
docTIF.close(SaveOptions.DONOTSAVECHANGES);
// Then I delete the Background Layer that was originally the JPG file
var ebenen = docRef.artLayers.length-1;
docRef.artLayers[ebenen].remove();
// Set the bottom Layer as Background Layer
var ebenen = docRef.artLayers.length-1;
docRef.artLayers[ebenen].isBackgroundLayer = 1;
// And finally replace the TIF file in the /TIF/ folderdocRef.saveAs(new File(newpath),TiffSaveOptions);
docRef.close();
docRef = null;
So this is what i need:
Either a possibility to check for Layersets and copy them as well
OR
A better faster solution to copy all paths from one Image to another.
Please Adobe, implement something in CS6 (or even better in an update for CS5
) to easily copy a whole path.
I hope you guys can help me (and I'm sure there are more people having the same issue...)
kind regards
derflow85
