G.H.O.S.T
12-02-2011, 10:23 AM
Hello everyone,
I´m trying to write a python script that will randomly connect attributes of different objects.
Here is what I have:
connections = e.g. connect 3 pCylinders connect to 10 polySpheres(that's why there is "Sph" in partition function.
inputNodes = []
outputNodes = []
selNodes = cm.ls(selection=True)
for nodes in selNodes:
if nodes.partition("Sph")[1] == "Sph":
inputNodes.append(nodes)
if nodes.partition("Sph")[1] != "Sph":
outputNodes.append(nodes)
for node in range(len(inputNodes)):
dividedNum = (len(inputNodes)-1)
i = random.randint(0,dividedNum)
dividedNum = (len(outputNodes)-1)
o = random.randint(0,dividedNum)
if cm.isConnected(outputNodes[o]+".rotateX", inputNodes[i]+".rotateX") == 1:
cm.disconnectAttr(outputNodes[o]+".rotateX", inputNodes[i]+".rotateX")
cm.connectAttr(outputNodes[o]+".rotateX", inputNodes[i]+".rotateX")
the problem is that when code detects connection between objects, instead of disconnect the attributes and then reconnect them it prints error , that attributes are already connected.
This means that somewhere I have and error. But where?
I´m trying to write a python script that will randomly connect attributes of different objects.
Here is what I have:
connections = e.g. connect 3 pCylinders connect to 10 polySpheres(that's why there is "Sph" in partition function.
inputNodes = []
outputNodes = []
selNodes = cm.ls(selection=True)
for nodes in selNodes:
if nodes.partition("Sph")[1] == "Sph":
inputNodes.append(nodes)
if nodes.partition("Sph")[1] != "Sph":
outputNodes.append(nodes)
for node in range(len(inputNodes)):
dividedNum = (len(inputNodes)-1)
i = random.randint(0,dividedNum)
dividedNum = (len(outputNodes)-1)
o = random.randint(0,dividedNum)
if cm.isConnected(outputNodes[o]+".rotateX", inputNodes[i]+".rotateX") == 1:
cm.disconnectAttr(outputNodes[o]+".rotateX", inputNodes[i]+".rotateX")
cm.connectAttr(outputNodes[o]+".rotateX", inputNodes[i]+".rotateX")
the problem is that when code detects connection between objects, instead of disconnect the attributes and then reconnect them it prints error , that attributes are already connected.
This means that somewhere I have and error. But where?
