Skip to main content
Max_Steven
Participant
September 23, 2021
Answered

Create Uniform Color with preset value through python

  • September 23, 2021
  • 1 reply
  • 596 views

Hello Can anyone give me an example like create a uniform color node in current graph and set the output size to 8x8? I want to study python in SD and need some example to move on

Thanks

This topic has been closed for replies.
Correct answer Luca Giarrizzo

Hello @Max_Steven,

 

This should do the trick:

import sd
from sd.api import *

app = sd.getContext().getSDApplication()
ui_mgr = app.getUIMgr()

# Get the graph currently in the currently active Graph view
graph = ui_mgr.getCurrentGraph()

# Create a new Uniform Color node
my_node = graph.newNode("sbs::compositing::uniform")

# Set the inheritance method of the node's Output Size property to Absolute
my_node.setInputPropertyInheritanceMethodFromId(
  "$outputsize",
  sdproperty.SDPropertyInheritanceMethod(2)
  )

# Set the node's Output Size property value to (4, 4)
my_node.setInputPropertyValueFromId(
  "$outputsize",
  sdvalueint2.SDValueInt2.sNew(sdbasetypes.int2(4, 4))
  )

# Set the node's Output Color property value to (1, 1, 0, 1)
my_node.setInputPropertyValueFromId(
  "outputcolor",
  sdvaluefloat4.SDValueFloat4.sNew(sdbasetypes.float4(1, 1, 0, 1))
  )

 

In the Help menu of Substance 3D Designer, you can find the Scripting documentation option which will open the Python API Reference in your web browser. I strongly recommend keeping this resource handy while scripting.

The Scripting section of Designer's documentation will also help get you started.

 

I hope this is helpful!

 

Best regards.

 

1 reply

Luca Giarrizzo
Community Manager
Luca GiarrizzoCommunity ManagerCorrect answer
Community Manager
September 23, 2021

Hello @Max_Steven,

 

This should do the trick:

import sd
from sd.api import *

app = sd.getContext().getSDApplication()
ui_mgr = app.getUIMgr()

# Get the graph currently in the currently active Graph view
graph = ui_mgr.getCurrentGraph()

# Create a new Uniform Color node
my_node = graph.newNode("sbs::compositing::uniform")

# Set the inheritance method of the node's Output Size property to Absolute
my_node.setInputPropertyInheritanceMethodFromId(
  "$outputsize",
  sdproperty.SDPropertyInheritanceMethod(2)
  )

# Set the node's Output Size property value to (4, 4)
my_node.setInputPropertyValueFromId(
  "$outputsize",
  sdvalueint2.SDValueInt2.sNew(sdbasetypes.int2(4, 4))
  )

# Set the node's Output Color property value to (1, 1, 0, 1)
my_node.setInputPropertyValueFromId(
  "outputcolor",
  sdvaluefloat4.SDValueFloat4.sNew(sdbasetypes.float4(1, 1, 0, 1))
  )

 

In the Help menu of Substance 3D Designer, you can find the Scripting documentation option which will open the Python API Reference in your web browser. I strongly recommend keeping this resource handy while scripting.

The Scripting section of Designer's documentation will also help get you started.

 

I hope this is helpful!

 

Best regards.

 

Luca Giarrizzo | Quality Engineer - Substance 3D Designer | Adobe
Max_Steven
Participant
September 23, 2021

Hey,

Thanks for the quick answer

From the comment in your code, I likely understand the flow and the keywords i need

Thank you so so much

Participating Frequently
September 23, 2021

It would be a bit better to write:

my_node.setInputPropertyInheritanceMethodFromId(
  "$outputsize",
  sdproperty.SDPropertyInheritanceMethod.Absolute
  )