Photoshop JavaScript Bug: smartObject’s compID returns nonsense

  • 3
  • Problem
  • Updated 2 years ago
Over at this thread
https://feedback.photoshop.com/photoshop_family/topics/ps-script-how-to-get-list-of-layer-comps-in-s...
MrCox made this statement: 
»OK, Smart Object descriptor info does include the ID of the currently selected comp for the child document, which will be -1 if none are selected.«

Unfortunately in my tests compID consistently returns nonsense. In this file 
http://transfer.viennapaint.com/index.php/s/1V78YMZBJjboTCO
three instances of the same Smart Object each have a different Layer Comp applied but with below code (which lists name, ID, compID and originalCompID for as Smart Objects) I get -1 as compID for all of them with Photoshop CC 2015.1.2 on OSX 10.11.4. 


So there seem to be two possibilities: 
• I am doing something wrong or have misunderstood the statement 
• The feature has been implemented with a bug 

A clarification either way would be welcome, thanks in advance. 
Regards, 
Pfaffenbichler 

#target photoshop
if (app.documents.length > 0) {
main ()
};
////////////////////////////////////
function main () {
// the file;
var myDocument = app.activeDocument;
// get number of layers;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
$.writeln("___"+theNumber+"___");
// process the layers;
var theLayers = new Array;
for (var m = 0; m <= theNumber; m++) {
$.writeln(m+"___");
try {
var ref = new ActionReference();
ref.putIndex( charIDToTypeID( "Lyr " ), m);
var layerDesc = executeActionGet(ref);
var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));
// if not layer group collect values;
if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart" && isBackground != true) {
// if smart objects;
if (layerDesc.hasKey(stringIDToTypeID("smartObject")) == true) {
var theSO = layerDesc.getObjectValue(stringIDToTypeID("smartObject"));
var theCompsList = theSO.getObjectValue(stringIDToTypeID("compsList"));
var xxx = theCompsList.getInteger(stringIDToTypeID("compID"));
var yyy = theCompsList.getInteger(stringIDToTypeID("originalCompID"));
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
theLayers.push([theName, theID, xxx, yyy]);
};
};
}
catch (e) {};
};
alert ("\n"+theLayers.join("\n"));
};
Photo of christoph pfaffenbichler

christoph pfaffenbichler, Champion

  • 1232 Posts
  • 178 Reply Likes

Posted 3 years ago

  • 3
Photo of Max Johnson

Max Johnson, Champion

  • 488 Posts
  • 235 Reply Likes
Yep. Only the Generator seems to correctly get the correct applied CompId and you have to write your own Generator plugin (I think) to get it to send you the json info over a socket. Not very scriptable.
Photo of christoph pfaffenbichler

christoph pfaffenbichler, Champion

  • 1232 Posts
  • 178 Reply Likes
Dang, I have no grasp on Generator-scripting or -plug-ins ... 

In another thread someone posted this link 
http://www.tonton-pixel.com/blog/scripts/utility-scripts/get-document-info-code/
and I’ll have to try and see if I can utilise some code from that Script. 
Photo of Max Johnson

Max Johnson, Champion

  • 488 Posts
  • 235 Reply Likes
Just tested on the new 2015.5 update and this is still broken. :(
Photo of Jaroslav Bereza

Jaroslav Bereza

  • 809 Posts
  • 187 Reply Likes
I did workaround which is implemented here: http://bereza.cz/ps/ (Unsmart) works good for me, but it's definitely not best solution. There is small posibility to get wrong comp and not good for performance, but it works.
Photo of christoph pfaffenbichler

christoph pfaffenbichler, Champion

  • 1232 Posts
  • 178 Reply Likes
When it comes to bug-fixing Adobe’s priorities can seem peculiar at times ... 

I cannot estimate the hours it would take to fix this one and Photoshop Scripting hardly seems Photoshop-user-mainstream but should known bugs not get fixed simply because they are there? 
Photo of christoph pfaffenbichler

christoph pfaffenbichler, Champion

  • 1232 Posts
  • 178 Reply Likes
Jaroslav Bereza and Max Johnson have thankfully pointed out that the issue has been resolved in another thread. 

var ref = new ActionReference();ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var layerDesc = executeActionGet(ref);
var theSOMore = layerDesc.getObjectValue(stringIDToTypeID("smartObjectMore"));
alert (theSOMore.getInteger(stringIDToTypeID("comp")));
(Edited)