python - connecting ICE nodes

Discussions concerning programming of SOFTIMAGE©
milanvasek
Posts: 143
Joined: 09 Jun 2009, 10:12
Location: Czech Republic

python - connecting ICE nodes

Post by milanvasek » 16 Feb 2012, 13:09

Hi.
I'm sorry for probably some basic question but my knowledge of python is very limited (well i have no idea...)

Here is the image:
Image


and here is my problem:

I create a node (modify shape) with simple python command and I want to plug it into ScatterHub node, "modify" port. But right know it just replaces the connection that is already there. Is there a simple way to find if the port is already connected and if it is, create a new port and connect node there (or if second one is already connected too, create third one etc...)
I was trying to look into ICEflowBuilder, but its just too confusing for me because it uses JS or VB and there is a lot of stuff :)

Please, I would really appreciate any help.
Milan Vasek
ceramic artist & softimage fan
http://www.milanvasek.com

EricTRocks
Moderator
Posts: 754
Joined: 25 Nov 2009, 00:41

Re: python - connecting ICE nodes

Post by EricTRocks » 16 Feb 2012, 13:34

If you can get to the node via scripting the following code may help

Code: Select all


xsi = Application
log = xsi.LogMessage
collSel = xsi.Selection

collPorts = collSel(0).InputPorts
dValuePorts = {}
lValuePorts = [x for x in collPorts if x.Name.startswith("value")]

for eachValPort in lValuePorts:
	dValuePorts[eachValPort.Name] = eachValPort.IsConnected

log(dValuePorts)

you'll want to change the section that says ".startswith()" to whatever the port name you're looking for starts with. So probably ".startswith("modify")
Eric Thivierge
Lead Kraken Developer, Fabric Engine
http://fabric-engine.github.io/Kraken

milanvasek
Posts: 143
Joined: 09 Jun 2009, 10:12
Location: Czech Republic

Re: python - connecting ICE nodes

Post by milanvasek » 16 Feb 2012, 13:44

i can't say i really understand it now, but thanks a lot. i'll try it in the evening when i get back to softimage :)
Milan Vasek
ceramic artist & softimage fan
http://www.milanvasek.com

EricTRocks
Moderator
Posts: 754
Joined: 25 Nov 2009, 00:41

Re: python - connecting ICE nodes

Post by EricTRocks » 16 Feb 2012, 14:08

well it simply demonstrates how you can get the InputPorts of a node and also get whether it is connected or not. Not sure how proficient you are with Python or not but what I did was basically get all the InputPorts whose name starts with "value". Then I add them to a Python dictionary where the port name is the key and true or false depending on whether the port is connected or not. From there you can build logic to create a new port or connect to an open one.
Eric Thivierge
Lead Kraken Developer, Fabric Engine
http://fabric-engine.github.io/Kraken