我有这个奇怪的东西,其中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有时间更新之后再次启动。我想最后的手段是让用户运行脚本两次,但我希望能够避免这种情况。 –