2017-02-22 75 views
1

嗨,我是一個Python和腳本編寫的新手,閱讀了很多教程,並嘗試創建腳本,將curveShapes合併到一條具有多形狀的曲線,它對我來說工作正常。但在這裏我有一個錯誤,當我啓動腳本第一次發射後瑪雅它給了我回溯,如果它是一個運行時它不給任何錯誤或回溯:Maya python腳本將幾條曲線合併爲一條

// 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. // 

這裏我的腳本:

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

任何人都可以幫忙嗎?

+0

只是爲了記錄,最好使用'pymel.core'而不是'maya.cmds',它非常相似,但給了更多的控制權。我有時候會重新安裝maya,然後看看,可能需要幾天時間:) – Peter

回答

0

你好,現在我解決了所有的錯誤和警告,並完成我的第一個Python腳本!它效果很好。所以這個腳本通過標準的maya attach曲線工具將幾條曲線合併到一條多形曲線,而不需要關閉點!所以現在它看起來像:

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

嗨,我試圖解決我的問題與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) 

但第二(乾淨的場景)不工作,所以我想在這裏,我有麻煩上市我不知道如何接收空組的列表,或者我如何比較兩個列表並刪除相同的項目?

0

好像過度殺死,爲什麼不是這樣?

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