• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Explorer ,
May 04, 2022 May 04, 2022

Copy link to clipboard

Copied

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

SIEJakeH_0-1651693103610.png

Any help would be greatly appreciated.

TOPICS
Substance Graph

Views

177

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , May 04, 2022 May 04, 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
...

Votes

Translate

Translate
Explorer ,
May 04, 2022 May 04, 2022

Copy link to clipboard

Copied

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
May 05, 2022 May 05, 2022

Copy link to clipboard

Copied

LATEST

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 | QA Analyst, 3D & Immersive | Adobe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines