Skip to main content
Known Participant
August 5, 2024
解決済み

how to get the smart object details

  • August 5, 2024
  • 返信数 4.
  • 1377 ビュー

hi 
i want get the smart object data from the psd file. 

in the above screenshot the layer name "reference-model-night" for that i have linked one jpg file . so the details about that linked layer or smart object layer , image data i want to retrieve 
is there any way to achieve this 
Thanks 

このトピックへの返信は締め切られました。
解決に役立った回答 c.pfaffenbichler
// based on code by michael l hale;
// 2024, use it at your own risk;
if (app.documents.length > 0) {
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var layerDesc = executeActionGet(ref);
var soDesc = layerDesc.getObjectValue(stringIDToTypeID('smartObject'));
checkDesc2 (soDesc, true);
var soMoreDesc = layerDesc.getObjectValue(stringIDToTypeID('smartObjectMore'));
var placedDesc = soDesc.getEnumerationValue(stringIDToTypeID('placed'));
var theFileRef = soDesc.getString(stringIDToTypeID('fileReference'));
var theDocID = soDesc.getString(stringIDToTypeID('documentID'));
var size = soMoreDesc.getObjectValue(stringIDToTypeID('size'));
checkDesc2 (soMoreDesc, true);
var transform = soMoreDesc.getList(stringIDToTypeID("transform"));
var xx = new Array;
for (var m = 0; m < transform.count; m++) {
xx.push(transform.getDouble(m))
};
//alert ("transform\n"+xx.join("\n\n")+"\n\nangle "+getAngle([xx[0], xx[1]], [xx[2], xx[3]]));
var nonAffineTransform = soMoreDesc.getList(stringIDToTypeID("nonAffineTransform"));
var yy = new Array;
for (var n = 0; n < nonAffineTransform.count; n++) {
yy.push(nonAffineTransform.getDouble(n))
};
alert ("nonaffinetransform\n"+yy.join("\n\n")+"\n\nangle "+getAngle([yy[6], yy[7]], [yy[4], yy[5]]));
};
//////
////// radians //////
function radiansOf (theAngle) {
return theAngle * Math.PI / 180
};
////// get an angle, 3:00 being 0˚, 6:00 90˚, etc. //////
function getAngle (pointOne, pointTwo) {
// calculate the triangle sides;
var width = pointTwo[0] - pointOne[0];
var height = pointTwo[1] - pointOne[1];
var sideC = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2)); 
// calculate the angles;
if (width+width > width) {theAngle = Math.asin(height / sideC) * 360 / 2 / Math.PI}
else {theAngle = 180 - (Math.asin(height / sideC) * 360 / 2 / Math.PI)};
if (theAngle < 0) {theAngle = (360 + theAngle)};
//	if (theAngle > 180) {theAngle = (360 - theAngle) * (-1)};
return theAngle
};
////// based on code by michael l hale //////
function checkDesc2 (theDesc, theAlert) {
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';
};
if (theAlert == true) {alert("desc\n\n"+str);
return};
return str
};
////// check //////
function getValues (theDesc, theNumber) {
switch (theDesc.getType(theDesc.getKey(theNumber))) {
case DescValueType.ALIASTYPE:
return theDesc.getPath(theDesc.getKey(theNumber));
break;
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;
};
};

返信数 4

Stephen Marsh
Community Expert
Community Expert
August 8, 2024
c.pfaffenbichler
Community Expert
Community Expert
August 5, 2024
quote

hi 
in the above screenshot the layer name "reference-model-night" for that i have linked one jpg file . 

Your screenshot seems to indicate that you did not link a file, but that you embedded the image. 

c.pfaffenbichler
Community Expert
Community Expert
August 5, 2024

Please explain what you mean. 

Which »data«, »details« do you actually mean? 

 

Edit: Beat my by that much … 

Mahesh12作成者
Known Participant
August 5, 2024

data like layer details, image data, channel details,  path details every i want to retrieve

c.pfaffenbichler
Community Expert
Community Expert
August 5, 2024
quote

data like layer details, image data, channel details,  path details every i want to retrieve

What does this mean? 

Please clarify and post screenshots to illustrate. 

Stephen Marsh
Community Expert
Community Expert
August 5, 2024

Are you looking for a script to:

 

1) Get data about the smart object layer as a layer

 

2) Get data about the smart object as a separate document, as when editing the contents of the layer

 

3) Both 1 and 2

 

And furthermore, what specific information are you looking for and how should it be reported/indicated by the script? What is the purpose of the information? To be read and understood by the user? To be read and used by a script?

Mahesh12作成者
Known Participant
August 5, 2024

both 1 and 2

Mahesh12作成者
Known Participant
August 6, 2024

Did you test the code I posted? 


yes thanks @c.pfaffenbichler