我有這個奇怪的東西,其中Maya表示在我嘗試更改其值時不存在某個屬性。 原因是Maya只在腳本中創建了該屬性,但尚未更新屬性「list」/「interface」。 有沒有辦法讓maya在繼續之前暫停腳本執行幾秒鐘?暫停maya python的執行,然後繼續
import maya.mel as mm
import maya.cmds as cmds
import time, os
# create something to add a node to
cmds.polySphere(sx=10, sy=15, r=20)
# add vray displacement node
mm.eval('vray objectProperties add_single VRayDisplacement;')
# add to displacement node
mm.eval('vray addAttributesFromGroup vrayDisplacement vray_subdivision 1;')
mm.eval('vray addAttributesFromGroup vrayDisplacement vray_displacement 1;')
mm.eval('vray addAttributesFromGroup vrayDisplacement vray_subquality 1;')
# connect filenode to displacement v-ray node
cmds.shadingNode('file',asTexture=1,n='displacement_file')
cmds.connectAttr('displacement_file.outColor', 'vrayDisplacement.displacement')
#cmds.pause(sec=2)
cmds.refresh(su=1)
cmds.refreshEditorTemplates
#time.sleep(5) # have to sleep because maya needs to update the vray node with the new attributes
# edit settings for displacement node
cmds.setAttr('vrayDisplacement.overrideGlobalDisplacement', 1)
cmds.setAttr('vrayDisplacement.vrayDisplacementKeepContinuity', 1)
cmds.setAttr('vrayDisplacement.vray2dDisplacementFilterTexture', 0)
cmds.setAttr('vrayDisplacement.vrayDisplacementAmount', 1.3)
cmds.setAttr('vrayDisplacement.vrayEdgeLength', 6)
cmds.setAttr('vrayDisplacement.vrayMaxSubdivs', 4)
我想:
cmds.pause(sec=2)
cmds.refresh(su=1)
cmds.refreshEditorTemplates
time.sleep(5)
這些都不解決。 我得到的錯誤是:
Error: RuntimeError: file <maya console> line 22: setAttr: No object matches name: vrayDisplacement.vrayDisplacementKeepContinuity #
如果是這樣,那爲什麼第一個'setAttr'運行?畢竟,它正在修改'vrayDisplacement'屬性。你有沒有嘗試評論'cmds.setAttr('vrayDisplacement.vrayDisplacementKeepContinuity',1)'看看會發生什麼?也許它不完全拼寫這種方式。當然只是一個建議。我還沒有到處玩vray呢...... –
您是否嘗試過在屬性編輯器關閉的情況下運行此操作? – theodox
overrideGlobalDisplacement工作的唯一原因是因爲它不是在執行腳本時添加的屬性。其他人雖然。我嘗試關閉屬性編輯器並註釋掉vrayDisplacementKeepContinuity,但是接下來maya會抱怨下一個filtertex。我不知何故需要python停止,然後在maya有時間更新之後再次啓動。我想最後的手段是讓用戶運行腳本兩次,但我希望能夠避免這種情況。 –