Accessing Layer Comp position recordings in javascript

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

urbanspaceman
Posts: 8
Joined: Tue Oct 11, 2016 10:12 am

Accessing Layer Comp position recordings in javascript

Post by urbanspaceman »

Great to see this forum up and running again!

Has anyone had experience with Action Manager and the Layer Comp visibility and positioning recording? Where is the position saved, for example, and how do I access it in the javascript environment?
urbanspaceman
Posts: 8
Joined: Tue Oct 11, 2016 10:12 am

Re: Accessing Layer Comp position recordings in javascript

Post by urbanspaceman »

I've been looking at some of the discussions on GitHub concerning Photoshop Generator, and when that plugin exports document information it creates something like this:

Code: Select all


"comps": [{
"name": "Comp 1",
"visibility": true,
"position": true,
"appearance": true,
"hasWarning": false,
"id": 48804065,
"layerSettings": [
{"layerID": 1, "enabled": true },
{"layerID": 12, "enabled": true, "blendOptions": {"mode": "passThrough"} },
{"layerID": 16, "enabled": true, "blendOptions": {"mode": "passThrough"} },
{"layerID": 20, "enabled": true, "offset": {"horizontal": -181, "vertical": -1} },
{"layerID": 22, "enabled": true, "FXRefPoint": {"horizontal": 47.280848, "vertical": 1.925534} },
{"layerID": 27, "enabled": false }
]
}]
So there is layer information inside the layer comps, but I don't know how to reference it in ExtendScript.

I've written my own script to dump the contents of the layer comps and I get this:

Code: Select all


<ActionList> [
0 <Object> : compsClass {
title <String> : "Comp 1"
itemIndex <Integer> : 1
ID <Integer> : 48804065
selection <Boolean> : false
useVisibility <Boolean> : true
usePosition <Boolean> : true
useAppearance <Boolean> : true
}
]
No layer information at all. How does Generator extract that?
urbanspaceman
Posts: 8
Joined: Tue Oct 11, 2016 10:12 am

Re: Accessing Layer Comp position recordings in javascript

Post by urbanspaceman »

Thanks to Thomas Ruark and Tim Wright at Adobe (two Generator developers) for pointing me in the right direction for this. You can get Photoshop to tell you all the Layer Comp settings as a JSON string by using the json property. I've written this function:

Code: Select all

/*---------------------------------------------------*/  
function getJSONStringForComps ()
/*---------------------------------------------------*/
{
var docRef = new ActionReference();
var desc = new ActionDescriptor();
var JSON = stringIDToTypeID("json");
docRef.putProperty(charIDToTypeID('Prpr'), JSON);
docRef.putEnumerated(stringIDToTypeID("document"), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));
desc.putReference(charIDToTypeID('null'), docRef);
desc.putBoolean(stringIDToTypeID("compInfo"), true); // just return the Layer Comp settings
desc.putBoolean(stringIDToTypeID( "getCompLayerSettings" ), true); // return Layer Comp settings for each layer
return executeAction(charIDToTypeID( "getd" ), desc, DialogModes.NO).getString(JSON);
}

Setting 'compInfo' to true will just return the comp settings, and 'getCompLayerSettings' to true will turn the layer information on. The layer values remain hidden without the the last setting turned on. Then you get something like this for the output:

Code: Select all

