User Guide Cancel

Nodes and properties | Substance 3D Designer

Nodes and properties

The SDNode class enables users to get information about specific nodes, which properties can be accessed with the SDProperty class. All of these can be either read of modified.

Available node information include:

  • definition
  • identifier
  • position
  • bounding box
  • properties (as a list)
  • resources that are being referenced

Accessing nodes and their properties

import sd
# Import the required classes.
from sd.api.sdproperty import SDPropertyCategory
from sd.api.sdvalueserializer import SDValueSerializer
# Get and print information regarding the selected nodes.
def printSelectedNodesInfo(nodes):
for node in nodes:
definition = node.getDefinition()
nodeId = node.getIdentifier()
print("node %s, id = %s" % (definition.getLabel(), nodeId))
# Create a list of each property category enumeration item.
categories = [
SDPropertyCategory.Annotation,
SDPropertyCategory.Input,
SDPropertyCategory.Output
]
# Get node properties for each property category.
for category in categories:
props = definition.getProperties(category)
# Get the label and identifier of each property.
for prop in props:
label = prop.getLabel()
propId = prop.getId()
# Get the connection for the currently accessed property.
if prop.isConnectable():
connections = node.getPropertyConnections(prop)
if connections:
print("Propery %s is connected!!!" % label)
continue
# Get the current and default values for the currently accessed property.
value = node.getPropertyValue(prop)
valueDefault = prop.getDefaultValue()
value = SDValueSerializer.sToString(value) if value else "None"
valueDefault = SDValueSerializer.sToString(valueDefault) if valueDefault else "None"
print("Property - %sn id = %sn value = %sn default = %s" % (
label,
propId,
value,
valueDefault
))
import sd # Import the required classes. from sd.api.sdproperty import SDPropertyCategory from sd.api.sdvalueserializer import SDValueSerializer # Get and print information regarding the selected nodes. def printSelectedNodesInfo(nodes): for node in nodes: definition = node.getDefinition() nodeId = node.getIdentifier() print("node %s, id = %s" % (definition.getLabel(), nodeId)) # Create a list of each property category enumeration item. categories = [ SDPropertyCategory.Annotation, SDPropertyCategory.Input, SDPropertyCategory.Output ] # Get node properties for each property category. for category in categories: props = definition.getProperties(category) # Get the label and identifier of each property. for prop in props: label = prop.getLabel() propId = prop.getId() # Get the connection for the currently accessed property. if prop.isConnectable(): connections = node.getPropertyConnections(prop) if connections: print("Propery %s is connected!!!" % label) continue # Get the current and default values for the currently accessed property. value = node.getPropertyValue(prop) valueDefault = prop.getDefaultValue() value = SDValueSerializer.sToString(value) if value else "None" valueDefault = SDValueSerializer.sToString(valueDefault) if valueDefault else "None" print("Property - %sn id = %sn value = %sn default = %s" % ( label, propId, value, valueDefault ))
import sd 
# Import the required classes. 
from sd.api.sdproperty import SDPropertyCategory 
from sd.api.sdvalueserializer import SDValueSerializer 
  
# Get and print information regarding the selected nodes. 
def printSelectedNodesInfo(nodes): 
    for node in nodes: 
        definition = node.getDefinition() 
        nodeId = node.getIdentifier() 
  
        print("node %s, id = %s" % (definition.getLabel(), nodeId)) 
  
        # Create a list of each property category enumeration item. 
        categories = [ 
            SDPropertyCategory.Annotation, 
            SDPropertyCategory.Input, 
            SDPropertyCategory.Output 
        ] 
  
        # Get node properties for each property category. 
        for category in categories: 
            props = definition.getProperties(category) 
  
            # Get the label and identifier of each property. 
            for prop in props: 
                label = prop.getLabel() 
                propId = prop.getId() 
  
                # Get the connection for the currently accessed property. 
                if prop.isConnectable(): 
                    connections = node.getPropertyConnections(prop) 
  
                    if connections: 
                        print("Propery %s is connected!!!" % label) 
                        continue 
  
                # Get the current and default values for the currently accessed property. 
                value = node.getPropertyValue(prop) 
                valueDefault = prop.getDefaultValue() 
     
                value = SDValueSerializer.sToString(value) if value else "None" 
                valueDefault = SDValueSerializer.sToString(valueDefault) if valueDefault else "None" 
 
                print("Property - %sn  id = %sn  value = %sn  default = %s" % ( 
                    label, 
                    propId, 
                    value, 
                    valueDefault 
                 ))

