1

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?

  • Just for the record, it's better to use `pymel.core` instead of `maya.cmds`, it's very similar but gives a bit more control. I'll get round to reinstalling maya sometime and have a look anyway, just might take a few days :) – Peter Feb 22 '17 at 17:38

3 Answers3

0

Hi i tried to solve my problem with pymel and redo it so now my first part works perfect:

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)

But second (clean scene) doesn't work so i think here i have trouble with listing and i have no idea how to receive list of empty groups or how i can compare two lists and delete same items?

0

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)
0

seems like over kill, why not something like this?

import maya.cmds as mc

def combineCurves(curves = []):
    crvGrp = mc.group(n = curves[0], em=1)
    for crv in curves:
        crvShape = mc.listRelatives(crv, shapes = 1)
        mc.parent(crvShape,crvGrp,s=1,r=1)
        mc.delete(crv)
        
combineCurves(mc.ls(selection=1))
Community
  • 1
  • 1