Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Dynamic input port handling for Python Nodes in XPresso (Cinema 4D).
import c4d
numerical_types = (
c4d.ID_GV_VALUE_TYPE_REAL, c4d.ID_GV_VALUE_TYPE_INTEGER,
c4d.DA_LONG, c4d.DA_REAL, c4d.DA_LLONG,
)
def main():
# Node output ports.
global Minimum, Maximum
Minimum = NotImplemented
Maximum = NotImplemented
# Only accept connected input port values?
only_connected = op[c4d.ID_USERDATA, 1]
# Iterate over the input ports of the node and
# handle the incoming port values.
for i in xrange(op.GetInPortCount()):
port = op.GetInPort(i)
# If specified in the UserData of the Node,
# we should only take the value of ports into
# consideration that are actually connectes.
# We also only ignore the Ports' value if its
# datatype is not numerical.
dtype = port.GetValueType()
connected = port.IsIncomingConnected() or not only_connected
if dtype in numerical_types and connected:
# Retrieve the value from the global scope by
# the name of the port.
v = globals()[port.GetName(op)]
if Minimum is NotImplemented or v < Minimum:
Minimum = v
if Maximum is NotImplemented or v > Maximum:
Maximum = v
# Set the Maximum and Minimum output values to the default
# if no values have been directed into the input ports
# of this node.
if Minimum is NotImplemented:
Minimum = op[c4d.ID_USERDATA, 2]
if Maximum is NotImplemented:
Maximum = op[c4d.ID_USERDATA, 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.