TypeError in creating Ncloth in Maya Script

Viewed 35

So, I got this code here, creating Ncloths

# create a cloth node
mesh = cmds.ls(sl=True)
nCloth = cmds.createNode("nCloth")

# 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=tform, name=outMeshName)
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(nindex), f=1)
cmds.connectAttr(nCloth + ".startState", nucleus + ".inputActiveStart[{}]", f=1)

# force the refresh when used in batch
cmds.getAttr(cloth + ".forceDynamics")

And the part where you connect the mesh to the ncloth doesn't work due to a typeError

TypeError: file <maya console> line 9: can only concatenate list (not "str") to list # 

What exactly is the error here and how will I fix it?

1 Answers

The command ls returns a list not a string.

mesh = cmds.ls(sl=True)[0]

Will work if a mesh is selected.

Related