{  
"id": 326,
"count": 49,
"timeStamp": 1477153891.92,
"version": "1.5.0"
"comps": [
{
"name": "Layer Comp 1",
"position": true,
"visibility": true,
"appearance": false,
"id": 462551238,
"layerSettings": [
{
"layerID": 34,
"enabled": true,
"FXRefPoint": {"horizontal": -576, "vertical": -296},
"vectorMask": {"offset": {"horizontal": -1, "vertical": -1}}
},
{
"layerID": 40,
"enabled": false,
"layerSpecific": {"textLayerSettings": {"textLayerSettingsWarpRect": [0,0,0,0], "warpPerspective": 0, "warpPerspectiveOther": 0,"warpRotate": "horizontal", "warpStyle": "warpNone","warpValue": 0}}
}
],
},
{
"name": "Layer Comp 2",
"position": true,
"visibility": true,
"appearance": false,
"id": 523795946,
"layerSettings": [
{
"layerID": 34,
"enabled": true,
"FXRefPoint": {"horizontal": -576,"vertical": -54},
"offset": {"horizontal": 0, "vertical": 242},
"vectorMask": {"offset": {"horizontal": -1, "vertical": 241}}
},
{
"layerID": 40,
"enabled": false,
"layerSpecific": {"textLayerSettings": {"textLayerSettingsWarpRect": [0,0,0,0], "warpPerspective": 0, "warpPerspectiveOther": 0,"warpRotate": "horizontal", "warpStyle": "warpNone","warpValue": 0}}
}
],
},
{
"name": "Layer Comp 3",
"position": true,
"visibility": true
"appearance": false,
"id": 717392943,
"layerSettings": [
{
"layerID": 34,
"enabled": true,
"FXRefPoint": {"horizontal": -576, "vertical": 220},
"offset": {"horizontal": 0, "vertical": 516},
"vectorMask": {"offset": {"horizontal": -1, "vertical": 515}}
},
{
"layerID": 40,
"enabled": false,
"layerSpecific": {"textLayerSettings": {"textLayerSettingsWarpRect": [0,0,0,0], "warpPerspective": 0, "warpPerspectiveOther": 0,"warpRotate": "horizontal", "warpStyle": "warpNone","warpValue": 0}}
}
],
}
],
}
So I'll have to spend extra time parsing the string to get the info I want, but at least I won't have to apply a Layer Comp to get it's values!
JavierAroche
Posts: 29
Joined: Sat Jul 30, 2016 3:52 am
Location: San Francisco

Re: Accessing Layer Comp position recordings in javascript

Post by JavierAroche »

This is gold man! Why is this not documented?? Did Thomas Ruark and Tim Wright point you to any specific documentation?

I modified your example a bit to get the current document's entire info, including its placed smart objects. It's super fast, just like generator, but from ExtendScript!

It uses the same flags as generator's getDocumentInfo (I haven't tested all of them)
https://github.com/adobe-photoshop/gene ... ntInfo.jsx

Code: Select all


function getDocumentInfo ()  {  
var docRef = new ActionReference();
var desc = new ActionDescriptor();
var JSON = stringIDToTypeID("json");
docRef.putProperty(charIDToTypeID('Prpr'), JSON);
docRef.putEnumerated(stringIDToTypeID("document"), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));
desc.putReference(charIDToTypeID('null'), docRef);
desc.putBoolean(stringIDToTypeID("compInfo"), true);
desc.putBoolean(stringIDToTypeID("imageInfo"), true);
desc.putBoolean(stringIDToTypeID("layerInfo"), true);
desc.putBoolean(stringIDToTypeID("expandSmartObjects"), true);
desc.putBoolean(stringIDToTypeID("getTextStyles"), true);
desc.putBoolean(stringIDToTypeID("getFullTextStyles"), true);
desc.putBoolean(stringIDToTypeID("selectedLayers"), false);
desc.putBoolean(stringIDToTypeID("getCompLayerSettings"), true);
desc.putBoolean(stringIDToTypeID("getDefaultLayerFX"), true);
desc.putBoolean(stringIDToTypeID("getPathData"), true);
return executeAction(charIDToTypeID( "getd" ), desc, DialogModes.NO).getString(JSON);
}
urbanspaceman
Posts: 8
Joined: Tue Oct 11, 2016 10:12 am

Re: Accessing Layer Comp position recordings in javascript

Post by urbanspaceman »

Tim explained by email that asking for the JSON property works like 'sendDocumentInfoToNetworkClient' in Generator but without having to run Generator.

Yes, this might change the way I script Photoshop! I have yet to really explore it's potential. Never seen it documented anywhere.

Tim also pointed me to 'DocumentInfo.jsx' and 'LayerInfo.jsx' in the Photoshop SDK:

photoshopsdk/connectionsdk/samples/mac/networkclientprototype/SampleJSX

http://www.adobe.com/devnet/photoshop/sdk.html