Hi I'm a newbee in python and scripting, read a lot of tutorials and try to create script for combine curveShapes to one curve with multishapes, it's works fine for me. But here i have one bug when i start script first time after launch Maya it gives me traceback and if it was run one time it don't give any errors or tracebacks:
// Error: Not enough objects or values.
# Traceback (most recent call last):
# File "<maya console>", line 2, in <module>
# File "C:/Users/.../maya/2017/scripts\CreateOneCurve.py", line 17, in <module>
# cmds.parent(r=True, s=True)
# RuntimeError: Not enough objects or values. //
Here my script:
#Funcion for create list of objects
def listCurveObj():
shapeList = cmds.ls(cmds.listRelatives(s=True), s=True)
groupList = cmds.ls(cmds.group(em=True, n='Curve#'))
listAllobjects = []
for obj in groupList:
listAllobjects.extend(shapeList)
listAllobjects.extend(groupList)
return listAllobjects
#Create one Curve
cmds.select(listCurveObj())
cmds.parent(r=True, s=True)
#Clean scene
transforms = cmds.ls(type='transform')
deleteList = []
for tran in transforms:
if cmds.nodeType(tran) == 'transform':
children = cmds.listRelatives(tran, c=True)
if children == None:
print '%s, has no childred' %(tran)
deleteList.append(tran)
if len(deleteList) > 0:
cmds.delete(deleteList)
May anyone can help with it?
Hi there ok now i solved all my bugs and warnings and finish my first python script! It works great. So this script combine few curves to one multishape curve without closing points via standart maya attach curve tool! So now it looks like:
import pymel.core as pm
#Get list of objects
shapeList = pm.ls(pm.listRelatives(c=True))
groupList = pm.ls(pm.group(em=True, n='Curve#'))
listAll = []
for obj in groupList:
listAll.extend(shapeList)
listAll.extend(groupList)
#Parent objects to one Curve
pm.select(listAll)
pm.parent(r=True, s=True)
#Clean scene
trans = pm.ls(tr=True)
parents = pm.listRelatives(pm.ls(), type='transform', p=True)
deleteList=[]
for obj in trans:
if obj not in parents:
deleteList.append(obj)
print '%s, has no childred' %(obj)
if len(deleteList) > 0:
pm.delete(deleteList)