'Python replication of an Ncloth and nucleus in Maya
Can someone please complete this code?
# create a cloth node
mesh = cmds.ls(sl=True)[0]
nCloth = cmds.createNode("nCloth")
nucleus = cmds.createNode("nucleus")
# connect time node
cmds.connectAttr("time1.outTime", nCloth + ".currentTime")
# connect your mesh to the ncloth
cmds.connectAttr(mesh + ".worldMesh", nCloth + ".inputMesh")
# create an output shape that will be the simulation mesh
outMesh = cmds.createNode("mesh", parent=mesh, name='outmesh')
cmds.connectAttr(nCloth + ".outputMesh", outMesh + ".inMesh")
# connect the startframe
cmds.connectAttr(nucleus + ".startFrame", nCloth + ".startFrame")
# Connect the cloth node to the nucleus with an available ID
cmds.connectAttr(nCloth + ".currentState", nucleus +".inputActive[{}]".format(index), f=1)
cmds.connectAttr(nCloth + ".startState", nucleus + ".inputActiveStart[{}]", f=1)
# force the refresh when used in batch
cmds.getAttr(cloth + ".forceDynamics")
There are still many errors, and honestly, I don't know what I'm doing. for now, I'm getting
name 'index' is not defined
Idk what's that intended. And although a Ncloth and nucleus were already applied, it just gave me a weird mesh with missing parts of the material attribute.
Solution 1:[1]
You should try to lear the basics of python, it takes a day and you will save a lot of time searching for simple errors. Your problem is that you use the variable indexin this line:
cmds.connectAttr(nCloth + ".currentState", nucleus +".inputActive[{}]".format(index), f=1)
And this name is not defined anywhere in your code. Before you use any variable, you must define it e.g.
index = 0
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | haggi krey |
