Inspecting ICE node connections from Python

72 views
Skip to first unread message

James Vecore

unread,
Jun 18, 2013, 2:10:50 PM6/18/13
to soft...@listproc.autodesk.com

I’m looking for a way to inspect the connections between ice nodes from Python. I’m trying to write a tool that will generate and update an ice graph on demand based on some parameters. I need to be able to inspect an existing ice graph and most importantly the connections between nodes in the ICE graph. I can’t seem to find how to do this in the docs. All I see related to node connections is ConnectICENode. Ideally I would like something like this AreICENodesConnected(outputPort, inputPort) or a way to enumerate connections but I don’t see anything available.

 

Am I missing something or is this just not possible from the Scripting API?

 

Thanks,

 

-James

 

James Vecore  |  Pluto  |  A Creative Content Place  |  hellopluto.com  |  248.723.3333 | 586.295.9473 mobile

 

Steven Caron

unread,
Jun 18, 2013, 2:18:43 PM6/18/13
to soft...@listproc.autodesk.com
you want the ICENodePort class...


example code...

from siutils import si
si = si() # win32com.client.Dispatch('XSI.Application')
from siutils import log # LogMessage
from siutils import disp # win32com.client.Dispatch
from siutils import C # win32com.client.constants

for op in si.Selection(0).ActivePrimitive.ConstructionHistory:
    if op.Type == "ICETree":
        ICETree = op
        lastPort = list(ICETree.InputPorts)[-1]
        if lastPort.IsConnected:
            si.AddPortToICENode( lastPort, "siNodePortDataInsertionLocationAfter" )
            lastPort = list(ICETree.InputPorts)[-1]
        log(lastPort.Name)

James Vecore

unread,
Jun 18, 2013, 2:43:19 PM6/18/13
to soft...@listproc.autodesk.com

Thanks for the reply Steve.

 

I should have been more specific in my question. IsConnect does tell if the port is connected and I had picked that up from the docs, but I don’t see a way to traverse backwards to the icenode that is feeding an input node. For example, lets say I have a GetData node (Node A) and a custom ICECompound (Node B). Node A is connected to an known input port in Node B.  So if I have a reference to Node B and the input port I’m interested in, how could find out that Node A is what is connected to that port? If you take the inputPort.Value you will get None if the value is a complex type (and the docs say these are not supported). The docs reference using ICENodePort.Parameters for types that are not supported by ICENodeInputPort.Value. However, inputPort.Parameters.Count == 0 and enumerating over it gives:

 

# WARNING : 3407 - Values cannot be accessed on connected ports: <Port: input_null>

 

I also searched all the commands with “ICE” in them and didn’t see anything that makes sense for my scenario.

 

Any Ideas?

 

-James

Steven Caron

unread,
Jun 18, 2013, 3:10:05 PM6/18/13
to soft...@listproc.autodesk.com
oh right, you want 'ConnectedPorts' and 'ConnectedNodes' property of an ICENodePort class. this example isn't a proper step through the graph but it shows you what you want... i think :)

from siutils import si
si = si() # win32com.client.Dispatch('XSI.Application')
from siutils import log # LogMessage
from siutils import disp # win32com.client.Dispatch
from siutils import C # win32com.client.constants

for op in si.Selection(0).ActivePrimitive.ConstructionHistory:
    if op.Type == "ICETree":
        ICETree = op
        # output port direction
        log("output ports")
        for node in op.Nodes:
            for port in node.OutputPorts:
                for connectedPort,connectedNode in zip(port.ConnectedPorts, port.ConnectedNodes):
                    log("%s.%s -> %s.%s" % (node.Name, port.Name, connectedNode.Name, connectedPort.Name))
        # input port direction
        log("input ports")
        for node in op.Nodes:
            for port in node.InputPorts:
                for connectedPort,connectedNode in zip(port.ConnectedPorts, port.ConnectedNodes):
                    log("%s.%s -> %s.%s" % (node.Name, port.Name, connectedNode.Name, connectedPort.Name))

James Vecore

unread,
Jun 18, 2013, 3:21:23 PM6/18/13
to soft...@listproc.autodesk.com

Ah perfect, Thanks!

 

Not sure how I missed that one. I was digging through commands and must have overlooked those Properties.

 

Thank you,

Steven Caron

unread,
Jun 18, 2013, 3:29:20 PM6/18/13
to soft...@listproc.autodesk.com
no sweat, it was a good reminder for me also :)
Reply all
Reply to author
Forward
0 new messages