Copy link to clipboard
Copied
Hello,
I make apparel for youth and school sports teams, many of which I have online stores for the parents to buy spiritwear. Majority of store use the same 20-30 products just a change of a logo.
Right now I have a photoshop file with all of the products in layers and I go in one by one and making visble the product and resizing the logo to the specific apparel export as a jpeg and over and over again.
I know with smart objects I can change the logo but what would be the quickest way to set up the whole process.
My wish is that I could just change one logo file then hit some sort of batch automation and it would exports all the jpeg automatically.
ANy ideas would be greatly appreciated.
Copy link to clipboard
Copied
IMO if you have 20 or 30 Product you should have 20 or 30 Product Mockup Templates and s script to populate the Mockups with you design changes and logos. Anytime you want to change a product you create your design replacement elements and run your script on the mockup template for the product.
There is no need to have common products elements or design elements between products. There is no good reason to put all you eggs in one basket. Putting all to products in one file makes it harder to maintain that file and create a single point of failure, slow down Photoshop processing for Photoshop is processing a large Document Files where you have most of the layers visibility are off for one only one products layer are visible. To save our you images. You template is harder to use for you need to configure the layers for each Product. Using 30 small easy to create maintain and use template will be faster.
Copy link to clipboard
Copied
Thank you. I can separate out into individual Products. Is there a place i can find an example of a similar script?
Copy link to clipboard
Copied
@GOODPEOPLES wrote:
Is there a place i can find an example of a similar script?
JJMack offers more than one here:
http://www.mouseprints.net/old/dpr/PhotoCollageToolkit.html
Copy link to clipboard
Copied
When it comes to templates the most important thing is that the replacement content must have the proper Aspect Ratio. Replacement content must be appropriate their use in the template. While replacement content that has the exact same Aspect Ratio and Size as the content in the Template is best. Replacement results may be accessible if the replacement content has an Aspect Ration close to the image's content in the template. If the Script has some options the address the replacement content Aspect related to the templates content.
In general if the imaged content has a wide Landscape Aspect Ration. Replacement content that has a tall Portrait aspect ratio will not produce accessible results and a wide Landscape replacing a portrait aspect ratio design will also not be accessible. I classify templates into two categories. Collage Templates and Mockup templates.
While Image Replacement in both Collage Templates and Mockup are Smart Object Layers. Collage Templates do not have Smart Object layers in the Template where Mockup Templates haves Smart object Layers on top on the layers stack to be replaced. Withe Mockup Templates Replacement content must have the exact same aspect Ratio, Size and resolution as the Smart object layers on top of the layers stack for the Populating Mockup Script to use Photoshop Replace Content for the top Smart Object Layers. My Mockup Scripts have an option to Edit Smart object layers instead of using replace content with some addition option for fitting replacement into the current object. However, all Smart objects are not Photoshop object. So Smart Object that is a RAW Camera Image Data and Vector Images can not be edited my Photoshop scripts so my mockup scripts will bypass replacing those Photoshop Smart objects.
Collage Templates do not Have Smart Objects layers in the template. They have Alpha Channels that Map Image Location Size and Shape. These area will be covered with Smart Object Layer that are scaled to the collage Images location Size and shape. However The Collage scripts do not Support Image rotation and warping like perspective. Mockup Templates are required if you need Image rotation and Warping.
Copy link to clipboard
Copied
I agree with JJMack in that setting up 30 or so master templates would be easier.
My first thought was to setup an action to place and scale the logo at different sizes for each product. I would use four guides to mark out the area for the logo on each product template, then use a helper script from JJMack to resize the logo layer to the guides.
The action only needs two steps if used with say Image Processor or Image Processor Pro scripts. Three steps if used with Automate/Batch (adding a save step which is not needed with the IP or IPP scripts).
1) File Place (embedded or linked as you prefer, it doesn't really matter unless saving layered files)
2) Fit Image to Guides script (a "helper" script)
Each time you need to place a new logo for a different club/team, just change the first step to place a different logo. Then you only need one action. Or you could just use a generic filename and replace the source logo with the new logo each time, so that you don't need to change the action.
Here I have used two images from Shutterstock as exmple products and the result of the suggested process. The 2 products could be 30, 300 or more – the single run of the bulk processing will add the same logo to all products at the required size.
Of course more steps could be added, such as using displacement maps or shadow/highlight layers to make the logo better conform to the underlying image.
I'll post the helper scripts in a separate post.
Copy link to clipboard
Copied
Portrait version:
// https://forums.adobe.com/message/8732179#8732179
// https://forums.adobe.com/message/8728770#8728770
// 2019 - Uncomment line 123 to enable the layer mask, which has been disabled to retain the proportions of the resized layer
// FitImageToGuides.jsx
/* ==========================================================
// 2014 John J. McAssey (JJMack)
// ======================================================= */
// This script is supplied as is. It is provided as freeware.
// The author accepts no liability for any problems arising from its use.
/* Help Category note tag menu can be used to place script in automate menu
<javascriptresource>
<about>$$$/JavaScripts/FitImageToGuides/About=JJMack's FitImageToGuides .^r^rCopyright 2014 Mouseprints.^r^rFour and only four guides are required</about>
<category>JJMack's Script</category>
</javascriptresource>
*/
// enable double-clicking from Mac Finder or Windows Explorer
#target photoshop
// bring application forward for double-click events
app.bringToFront();
// ensure at least one document open
if (!documents.length) alert('There are no documents open.', 'No Document');
else {
// declare Global variables
//main(); // at least one document exists proceed
app.activeDocument.suspendHistory('Fix Image to Guides','main()'); //problem if there is a selection a layer resize Photoshop back up a history step ?
}
///////////////////////////////////////////////////////////////////////////////
// main function
///////////////////////////////////////////////////////////////////////////////
function main() {
// declare local variables
var orig_ruler_units = app.preferences.rulerUnits;
var orig_type_units = app.preferences.typeUnits;
var orig_display_dialogs = app.displayDialogs;
app.preferences.rulerUnits = Units.PIXELS; // Set the ruler units to PIXELS
app.preferences.typeUnits = TypeUnits.POINTS; // Set Type units to POINTS
app.displayDialogs = DialogModes.NO; // Set Dialogs off
try { code(); }
// display error message if something goes wrong
catch(e) { alert(e + ': on line ' + e.line, 'Script Error', true); }
app.displayDialogs = orig_display_dialogs; // Reset display dialogs
app.preferences.typeUnits = orig_type_units; // Reset ruler units to original settings
app.preferences.rulerUnits = orig_ruler_units; // Reset units to original settings
}
///////////////////////////////////////////////////////////////////////////////
// main function end
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
// The real code is embedded into this function so that at any point it can return
// to the main line function to let it restore users edit environment and end
//////////////////////////////////////////////////////////////////////////////////////////////
function code() {
if (app.activeDocument.guides.length != 4) { alert("Four and only four Guides are required"); return; } // quit
// get guides;
var theVert = new Array;
var theHor = new Array;
for (var m = 0; m < app.activeDocument.guides.length; m++) {
if (app.activeDocument.guides[m].direction == Direction.HORIZONTAL) {theVert.push(app.activeDocument.guides[m].coordinate)}
else {theHor.push(app.activeDocument.guides[m].coordinate)}
};
if (theHor.length != 2 || theVert.length != 2) { alert("Four Guides two vertical and two horizontal are required"); return; } // quit
getTarget=getSelectedLayersIdx();
if (getTarget.length!=1){ alert("The number of layers targeted is " + getTarget.length ); return; } // quit
if (app.activeDocument.activeLayer.isBackgroundLayer ) { alert("Can not resize the background layer"); return; } // quit
if (!app.activeDocument.activeLayer.visible ) { alert("Active layer is not visible"); return; } // quit
//if (hasLayerMask()) { alert("Active layer is Masked"); return; } // quit
if (app.activeDocument.activeLayer.kind == LayerKind.NORMAL || app.activeDocument.activeLayer.kind == LayerKind.SMARTOBJECT && hasLayerMask()) { deleteLayerMask ();}
if (app.activeDocument.activeLayer.kind != LayerKind.NORMAL && app.activeDocument.activeLayer.kind != LayerKind.SMARTOBJECT ) {
alert("Active layer is " + app.activeDocument.activeLayer.kind); return; } // quit
// set selection to the area defined but the guide lines the selection may get undone by the bug in .resize() backing up a step in histoty ???
app.activeDocument.selection.select([[theHor[0], theVert[0]], [theHor[1], theVert[0]], [theHor[1], theVert[1]], [theHor[0], theVert[1]]]);
// resize current normal layer or smart object layer to just cover selection canvas area aspect ratio and size and mask off any overflow
var SB = app.activeDocument.selection.bounds; // Get selection bounds
var SWidth = (SB[2].value) - (SB[0].value); // Area width
var SHeight = (SB[3].value) - (SB[1].value); // Area height
var LB = app.activeDocument.activeLayer.bounds; // Get Active layers bounds
var LWidth = (LB[2].value) - (LB[0].value); // Area width
var LHeight = (LB[3].value) - (LB[1].value); // Area height
var userResampleMethod = app.preferences.interpolation; // Save interpolation settings
app.preferences.interpolation = ResampleMethod.BICUBIC; // resample interpolation bicubic
app.activeDocument.selection.deselect(); // This deselect work around Adobe Bug in CS5, CS6, CC and CC 2014
// Since Adobe does not fix old releases of Photoshop this is a necessary work around for many releases of Photoshop
//alert("Before re-size history"); // Added to debug Adobe Resize Bug
try {
if (LWidth/LHeight<SWidth/SHeight) { // layer's Aspect Ratio less the Canvas area Aspect Ratio
var percentageChange = ((SWidth/LWidth)*100); // Resize to canvas area width
app.activeDocument.activeLayer.resize(percentageChange,percentageChange,AnchorPosition.MIDDLECENTER);
}
else {
var percentageChange = ((SHeight/LHeight)*100); // resize to canvas area height
app.activeDocument.activeLayer.resize(percentageChange,percentageChange,AnchorPosition.MIDDLECENTER);
}
}
catch(e) {
app.preferences.interpolation = userResampleMethod; // Reset interpolation setting
selectFront(); // Photoshop make top layer current when none are targeted
code(); // Retry with top visible layer selected targeted
return; // rest would have been done during the retry
}
//alert("After re-size history"); // Added to debug Adobe Resize Bug
app.preferences.interpolation = userResampleMethod; // Reset interpolation setting
// Seems to be a bug in resize() the document seems to first be backed up a step in history
app.activeDocument.selection.select([[theHor[0], theVert[0]], [theHor[1], theVert[0]], [theHor[1], theVert[1]], [theHor[0], theVert[1]]]); // redo the selection
align('AdCH'); // align to horizontal centers
align('AdCV'); // align to vertical centers
// addLayermask(); // add layer mask to mask off excess
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Helper Functions
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function align(method) {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
desc.putReference( charIDToTypeID( "null" ), ref );
desc.putEnumerated( charIDToTypeID( "Usng" ), charIDToTypeID( "ADSt" ), charIDToTypeID( method ) );
try{executeAction( charIDToTypeID( "Algn" ), desc, DialogModes.NO );}
catch(e){}
}
///////////////////////////////////////////////////////////////////////////////
// Function: hasLayerMask
// Usage: see if there is a raster layer mask
// Input: <none> Must have an open document
// Return: true if there is a vector mask
///////////////////////////////////////////////////////////////////////////////
function hasLayerMask() {
var hasLayerMask = false;
try {
var ref = new ActionReference();
var keyUserMaskEnabled = app.charIDToTypeID( 'UsrM' );
ref.putProperty( app.charIDToTypeID( 'Prpr' ), keyUserMaskEnabled );
ref.putEnumerated( app.charIDToTypeID( 'Lyr ' ), app.charIDToTypeID( 'Ordn' ), app.charIDToTypeID( 'Trgt' ) );
var desc = executeActionGet( ref );
if ( desc.hasKey( keyUserMaskEnabled ) ) { hasLayerMask = true; }
}
catch(e) { hasLayerMask = false; }
return hasLayerMask;
}
function getSelectedLayersIdx(){
var selectedLayers = new Array;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref);
if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){
desc = desc.getList( stringIDToTypeID( 'targetLayers' ));
var c = desc.count
var selectedLayers = new Array();
for(var i=0;i<c;i++){
try{
activeDocument.backgroundLayer;
selectedLayers.push( desc.getReference( i ).getIndex() );
}catch(e){
selectedLayers.push( desc.getReference( i ).getIndex()+1 );
}
}
}else{
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
try{
activeDocument.backgroundLayer;
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);
}catch(e){
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));
}
}
return selectedLayers;
};
function selectFront() {
// Alt+. shortcut select ftont visible layer
var idslct = charIDToTypeID( "slct" );
var desc250 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref207 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idFrnt = charIDToTypeID( "Frnt" );
ref207.putEnumerated( idLyr, idOrdn, idFrnt );
desc250.putReference( idnull, ref207 );
var idMkVs = charIDToTypeID( "MkVs" );
desc250.putBoolean( idMkVs, false );
executeAction( idslct, desc250, DialogModes.NO );
}
function deleteLayerMask (apply) {
// Delet Layer mask default to not apply first
if (apply == undefined) {var apply = false};
try {
var idDlt = charIDToTypeID( "Dlt " );
var desc9 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref5 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idChnl = charIDToTypeID( "Chnl" );
var idMsk = charIDToTypeID( "Msk " );
ref5.putEnumerated( idChnl, idChnl, idMsk );
desc9.putReference( idnull, ref5 );
var idAply = charIDToTypeID( "Aply" );
desc9.putBoolean( idAply, apply );
executeAction( idDlt, desc9, DialogModes.NO );
}
catch (e) {}
};
function addLayermask(){
// Add layer Mask
var idMk = charIDToTypeID( "Mk " );
var desc52 = new ActionDescriptor();
var idNw = charIDToTypeID( "Nw " );
var idChnl = charIDToTypeID( "Chnl" );
desc52.putClass( idNw, idChnl );
var idAt = charIDToTypeID( "At " );
var ref19 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idChnl = charIDToTypeID( "Chnl" );
var idMsk = charIDToTypeID( "Msk " );
ref19.putEnumerated( idChnl, idChnl, idMsk );
desc52.putReference( idAt, ref19 );
var idUsng = charIDToTypeID( "Usng" );
var idUsrM = charIDToTypeID( "UsrM" );
var idRvlS = charIDToTypeID( "RvlS" );
desc52.putEnumerated( idUsng, idUsrM, idRvlS );
executeAction( idMk, desc52, DialogModes.NO );
// Un link layer mask just added fron the layers content
var idsetd = charIDToTypeID( "setd" );
var desc2 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref1.putEnumerated( idLyr, idOrdn, idTrgt );
desc2.putReference( idnull, ref1 );
var idT = charIDToTypeID( "T " );
var desc3 = new ActionDescriptor();
var idUsrs = charIDToTypeID( "Usrs" );
desc3.putBoolean( idUsrs, false );
var idLyr = charIDToTypeID( "Lyr " );
desc2.putObject( idT, idLyr, desc3 );
executeAction( idsetd, desc2, DialogModes.NO );
}
Copy link to clipboard
Copied
Landscape version:
//forums.adobe.com/message/8732179#8732179
//forums.adobe.com/message/8728770#8728770
// 2019 - Uncomment line 123 to enable the layer mask, which has been disabled to retain the proportions of the resized layer
// FitImageToGuides.jsx
/* ==========================================================
// 2014 John J. McAssey (JJMack)
// ======================================================= */
// This script is supplied as is. It is provided as freeware.
// The author accepts no liability for any problems arising from its use.
/* Help Category note tag menu can be used to place script in automate menu
<javascriptresource>
<about>$$$/JavaScripts/FitImageToGuides/About=JJMack's FitImageToGuides .^r^rCopyright 2014 Mouseprints.^r^rFour and only four guides are required</about>
<category>JJMack's Script</category>
</javascriptresource>
*/
// enable double-clicking from Mac Finder or Windows Explorer
#target photoshop
// bring application forward for double-click events
app.bringToFront();
// ensure at least one document open
if (!documents.length) alert('There are no documents open.', 'No Document');
else {
// declare Global variables
//main(); // at least one document exists proceed
app.activeDocument.suspendHistory('Fix Image to Guides','main()'); //problem if there is a selection a layer resize Photoshop back up a history step ?
}
///////////////////////////////////////////////////////////////////////////////
// main function
///////////////////////////////////////////////////////////////////////////////
function main() {
// declare local variables
var orig_ruler_units = app.preferences.rulerUnits;
var orig_type_units = app.preferences.typeUnits;
var orig_display_dialogs = app.displayDialogs;
app.preferences.rulerUnits = Units.PIXELS; // Set the ruler units to PIXELS
app.preferences.typeUnits = TypeUnits.POINTS; // Set Type units to POINTS
app.displayDialogs = DialogModes.NO; // Set Dialogs off
try { code(); }
// display error message if something goes wrong
catch(e) { alert(e + ': on line ' + e.line, 'Script Error', true); }
app.displayDialogs = orig_display_dialogs; // Reset display dialogs
app.preferences.typeUnits = orig_type_units; // Reset ruler units to original settings
app.preferences.rulerUnits = orig_ruler_units; // Reset units to original settings
}
///////////////////////////////////////////////////////////////////////////////
// main function end
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
// The real code is embedded into this function so that at any point it can return
// to the main line function to let it restore users edit environment and end
//////////////////////////////////////////////////////////////////////////////////////////////
function code() {
if (app.activeDocument.guides.length != 4) { alert("Four and only four Guides are required"); return; } // quit
// get guides;
var theVert = new Array;
var theHor = new Array;
for (var m = 0; m < app.activeDocument.guides.length; m++) {
if (app.activeDocument.guides[m].direction == Direction.HORIZONTAL) {theVert.push(app.activeDocument.guides[m].coordinate)}
else {theHor.push(app.activeDocument.guides[m].coordinate)}
};
if (theHor.length != 2 || theVert.length != 2) { alert("Four Guides two vertical and two horizontal are required"); return; } // quit
getTarget=getSelectedLayersIdx();
if (getTarget.length!=1){ alert("The number of layers targeted is " + getTarget.length ); return; } // quit
if (app.activeDocument.activeLayer.isBackgroundLayer ) { alert("Can not resize the background layer"); return; } // quit
if (!app.activeDocument.activeLayer.visible ) { alert("Active layer is not visible"); return; } // quit
//if (hasLayerMask()) { alert("Active layer is Masked"); return; } // quit
if (app.activeDocument.activeLayer.kind == LayerKind.NORMAL || app.activeDocument.activeLayer.kind == LayerKind.SMARTOBJECT && hasLayerMask()) { deleteLayerMask ();}
if (app.activeDocument.activeLayer.kind != LayerKind.NORMAL && app.activeDocument.activeLayer.kind != LayerKind.SMARTOBJECT ) {
alert("Active layer is " + app.activeDocument.activeLayer.kind); return; } // quit
// set selection to the area defined but the guide lines the selection may get undone by the bug in .resize() backing up a step in histoty ???
app.activeDocument.selection.select([[theHor[0], theVert[0]], [theHor[1], theVert[0]], [theHor[1], theVert[1]], [theHor[0], theVert[1]]]);
// resize current normal layer or smart object layer to just cover selection canvas area aspect ratio and size and mask off any overflow
var SB = app.activeDocument.selection.bounds; // Get selection bounds
var SWidth = (SB[2].value) - (SB[0].value); // Area width
var SHeight = (SB[3].value) - (SB[1].value); // Area height
var LB = app.activeDocument.activeLayer.bounds; // Get Active layers bounds
var LWidth = (LB[2].value) - (LB[0].value); // Area width
var LHeight = (LB[3].value) - (LB[1].value); // Area height
var userResampleMethod = app.preferences.interpolation; // Save interpolation settings
app.preferences.interpolation = ResampleMethod.BICUBIC; // resample interpolation bicubic
app.activeDocument.selection.deselect(); // This deselect work around Adobe Bug in CS5, CS6, CC and CC 2014
// Since Adobe does not fix old releases of Photoshop this is a necessary work around for many releases of Photoshop
//alert("Before re-size history"); // Added to debug Adobe Resize Bug
try {
if (LWidth/LHeight<SWidth/SHeight) { // layer's Aspect Ratio less the Canvas area Aspect Ratio
var percentageChange = ((SWidth/LWidth)*100); // Resize to canvas area width
app.activeDocument.activeLayer.resize(percentageChange,percentageChange,AnchorPosition.MIDDLECENTER);
}
else {
// STEPHEN A. MARSH 2019 - EDIT HEIGHT TO WIDTH
var percentageChange = ((SWidth/LWidth)*100); // resize to canvas area width
app.activeDocument.activeLayer.resize(percentageChange,percentageChange,AnchorPosition.MIDDLECENTER);
}
}
catch(e) {
app.preferences.interpolation = userResampleMethod; // Reset interpolation setting
selectFront(); // Photoshop make top layer current when none are targeted
code(); // Retry with top visible layer selected targeted
return; // rest would have been done during the retry
}
//alert("After re-size history"); // Added to debug Adobe Resize Bug
app.preferences.interpolation = userResampleMethod; // Reset interpolation setting
// Seems to be a bug in resize() the document seems to first be backed up a step in history
app.activeDocument.selection.select([[theHor[0], theVert[0]], [theHor[1], theVert[0]], [theHor[1], theVert[1]], [theHor[0], theVert[1]]]); // redo the selection
align('AdCH'); // align to horizontal centers
align('AdCV'); // align to vertical centers
// addLayermask(); // add layer mask to mask off excess
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Helper Functions
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function align(method) {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
desc.putReference( charIDToTypeID( "null" ), ref );
desc.putEnumerated( charIDToTypeID( "Usng" ), charIDToTypeID( "ADSt" ), charIDToTypeID( method ) );
try{executeAction( charIDToTypeID( "Algn" ), desc, DialogModes.NO );}
catch(e){}
}
///////////////////////////////////////////////////////////////////////////////
// Function: hasLayerMask
// Usage: see if there is a raster layer mask
// Input: <none> Must have an open document
// Return: true if there is a vector mask
///////////////////////////////////////////////////////////////////////////////
function hasLayerMask() {
var hasLayerMask = false;
try {
var ref = new ActionReference();
var keyUserMaskEnabled = app.charIDToTypeID( 'UsrM' );
ref.putProperty( app.charIDToTypeID( 'Prpr' ), keyUserMaskEnabled );
ref.putEnumerated( app.charIDToTypeID( 'Lyr ' ), app.charIDToTypeID( 'Ordn' ), app.charIDToTypeID( 'Trgt' ) );
var desc = executeActionGet( ref );
if ( desc.hasKey( keyUserMaskEnabled ) ) { hasLayerMask = true; }
}
catch(e) { hasLayerMask = false; }
return hasLayerMask;
}
function getSelectedLayersIdx(){
var selectedLayers = new Array;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref);
if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){
desc = desc.getList( stringIDToTypeID( 'targetLayers' ));
var c = desc.count
var selectedLayers = new Array();
for(var i=0;i<c;i++){
try{
activeDocument.backgroundLayer;
selectedLayers.push( desc.getReference( i ).getIndex() );
}catch(e){
selectedLayers.push( desc.getReference( i ).getIndex()+1 );
}
}
}else{
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
try{
activeDocument.backgroundLayer;
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);
}catch(e){
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));
}
}
return selectedLayers;
};
function selectFront() {
// Alt+. shortcut select ftont visible layer
var idslct = charIDToTypeID( "slct" );
var desc250 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref207 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idFrnt = charIDToTypeID( "Frnt" );
ref207.putEnumerated( idLyr, idOrdn, idFrnt );
desc250.putReference( idnull, ref207 );
var idMkVs = charIDToTypeID( "MkVs" );
desc250.putBoolean( idMkVs, false );
executeAction( idslct, desc250, DialogModes.NO );
}
function deleteLayerMask (apply) {
// Delet Layer mask default to not apply first
if (apply == undefined) {var apply = false};
try {
var idDlt = charIDToTypeID( "Dlt " );
var desc9 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref5 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idChnl = charIDToTypeID( "Chnl" );
var idMsk = charIDToTypeID( "Msk " );
ref5.putEnumerated( idChnl, idChnl, idMsk );
desc9.putReference( idnull, ref5 );
var idAply = charIDToTypeID( "Aply" );
desc9.putBoolean( idAply, apply );
executeAction( idDlt, desc9, DialogModes.NO );
}
catch (e) {}
};
function addLayermask(){
// Add layer Mask
var idMk = charIDToTypeID( "Mk " );
var desc52 = new ActionDescriptor();
var idNw = charIDToTypeID( "Nw " );
var idChnl = charIDToTypeID( "Chnl" );
desc52.putClass( idNw, idChnl );
var idAt = charIDToTypeID( "At " );
var ref19 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idChnl = charIDToTypeID( "Chnl" );
var idMsk = charIDToTypeID( "Msk " );
ref19.putEnumerated( idChnl, idChnl, idMsk );
desc52.putReference( idAt, ref19 );
var idUsng = charIDToTypeID( "Usng" );
var idUsrM = charIDToTypeID( "UsrM" );
var idRvlS = charIDToTypeID( "RvlS" );
desc52.putEnumerated( idUsng, idUsrM, idRvlS );
executeAction( idMk, desc52, DialogModes.NO );
// Un link layer mask just added fron the layers content
var idsetd = charIDToTypeID( "setd" );
var desc2 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref1.putEnumerated( idLyr, idOrdn, idTrgt );
desc2.putReference( idnull, ref1 );
var idT = charIDToTypeID( "T " );
var desc3 = new ActionDescriptor();
var idUsrs = charIDToTypeID( "Usrs" );
desc3.putBoolean( idUsrs, false );
var idLyr = charIDToTypeID( "Lyr " );
desc2.putObject( idT, idLyr, desc3 );
executeAction( idsetd, desc2, DialogModes.NO );
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now