Accessing node inputs identifiers and types

import sd
# Import the required classes.
from sd.api import sduimgr
from sd.api.sdproperty import *
# Access a node in the current graph, and its properties.
graph = uiMgr.getCurrentGraph()
node = graph.getNodeFromId('<Replace this text with the node ID>')
nodeProps = node.getProperties(SDPropertyCategory.Input)
# List node identifiers and types in console.
for i in range(len(nodeProps)):
print(nodeProps[i].getId())
print(nodeProps[i].getType())
import sd # Import the required classes. from sd.api import sduimgr from sd.api.sdproperty import * # Access a node in the current graph, and its properties. graph = uiMgr.getCurrentGraph() node = graph.getNodeFromId('<Replace this text with the node ID>') nodeProps = node.getProperties(SDPropertyCategory.Input) # List node identifiers and types in console. for i in range(len(nodeProps)): print(nodeProps[i].getId()) print(nodeProps[i].getType())
import sd 
# Import the required classes. 
from sd.api import sduimgr 
from sd.api.sdproperty import * 
 
# Access a node in the current graph, and its properties. 
graph = uiMgr.getCurrentGraph() 
node = graph.getNodeFromId('<Replace this text with the node ID>') 
nodeProps = node.getProperties(SDPropertyCategory.Input) 
 
# List node identifiers and types in console. 
for i in range(len(nodeProps)): 
 print(nodeProps[i].getId()) 
 print(nodeProps[i].getType())

Accessing node Position and bounding box

import sd
app = sd.getContext().getSDApplication()
uiMgr = app.getUIMgr()
currentGraph = uiMgr.getCurrentGraph()
# Works reliably if there is only one Graph View
currentGraphViewID = uiMgr.getGraphViewIDAt(0)
for node in currentGraph.getNodes():
# Position is accessed directly through the node
nodePosition = node.getPosition()
# Bbox is accessed through the UI manager and the Graph View ID
nodeBbox = uiMgr.getGraphNodeBBox(currentGraphViewID, node)
print(f"""
{node.getDefinition().getLabel().upper()}
UID: {node.getIdentifier()}
Position:
- Center X: {nodePosition.x}
- Center Y: {nodePosition.y}
Bounding box:
- Top-left X: {nodeBbox.x}
- Top-left Y: {nodeBbox.y}
- Width: {nodeBbox.z}
- Height: {nodeBbox.w}
""")
import sd app = sd.getContext().getSDApplication() uiMgr = app.getUIMgr() currentGraph = uiMgr.getCurrentGraph() # Works reliably if there is only one Graph View currentGraphViewID = uiMgr.getGraphViewIDAt(0) for node in currentGraph.getNodes(): # Position is accessed directly through the node nodePosition = node.getPosition() # Bbox is accessed through the UI manager and the Graph View ID nodeBbox = uiMgr.getGraphNodeBBox(currentGraphViewID, node) print(f""" {node.getDefinition().getLabel().upper()} UID: {node.getIdentifier()} Position: - Center X: {nodePosition.x} - Center Y: {nodePosition.y} Bounding box: - Top-left X: {nodeBbox.x} - Top-left Y: {nodeBbox.y} - Width: {nodeBbox.z} - Height: {nodeBbox.w} """)
import sd

app = sd.getContext().getSDApplication()

uiMgr = app.getUIMgr()
currentGraph = uiMgr.getCurrentGraph()

# Works reliably if there is only one Graph View
currentGraphViewID = uiMgr.getGraphViewIDAt(0)

for node in currentGraph.getNodes():
	
	# Position is accessed directly through the node
	nodePosition = node.getPosition()
	# Bbox is accessed through the UI manager and the Graph View ID	
	nodeBbox = uiMgr.getGraphNodeBBox(currentGraphViewID, node)
	
	print(f"""
	
{node.getDefinition().getLabel().upper()}
  UID: {node.getIdentifier()}
  Position:
    - Center X: {nodePosition.x}
    - Center Y: {nodePosition.y}
  Bounding box:
    - Top-left X: {nodeBbox.x}
    - Top-left Y: {nodeBbox.y}
    - Width: {nodeBbox.z}
    - Height: {nodeBbox.w}
""")

Get help faster and easier

New user?