Skip to main content
Inspiring
May 4, 2022
Answered

Python API question: Any way to get the graph's size or aspect ratio?

  • May 4, 2022
  • 1 reply
  • 502 views

Really, all I need is the x:y aspect ratio, but I'd by happy to discover a way to get the size as well. The .sbs has a base parameter called "defaultParentSize" which is essentially what I'm looking for, but there doesn't appear to be a way to get it in the python API

Any help would be greatly appreciated.

This topic has been closed for replies.
Correct answer SIE Jake H

I've figured out a hacky workaround until this is officially supported.

 

from sd.api.sdproperty import SDPropertyCategory

def get_graph_resolution(api):
    graph = api.ui_mgr.getCurrentGraph()
    # create a temp output node:
    output_node = graph.newNode('sbs::compositing::output')
    # we have to compute the graph, unfortunately, or else the output node won't have any properties:
    graph.compute()
    # get the output texture:
    properties = output_node.getProperties(SDPropertyCategory.Output)
    texture = output_node.getPropertyValue(properties[0]).get()
    # this is all we need:
    x, y = texture.getSize()
    # delete the output node:
    graph.deleteNode(output_node)
    return x, y

 

There are a few things that aren't ideal about this workaround:

  1.  It (probably) won't work if the file is read-only (I haven't actually tested this, so I don't really know)
  2.  It dirties the scene.
  3.  It requires the graph to be computed, which can be sloooooow.

If anybody has a better solution please let me know.

Thanks!

1 reply

SIE Jake HAuthorCorrect answer
Inspiring
May 5, 2022

I've figured out a hacky workaround until this is officially supported.

 

from sd.api.sdproperty import SDPropertyCategory

def get_graph_resolution(api):
    graph = api.ui_mgr.getCurrentGraph()
    # create a temp output node:
    output_node = graph.newNode('sbs::compositing::output')
    # we have to compute the graph, unfortunately, or else the output node won't have any properties:
    graph.compute()
    # get the output texture:
    properties = output_node.getProperties(SDPropertyCategory.Output)
    texture = output_node.getPropertyValue(properties[0]).get()
    # this is all we need:
    x, y = texture.getSize()
    # delete the output node:
    graph.deleteNode(output_node)
    return x, y

 

There are a few things that aren't ideal about this workaround:

  1.  It (probably) won't work if the file is read-only (I haven't actually tested this, so I don't really know)
  2.  It dirties the scene.
  3.  It requires the graph to be computed, which can be sloooooow.

If anybody has a better solution please let me know.

Thanks!

Luca Giarrizzo
Community Manager
Community Manager
May 5, 2022

Hello @SIE Jake H,

 

This is a nice little hack indeed, well done!

I appreciate wour patience until we expose the defaultParentSize attribute in the Python API.

 

Best regards.

 

Luca Giarrizzo | Quality Engineer - Substance 3D Designer | Adobe