用于将多条曲线合并为一条曲线的Maya python脚本

用于将多条曲线合并为一条曲线的Maya python脚本,python,maya-api,Python,Maya Api,您好,我是python和脚本的新手,阅读了大量教程,并尝试创建脚本,将曲线形状组合到一条曲线和多个形状,对我来说效果很好。但在这里,我有一个错误,当我在启动Maya后第一次启动脚本时,它会给我回溯,如果它运行一次,则不会给出任何错误或回溯: // Error: Not enough objects or values. # Traceback (most recent call last): # File "<maya console>", line 2, in <modu

您好,我是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/scripts\CreateOneCurve.py", line 17, in <module>
#     cmds.parent(r=True, s=True)
# RuntimeError: Not enough objects or values. //

有人可以帮忙吗?

嗨,我试图用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)

但是第二个(干净的场景)不起作用,所以我想在这里我在列表方面有问题,我不知道如何接收空组列表,或者如何比较两个列表并删除相同的项目

嗨,我试着用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)

但是第二个(干净的场景)不起作用,所以我想在这里我在列表方面有问题,我不知道如何接收空组列表,或者如何比较两个列表并删除相同的项目

大家好,现在我解决了所有的bug和警告,完成了我的第一个python脚本!它工作得很好。因此,该脚本通过standart maya attach curve tool将几条曲线合并为一条多形状曲线,而无需闭合点!所以现在看起来像:

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)

大家好,现在我解决了所有的bug和警告,完成了我的第一个python脚本!它工作得很好。因此,该脚本通过standart maya attach curve tool将几条曲线合并为一条多形状曲线,而无需闭合点!所以现在看起来像:

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)
看起来像是过度杀戮,为什么不做这样的事情呢? 看起来像是过度杀戮,为什么不做这样的事情呢?
为了便于记录,最好使用
pymel.core
而不是
maya.cmds
,它非常类似,但提供了更多的控制。我会抽出时间重新安装maya,然后看看,可能需要几天时间:)为了记录在案,最好使用
pymel.core
而不是
maya.cmds
,它非常类似,但提供了更多的控制。我会抽出时间重新安装maya,然后再看一看,可能需要几天时间:)