Maya Python脚本将几条曲线结合在一起



嗨,我是python和脚本的新生,阅读了很多教程,并尝试创建脚本以将曲线变成一个曲线与多曲线,对我来说很好。但是在这里,我有一个错误,当我在启动Maya之后第一次启动脚本时,它会给我追溯,如果它运行一次,则不会给任何错误或追溯:

// Error: Not enough objects or values.
# Traceback (most recent call last):
#   File "<maya console>", line 2, in <module>
#   File "C:/Users/.../maya/2017/scriptsCreateOneCurve.py", line 17, in <module>
#     cmds.parent(r=True, s=True)
# RuntimeError: Not enough objects or values. //

在这里我的脚本:

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

任何人都可以提供帮助吗?

嗨,我试图解决我对pymel的问题并重做它,所以现在我的第一部分工作完美:

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)

但是第二个(干净的场景)不起作用,所以我认为在这里我在列表方面遇到麻烦,我不知道如何接收空列表的列表,或者如何比较两个列表并删除相同的项目?

嗨,现在我解决了所有错误和警告,并完成了我的第一个Python脚本!它效果很好。因此,该脚本将几条曲线结合到一个多曲线曲线,而无需通过Standart Maya附加曲线工具结合点!所以现在看起来像:

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)

看起来像是杀死,为什么不这样的东西?

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

相关内容

  • 没有找到相关文章

最新更新