Please Help!
I have a script that works great when ran manually. I want to use it in a switch flow. This script creates Tifs from adjustment layers in the open document. Is it possible to have all of these new tifs go down the outgoing connection? I've tried to convert this but I don't know what in the hell I'm doing...
________________________________________________________________________
// thanks to xbytor for regexp;
// 2012, use it at your own risk;
#target photoshop
if (app.documents.length > 0) {
var myDoc = app.activeDocument;
var docName = myDoc.name;
try {var basename = docName.match(/(.*).[^.]+$/)[1];
var docPath = myDoc.path}
catch (e) {var basename = docName;
var docPath = "~/Desktop"};
// try to get set »Main colors« in »product«;
try {
var theSet = myDoc.layers.getByName("group").layers.getByName("colors");
for (var n = 0; n < theSet.layers.length; n++) {
theSet.layers[n].visible = false;
};
// process;
for (var m = 0; m < theSet.layers.length; m++) {
var thisLayer = theSet.layers[m];
thisLayer.visible = true;
var layerName = thisLayer.name;
while (layerName.indexOf("/") != -1) {layerName = layerName.replace("/", "_")};
saveFlattenedTiff (myDoc, basename + "_" + layerName, docPath)
thisLayer.visible = false;
}
}
catch (e) {alert ("can’t locate folder")};
};
////// function to save the flattened tiff from copy //////
function saveFlattenedTiff (myDoc, basename, docPath) {
tifOpts = new TiffSaveOptions();
tifOpts.embedColorProfile = true;
tifOpts.imageCompression = TIFFEncoding.TIFFLZW;
tifOpts.alphaChannels = false;
tifOpts.byteOrder = ByteOrder.MACOS;
tifOpts.layers = false;
myDoc.saveAs((new File(docPath+"/"+basename+".tif")),tifOpts,true)
};
________________________________________________________________________
Any help would be greatly appreciated.
Thanks
JG
Converting Photoshop Script
-
- TOP CONTRIBUTOR
- Posts: 628
- Joined: Mon Nov 29, 2010 8:45 pm
- Location: Alpharetta GA USA
- Contact:
Converting Photoshop Script
Hello, try this modified version that adds Switch variables.
// thanks to xbytor for regexp;
// 2012, use it at your own risk;
var myDoc = $doc;
var docName = myDoc.name;
var basename;
try {
basename = docName.match(/(.*).[^.]+$/)[1];
} catch (e) {
$error = "filename error";
}
// try to get set »Main colors« in »product«;
try {
var theSet = myDoc.layers.getByName("group").layers.getByName("colors");
for (var n = 0; n < theSet.layers.length; n++) {
theSet.layers[n].visible = false;
}
// process;
for (var m = 0; m < theSet.layers.length; m++) {
var thisLayer = theSet.layers[m];
thisLayer.visible = true;
var layerName = thisLayer.name;
while (layerName.indexOf("/") != -1) {
layerName = layerName.replace("/", "_")
};
saveFlattenedTiff(myDoc, basename + "_" + layerName)
thisLayer.visible = false;
}
} catch (e) {
$error = "can’t locate folder";
}
////// function to save the flattened tiff from copy //////
function saveFlattenedTiff(myDoc, basename) {
tifOpts = new TiffSaveOptions();
tifOpts.embedColorProfile = true;
tifOpts.imageCompression = TIFFEncoding.TIFFLZW;
tifOpts.alphaChannels = false;
tifOpts.byteOrder = ByteOrder.MACOS;
tifOpts.layers = false;
myDoc.saveAs((new File($outpath+"/"+basename+".tif")),tifOpts,true);
outfiles.push($outpath+"/"+basename+".tif");
};
Dwight Kelly
Apago, Inc.
dkelly@apago.com
// thanks to xbytor for regexp;
// 2012, use it at your own risk;
var myDoc = $doc;
var docName = myDoc.name;
var basename;
try {
basename = docName.match(/(.*).[^.]+$/)[1];
} catch (e) {
$error = "filename error";
}
// try to get set »Main colors« in »product«;
try {
var theSet = myDoc.layers.getByName("group").layers.getByName("colors");
for (var n = 0; n < theSet.layers.length; n++) {
theSet.layers[n].visible = false;
}
// process;
for (var m = 0; m < theSet.layers.length; m++) {
var thisLayer = theSet.layers[m];
thisLayer.visible = true;
var layerName = thisLayer.name;
while (layerName.indexOf("/") != -1) {
layerName = layerName.replace("/", "_")
};
saveFlattenedTiff(myDoc, basename + "_" + layerName)
thisLayer.visible = false;
}
} catch (e) {
$error = "can’t locate folder";
}
////// function to save the flattened tiff from copy //////
function saveFlattenedTiff(myDoc, basename) {
tifOpts = new TiffSaveOptions();
tifOpts.embedColorProfile = true;
tifOpts.imageCompression = TIFFEncoding.TIFFLZW;
tifOpts.alphaChannels = false;
tifOpts.byteOrder = ByteOrder.MACOS;
tifOpts.layers = false;
myDoc.saveAs((new File($outpath+"/"+basename+".tif")),tifOpts,true);
outfiles.push($outpath+"/"+basename+".tif");
};
Dwight Kelly
Apago, Inc.
dkelly@apago.com
Converting Photoshop Script
Hi dkelly,
Thanks for your help.
I tried running this in a flow and it is moved to the problems folder with the can't find folder error. Do you have any suggestions?
Thanks again for your help.
JG
Thanks for your help.
I tried running this in a flow and it is moved to the problems folder with the can't find folder error. Do you have any suggestions?
Thanks again for your help.
JG
-
- TOP CONTRIBUTOR
- Posts: 628
- Joined: Mon Nov 29, 2010 8:45 pm
- Location: Alpharetta GA USA
- Contact:
Converting Photoshop Script
Add a "Problem folder" to your flow. It's listed with the other Configurators. Existing jobs will be preserved and show up when you start flow again.
Send me a sample input file if you want me to verify the correct behavior. Your Photoshop script looked for a very specific type of adjustment layers.
Dwight Kelly
Apago, Inc.
dkelly@apago.com
Send me a sample input file if you want me to verify the correct behavior. Your Photoshop script looked for a very specific type of adjustment layers.
Dwight Kelly
Apago, Inc.
dkelly@apago.com
Converting Photoshop Script
Hi dkelly,
I've just sent you an email with an attached test file. If you don't receive it, please let me know and I can try to resend it.
Thank you,
JG
I've just sent you an email with an attached test file. If you don't receive it, please let me know and I can try to resend it.
Thank you,
JG
-
- TOP CONTRIBUTOR
- Posts: 628
- Joined: Mon Nov 29, 2010 8:45 pm
- Location: Alpharetta GA USA
- Contact:
Converting Photoshop Script
Here's the version that correctly processed your sample PSD file. Set this a the Photoshop "Save" script in Switch.
// thanks to xbytor for regexp;
// 2012, use it at your own risk;
var myDoc = $doc;
var docName = myDoc.name;
var basename;
try {
basename = docName.match(/(.*).[^.]+$/)[1];
} catch (e) {
$error = "filename error";
}
// try to get set »Main colors« in »product«;
try {
var theSet = myDoc.layers.getByName("group").layers.getByName("colors");
for (var n = 0; n < theSet.layers.length; n++) {
theSet.layers[n].visible = false;
}
// process;
for (var m = 0; m < theSet.layers.length; m++) {
var thisLayer = theSet.layers[m];
thisLayer.visible = true;
var layerName = thisLayer.name;
while (layerName.indexOf("/") != -1) {
layerName = layerName.replace("/", "_")
};
saveFlattenedTiff(myDoc, basename + "_" + layerName)
thisLayer.visible = false;
}
} catch (e) {
$error = "can’t locate folder";
}
////// function to save the flattened tiff from copy //////
function saveFlattenedTiff(myDoc, basename) {
tifOpts = new TiffSaveOptions();
tifOpts.embedColorProfile = true;
tifOpts.imageCompression = TIFFEncoding.TIFFLZW;
tifOpts.alphaChannels = false;
tifOpts.byteOrder = ByteOrder.MACOS;
tifOpts.layers = false;
myDoc.saveAs((new File($outfolder+"/"+basename+".tif")),tifOpts,true);
$outfiles.push($outfolder+"/"+basename+".tif");
};
// thanks to xbytor for regexp;
// 2012, use it at your own risk;
var myDoc = $doc;
var docName = myDoc.name;
var basename;
try {
basename = docName.match(/(.*).[^.]+$/)[1];
} catch (e) {
$error = "filename error";
}
// try to get set »Main colors« in »product«;
try {
var theSet = myDoc.layers.getByName("group").layers.getByName("colors");
for (var n = 0; n < theSet.layers.length; n++) {
theSet.layers[n].visible = false;
}
// process;
for (var m = 0; m < theSet.layers.length; m++) {
var thisLayer = theSet.layers[m];
thisLayer.visible = true;
var layerName = thisLayer.name;
while (layerName.indexOf("/") != -1) {
layerName = layerName.replace("/", "_")
};
saveFlattenedTiff(myDoc, basename + "_" + layerName)
thisLayer.visible = false;
}
} catch (e) {
$error = "can’t locate folder";
}
////// function to save the flattened tiff from copy //////
function saveFlattenedTiff(myDoc, basename) {
tifOpts = new TiffSaveOptions();
tifOpts.embedColorProfile = true;
tifOpts.imageCompression = TIFFEncoding.TIFFLZW;
tifOpts.alphaChannels = false;
tifOpts.byteOrder = ByteOrder.MACOS;
tifOpts.layers = false;
myDoc.saveAs((new File($outfolder+"/"+basename+".tif")),tifOpts,true);
$outfiles.push($outfolder+"/"+basename+".tif");
};
Converting Photoshop Script
Great! I've tried and it works perfect. Thank you for your help with this. It would have taken me a while to figure it out....
Thanks again
Thanks again