Pregunta

I have this wierd thing where Maya says an attribute doesn’t exist when I try to change it’s value. The reason is that Maya just created that attribute in the script and hasn’t updated the attribute “list”/”interface” yet. Is there a way to make maya pause the script excecution for a few seconds before continueing?

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)

I tried:

cmds.pause( sec=2 )
cmds.refresh(su=1)
cmds.refreshEditorTemplates
time.sleep(5)

none of these worked out. the error I get is:

Error: RuntimeError: file <maya console> line 22: setAttr: No object matches name: vrayDisplacement.vrayDisplacementKeepContinuity # 
¿Fue útil?

Solución

It´s a weird things in maya. You have to use cmds.evalDeffered() to wrap your cmds.setAttr to delay it.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top