2014-04-23 69 views
0

有沒有辦法修改這個腳本,它試圖在操作過程中嘗試填充兩行並導致錯誤,並繼續執行腳本?嘗試例外似乎不起作用。maya + python:在錯誤操作時執行並繼續

import maya.cmds as cmds 

cmds.file(new=True, f=True) 

# Create a circular fillet (by default) having radius 2.5 between the 
# active curves: 
a = cmds.curve(d=1, p=[(0, 0, 0), (0, 0, 5)]) 
b = cmds.curve(d=1, p=[(0, 0, 5), (0, 0, 10)]) 
c = cmds.curve(d=1, p=[(0, 0, 10), (-5, 0, 10)]) 

allShapes = [a,b,c] 

# do the first fillet 
filletA = cmds.filletCurve(a,b, r=1.5) 
if cmds.objExists(filletA): 
    allShapes.append(filletA) 

# do the second fillet 
filletB = cmds.filletCurve(b,c, r=1.5) 
if cmds.objExists(filletB): 
    allShapes.append(filletB) 

print 'ran' 
print allShapes 

錯誤

# Warning: No curve contact point specified. Using start of curve instead. # 
# Warning: No curve contact point specified. Using start of curve instead. # 
# Warning: filletCurve1 (Fillet Curve): failed to get normal. # 
# Traceback (most recent call last): 
# File "<string>", line 12, in <module> 
# File "C:\\Users\\Martini\\Desktop\\trash\\fillet_01.py", line 14, in <module> 
#  filletA = cmds.filletCurve(a,b, r=1.5) 
# # RuntimeError: Command filletCurve failed. Open Script Editor for details. 
+0

已更新以上爲您 – JokerMartini

回答

2

標準Python try/except

try: 
    #... do your stuff here... 
except RuntimeError: 
    #... continue here 

限制你的異常捕獲到你期望(在這種情況下的,RuntimeError是,如果一個命令失敗,什麼瑪雅通常拋出),所以你可以繞過Maya問題而不會隱藏你的錯誤。

的一般常識here

+0

有沒有更好的方法來測試在不產生真實結果的意外線上的切片? – JokerMartini

+0

可能不是一個值得的時間,沒有。幸運的是,在Python中,異常處理比if語句更便宜,沒有更多的混淆。谷歌「EAFP python」的理論 – theodox

+0

非常感謝您的幫助和解釋。 – JokerMartini

0

而且,它可能是瑪雅更新的錯誤。

當您創建一個對象或屬性時,maya不會刷新整個腳本。

由於您不能使用「暫停」來強制刷新,您必須採取艱難的方式並使用:cmds.evalDeferred()命令。