My current script is able to analyze the font attributes and display the info as a text layer such as font, type, size, color, justification.
I'd like to do the same thing for layer and shapes, where I'd like to get some script that will analyze "existing" effects/shape attributes, such as color, size, stroke, shadow, gradient, ....etc.
Does anyone know of how to do this with script? I just need the code snippet for this, so my friend can help me fully realize this script.
See my attached file for what I mean.
Thx.
Layer Styles & Shapes (Existing Effects & Attributes)
Layer Styles & Shapes (Existing Effects & Attributes)
The following code can be used to asses Layer Styles if such are present.
The line
Code: Select allcheckDesc2 (effectsDesc);
should present you with a list of the keys that are there (checking first or wrapping it in a try clause might be a good idea) and
Code: Select allcheckDesc2 (dropShadow);
should present you with a list of the parameters of Drop Shadow. (Again checking first …)
Code: Select all// get keys for type layer’s style;
// based on code by michael l hale;
// 2013, use it at your own risk;
#target photoshop
if (app.documents.length > 0) {
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var layerDesc = executeActionGet(ref);
var effectsDesc = layerDesc.getObjectValue(stringIDToTypeID('layerEffects'));
checkDesc2 (effectsDesc);
var dropShadow = effectsDesc.getObjectValue(stringIDToTypeID('dropShadow'));
checkDesc2 (dropShadow);
};
//////
// by michael l hale;
function checkDesc (theDesc) {
var c = theDesc.count;
var str = '';
for(var i=0;i<c;i++){ //enumerate descriptor's keys
str = str + 'Key '+i+' = '+typeIDToStringID(theDesc.getKey(i))+': '+theDesc.getType(theDesc.getKey(i))+'\n';
};
alert("desc\n\n"+str);
};
////// based on code by michael l hale //////
function checkDesc2 (theDesc) {
var c = theDesc.count;
var str = '';
for(var i=0;i<c;i++){ //enumerate descriptor's keys
str = str + 'Key '+i+' = '+typeIDToStringID(theDesc.getKey(i))+': '+theDesc.getType(theDesc.getKey(i))+'\n'+getValues (theDesc, i)+'\n';
};
alert("desc\n\n"+str);
};
////// check //////
function getValues (theDesc, theNumber) {
switch (theDesc.getType(theDesc.getKey(theNumber))) {
case DescValueType.BOOLEANTYPE:
return theDesc.getBoolean(theDesc.getKey(theNumber));
break;
case DescValueType.CLASSTYPE:
return theDesc.getClass(theDesc.getKey(theNumber));
break;
case DescValueType.DOUBLETYPE:
return theDesc.getDouble(theDesc.getKey(theNumber));
break;
case DescValueType.ENUMERATEDTYPE:
return (typeIDToStringID(theDesc.getEnumerationValue(theDesc.getKey(theNumber)))+"_"+typeIDToStringID(theDesc.getEnumerationType(theDesc.getKey(theNumber))));
break;
case DescValueType.INTEGERTYPE:
return theDesc.getInteger(theDesc.getKey(theNumber));
break;
case DescValueType.LISTTYPE:
return theDesc.getList(theDesc.getKey(theNumber));
break;
case DescValueType.OBJECTTYPE:
return (theDesc.getObjectValue(theDesc.getKey(theNumber))+"_"+typeIDToStringID(theDesc.getObjectType(theDesc.getKey(theNumber))));
break;
case DescValueType.REFERENCETYPE:
return theDesc.getReference(theDesc.getKey(theNumber));
break;
case DescValueType.STRINGTYPE:
return theDesc.getString(theDesc.getKey(theNumber));
break;
case DescValueType.UNITDOUBLE:
return (theDesc.getUnitDoubleValue(theDesc.getKey(theNumber))+"_"+typeIDToStringID(theDesc.getUnitDoubleType(theDesc.getKey(theNumber))));
break;
default:
break;
};
};
The line
Code: Select allcheckDesc2 (effectsDesc);
should present you with a list of the keys that are there (checking first or wrapping it in a try clause might be a good idea) and
Code: Select allcheckDesc2 (dropShadow);
should present you with a list of the parameters of Drop Shadow. (Again checking first …)
Code: Select all// get keys for type layer’s style;
// based on code by michael l hale;
// 2013, use it at your own risk;
#target photoshop
if (app.documents.length > 0) {
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var layerDesc = executeActionGet(ref);
var effectsDesc = layerDesc.getObjectValue(stringIDToTypeID('layerEffects'));
checkDesc2 (effectsDesc);
var dropShadow = effectsDesc.getObjectValue(stringIDToTypeID('dropShadow'));
checkDesc2 (dropShadow);
};
//////
// by michael l hale;
function checkDesc (theDesc) {
var c = theDesc.count;
var str = '';
for(var i=0;i<c;i++){ //enumerate descriptor's keys
str = str + 'Key '+i+' = '+typeIDToStringID(theDesc.getKey(i))+': '+theDesc.getType(theDesc.getKey(i))+'\n';
};
alert("desc\n\n"+str);
};
////// based on code by michael l hale //////
function checkDesc2 (theDesc) {
var c = theDesc.count;
var str = '';
for(var i=0;i<c;i++){ //enumerate descriptor's keys
str = str + 'Key '+i+' = '+typeIDToStringID(theDesc.getKey(i))+': '+theDesc.getType(theDesc.getKey(i))+'\n'+getValues (theDesc, i)+'\n';
};
alert("desc\n\n"+str);
};
////// check //////
function getValues (theDesc, theNumber) {
switch (theDesc.getType(theDesc.getKey(theNumber))) {
case DescValueType.BOOLEANTYPE:
return theDesc.getBoolean(theDesc.getKey(theNumber));
break;
case DescValueType.CLASSTYPE:
return theDesc.getClass(theDesc.getKey(theNumber));
break;
case DescValueType.DOUBLETYPE:
return theDesc.getDouble(theDesc.getKey(theNumber));
break;
case DescValueType.ENUMERATEDTYPE:
return (typeIDToStringID(theDesc.getEnumerationValue(theDesc.getKey(theNumber)))+"_"+typeIDToStringID(theDesc.getEnumerationType(theDesc.getKey(theNumber))));
break;
case DescValueType.INTEGERTYPE:
return theDesc.getInteger(theDesc.getKey(theNumber));
break;
case DescValueType.LISTTYPE:
return theDesc.getList(theDesc.getKey(theNumber));
break;
case DescValueType.OBJECTTYPE:
return (theDesc.getObjectValue(theDesc.getKey(theNumber))+"_"+typeIDToStringID(theDesc.getObjectType(theDesc.getKey(theNumber))));
break;
case DescValueType.REFERENCETYPE:
return theDesc.getReference(theDesc.getKey(theNumber));
break;
case DescValueType.STRINGTYPE:
return theDesc.getString(theDesc.getKey(theNumber));
break;
case DescValueType.UNITDOUBLE:
return (theDesc.getUnitDoubleValue(theDesc.getKey(theNumber))+"_"+typeIDToStringID(theDesc.getUnitDoubleType(theDesc.getKey(theNumber))));
break;
default:
break;
};
};
Layer Styles & Shapes (Existing Effects & Attributes)
You are combining different things. To me it looks like you are getting the frist item from the adjustment layer type, the second from the layer styles, and the last two from the layer's vector mask.
For the first item you can get the type using layer.kind. This will get you the color if it's a solidfill/shape layer.Code: Select allfunction getFillColor(){
var ref = new ActionReference();
ref.putEnumerated( stringIDToTypeID( "contentLayer" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ));
var ref1= executeActionGet( ref );
var list = ref1.getList( charIDToTypeID( "Adjs" ) ) ;
var solidColorLayer = list.getObjectValue(0);
var color = solidColorLayer.getObjectValue(charIDToTypeID('Clr '));
var fillcolor = new SolidColor;
fillcolor.rgb.red = color.getDouble(charIDToTypeID('Rd '));
fillcolor.rgb.green = color.getDouble(charIDToTypeID('Grn '));
fillcolor.rgb.blue = color.getDouble(charIDToTypeID('Bl '));
return fillcolor.rgb.hexValue;
};gradient is harder because I think you would need more info that you show to recreate.
There are a lot of settings in layer styles. Here is an example to get the stroke's styleCode: Select allfunction getLayerStyles(layerDesc){// layerDesc optional - allows getting styles by index, id, or name. default is activeLayer
if(undefined == layerDesc){
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
var layerDesc = executeActionGet(ref);
}
if(layerDesc.hasKey(stringIDToTypeID('layerEffects'))){
stylesDesc = layerDesc.getObjectValue(stringIDToTypeID('layerEffects'));
var styles = {};
styles.toString = function(){return 'LayerStyles';}
styles.count = 0;
if(stylesDesc.hasKey( stringIDToTypeID('frameFX') )) {
styles['stroke'] = stylesDesc.getObjectValue( stringIDToTypeID('frameFX') ); styles.count++;
var amStyle = typeIDToStringID(styles['stroke'].getEnumerationValue(charIDToTypeID( 'Styl' ))).replace('Frame','');
switch (amStyle){
case 'outset': styles['stroke'].style = 'Outside';break;
case 'inset': styles['stroke'].style = 'Inside';break;
case 'centered': styles['stroke'].style = 'Center';break;
}
// set other needed properties
}
/*
additional if block for the other effects you need
*/
return styles;
}
};
alert('Stroke: '+getLayerStyles().stroke.style);You or your friend can expand this function for the other effects and properties needed.
The last two come from the vector mask path. Size should be easy to determine from the path points. It may be possible to determine the radius of the corners but that need better math skills than I have.
For the first item you can get the type using layer.kind. This will get you the color if it's a solidfill/shape layer.Code: Select allfunction getFillColor(){
var ref = new ActionReference();
ref.putEnumerated( stringIDToTypeID( "contentLayer" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ));
var ref1= executeActionGet( ref );
var list = ref1.getList( charIDToTypeID( "Adjs" ) ) ;
var solidColorLayer = list.getObjectValue(0);
var color = solidColorLayer.getObjectValue(charIDToTypeID('Clr '));
var fillcolor = new SolidColor;
fillcolor.rgb.red = color.getDouble(charIDToTypeID('Rd '));
fillcolor.rgb.green = color.getDouble(charIDToTypeID('Grn '));
fillcolor.rgb.blue = color.getDouble(charIDToTypeID('Bl '));
return fillcolor.rgb.hexValue;
};gradient is harder because I think you would need more info that you show to recreate.
There are a lot of settings in layer styles. Here is an example to get the stroke's styleCode: Select allfunction getLayerStyles(layerDesc){// layerDesc optional - allows getting styles by index, id, or name. default is activeLayer
if(undefined == layerDesc){
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
var layerDesc = executeActionGet(ref);
}
if(layerDesc.hasKey(stringIDToTypeID('layerEffects'))){
stylesDesc = layerDesc.getObjectValue(stringIDToTypeID('layerEffects'));
var styles = {};
styles.toString = function(){return 'LayerStyles';}
styles.count = 0;
if(stylesDesc.hasKey( stringIDToTypeID('frameFX') )) {
styles['stroke'] = stylesDesc.getObjectValue( stringIDToTypeID('frameFX') ); styles.count++;
var amStyle = typeIDToStringID(styles['stroke'].getEnumerationValue(charIDToTypeID( 'Styl' ))).replace('Frame','');
switch (amStyle){
case 'outset': styles['stroke'].style = 'Outside';break;
case 'inset': styles['stroke'].style = 'Inside';break;
case 'centered': styles['stroke'].style = 'Center';break;
}
// set other needed properties
}
/*
additional if block for the other effects you need
*/
return styles;
}
};
alert('Stroke: '+getLayerStyles().stroke.style);You or your friend can expand this function for the other effects and properties needed.
The last two come from the vector mask path. Size should be easy to determine from the path points. It may be possible to determine the radius of the corners but that need better math skills than I have.
Layer Styles & Shapes (Existing Effects & Attributes)
great man, thank you very much for both your help and insight on this....