I am trying to a condition to this script. I created it from my another photoshop action using Action to JSX Script Photoshop action.
Normally my PSDs have at least two layers. 1st layer is a (unwanted) partial mirror image of a (wanted) second layer. This script select the unwanted 1st layer and remove it and do some other actions on remaining layer and create a jpg. My second layer contain required image.
However, If 1st layer is not a partial mirror image of second layer, as there is no mirror image layer exist then I don't want to remove 1st layer as it contain required image in it.
In this situation I want to create a new blank helping layer on top of this 1st layer to make it second layer then my script do as usual as it does, i.e. remove unwanted 1st layer and do other actions on remaining layer.
So to achieve this I want conditional addition of New Layer based upon front Layer. In my mind I have a condition which should trigger addition of a new layer:
- If 1st layer is 60% to 70% filled with some image, then it add a layer otherwise proceed to next line
How to incorporated this condition to my JS script between 18 and 19 line. I have checked photoshop cc javascript ref 2015 but I didn't understand how to incorporated this condition to my script.
#target photoshop
//
// Conditional Layer Removal PSD JPG.jsx
// Conditional Removal of ID Layer based upon number of layer in a PSD
//
// Generated Sat Jul 29 2017 00:59:28 GMT+0500
//
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
var layerCount = app.activeDocument.layers.length;
if (layerCount > 2)
{
//
//==================== RemoveIDLayer ==============
//
function RemoveIDLayer() {
// Select
function step1(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Frnt'));
desc1.putReference(cTID('null'), ref1);
desc1.putBoolean(cTID('MkVs'), false);
var list1 = new ActionList();
list1.putInteger(9);
desc1.putList(cTID('LyrI'), list1);
executeAction(cTID('slct'), desc1, dialogMode);
};
// Delete
function step2(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
desc1.putReference(cTID('null'), ref1);
var list1 = new ActionList();
list1.putInteger(9);
desc1.putList(cTID('LyrI'), list1);
executeAction(cTID('Dlt '), desc1, dialogMode);
};
// Select
function step3(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Frnt'));
desc1.putReference(cTID('null'), ref1);
desc1.putBoolean(cTID('MkVs'), false);
var list1 = new ActionList();
list1.putInteger(9);
desc1.putList(cTID('LyrI'), list1);
executeAction(cTID('slct'), desc1, dialogMode);
};
// Trim
function step4(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putEnumerated(sTID("trimBasedOn"), sTID("trimBasedOn"), sTID("topLeftPixelColor"));
desc1.putBoolean(cTID('Top '), true);
desc1.putBoolean(cTID('Btom'), true);
desc1.putBoolean(cTID('Left'), true);
desc1.putBoolean(cTID('Rght'), true);
executeAction(sTID('trim'), desc1, dialogMode);
};
// Trim
function step5(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putEnumerated(sTID("trimBasedOn"), sTID("trimBasedOn"), sTID("bottomRightPixelColor"));
desc1.putBoolean(cTID('Top '), true);
desc1.putBoolean(cTID('Btom'), true);
desc1.putBoolean(cTID('Left'), true);
desc1.putBoolean(cTID('Rght'), true);
executeAction(sTID('trim'), desc1, dialogMode);
};
// Scripts
function step6(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var estr = '//@include "~/OneDrive/Business/Website Making/Commands and Scripts/Adobe Scripts/Conditional resizeImage 1100 All.jsx";\r\n';
eval(estr);
};
// Canvas Size
function step7(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putBoolean(cTID('Rltv'), true);
desc1.putUnitDouble(cTID('Wdth'), cTID('#Pxl'), 300);
desc1.putUnitDouble(cTID('Hght'), cTID('#Pxl'), 300);
desc1.putEnumerated(cTID('Hrzn'), cTID('HrzL'), cTID('Cntr'));
desc1.putEnumerated(cTID('Vrtc'), cTID('VrtL'), cTID('Cntr'));
desc1.putEnumerated(sTID("canvasExtensionColorType"), sTID("canvasExtensionColorType"), cTID('BckC'));
executeAction(sTID('canvasSize'), desc1, dialogMode);
};
// Scripts
function step8(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var estr = '//@include "~/OneDrive/Business/Website Making/Commands and Scripts/Adobe Scripts/PSDtoJPG.jsx";\r\n';
eval(estr);
};
// Close
function step9(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putEnumerated(cTID('Svng'), cTID('YsN '), cTID('N '));
desc1.putInteger(cTID('DocI'), 816);
desc1.putBoolean(sTID("forceNotify"), true);
executeAction(cTID('Cls '), desc1, dialogMode);
};
step1(); // Select
step2(); // Delete
step3(); // Select
step4(); // Trim
step5(); // Trim
step6(); // Scripts
step7(); // Canvas Size
step8(); // Scripts
step9(); // Close
};
//=========================================
// RemoveIDLayer.main
//=========================================
//
RemoveIDLayer.main = function () {
RemoveIDLayer();
};
RemoveIDLayer.main();
// EOF
"Conditional Layer Removal PSD JPG.jsx"
// EOF
}
else app.doAction ("< 2 Layer removal PSD", "My Actions")
Aucun commentaire:
Enregistrer un commentaire