Photoshop - Get layer bounds

Hi,

I’m struggling to get layer bounds in Photoshop via Adobe framework.

Here is example code:

import sgtk

engine = sgtk.platform.current_engine()
adobe = engine.adobe
active_document = adobe.app.activeDocument
active_layer = active_document.activeLayer

bounds = active_layer.bounds

active_layer.bounds unfortunately returns a list of dictionaries representing UnitValue objects but not the actual object (which, from my understanding, should be an instance of ProxyWrapper).

# Results:
#  [{u'instanceof': u'UnitValue', u'description': u'', u'__uniqueid': 1363, u'help': u'', u'properties': [u'type', u'value', u'baseUnit', u'__proto__'], u'methods': {u'convert': {u'description': u'Convert this instance to a different unit.', u'__uniqueid': 1361, u'dataType': u'boolean', u'help': u'', u'arguments': [{u'dataType': u'string', u'help': u'', u'name': u'unitName', u'description': u'The unit name.'}], u'name': u'convert'}, u'as': {u'description': u'Return this instance as a different unit.', u'__uniqueid': 1362, u'dataType': u'UnitValue', u'help': u'', u'arguments': [{u'dataType': u'string', u'help': u'', u'name': u'unitName', u'description': u'The unit name.'}], u'name': u'as'}}}, {u'instanceof': u'UnitValue', u'description': u'', u'__uniqueid': 1366, u'help': u'', u'properties': [u'type', u'value', u'baseUnit', u'__proto__'], u'methods': {u'convert': {u'description': u'Convert this instance to a different unit.', u'__uniqueid': 1364, u'dataType': u'boolean', u'help': u'', u'arguments': [{u'dataType': u'string', u'help': u'', u'name': u'unitName', u'description': u'The unit name.'}], u'name': u'convert'}, u'as': {u'description': u'Return this instance as a different unit.', u'__uniqueid': 1365, u'dataType': u'UnitValue', u'help': u'', u'arguments': [{u'dataType': u'string', u'help': u'', u'name': u'unitName', u'description': u'The unit name.'}], u'name': u'as'}}}, {u'instanceof': u'UnitValue', u'description': u'', u'__uniqueid': 1369, u'help': u'', u'properties': [u'type', u'value', u'baseUnit', u'__proto__'], u'methods': {u'convert': {u'description': u'Convert this instance to a different unit.', u'__uniqueid': 1367, u'dataType': u'boolean', u'help': u'', u'arguments': [{u'dataType': u'string', u'help': u'', u'name': u'unitName', u'description': u'The unit name.'}], u'name': u'convert'}, u'as': {u'description': u'Return this instance as a different unit.', u'__uniqueid': 1368, u'dataType': u'UnitValue', u'help': u'', u'arguments': [{u'dataType': u'string', u'help': u'', u'name': u'unitName', u'description': u'The unit name.'}], u'name': u'as'}}}, {u'instanceof': u'UnitValue', u'description': u'', u'__uniqueid': 1372, u'help': u'', u'properties': [u'type', u'value', u'baseUnit', u'__proto__'], u'methods': {u'convert': {u'description': u'Convert this instance to a different unit.', u'__uniqueid': 1370, u'dataType': u'boolean', u'help': u'', u'arguments': [{u'dataType': u'string', u'help': u'', u'name': u'unitName', u'description': u'The unit name.'}], u'name': u'convert'}, u'as': {u'description': u'Return this instance as a different unit.', u'__uniqueid': 1371, u'dataType': u'UnitValue', u'help': u'', u'arguments': [{u'dataType': u'string', u'help': u'', u'name': u'unitName', u'description': u'The unit name.'}], u'name': u'as'}}}]

Is this an intended behavior, or simply a limitation of how the bridge to photoshops API was implemented?

Is there a way to somehow capture this objects if we have their serialized representations?

Cheers,
Aleksandar

3 Likes

Isn’t it great that you often ask for help and than actually do what you should have done in the first place?

So yeah, here is the solution (example for upper left x position):

import sgtk
from tk_framework_adobe.rpc.proxy import ProxyWrapper

engine = sgtk.platform.current_engine()
adobe = engine.adobe
active_document = adobe.app.activeDocument
active_layer = active_document.activeLayer
x = ProxyWrapper(active_layer.bounds[0], adobe)

print(x.value)

At least that’s the one I can be satisfied with. If there’s a more “proper” way, I’m all ears. :slight_smile:

3 Likes

I couldn’t tell you unfortunately if there is a better way, but thanks for sharing!

2 Likes

Hey Aleksandar – I’m thinking this is a bug on our end. It’s not intended behavior to have list of unwrapped data returned that way, and I can’t think of any reason why we would want the RPC api to do that.

Your example code is a good workaround for the time being, as it’s more or less exactly what we’d want the api itself to handle for you.

We’ll log a bug ticket for this and take a look when we can. Thanks a ton for pointing it out to us!

2 Likes

Hi Jeff,

Thanks for clarifying that. I’ll go ahead and implement a simple check on what kind of data is returned in these cases and only go for a workaround if its unwrapped (so that we don’t have to change the code once the API gets fixed).

Cheers,
Aleksandar

2 Likes