I’m adding a vrayDisplacement node and wish to modify its attribute values using python. For some reason I can’t run the code in one go, probably because the UI/attribute editor needs to get refreshed, which only seems to happen when the script has finished.
This means I am right now forced to create two scripts which has to be manually executed one after the other in order for this to work. Any ideas on how I could make this code work in one go?
import maya.cmds as cmds
import maya.mel as mel
selected = cmds.ls(sl=True) # Get selected objects
mel.eval("vray objectProperties add_single VRayDisplacement") # Create vrayobjectproperties node and attach the selected objects
vrayObjProp = cmds.listConnections(selected[0]) # Grab name of vop node (sketchy method)
mel.eval("vray addAttributesFromGroup " + vrayObjProp[0] + " vray_displacement 1;") # Adding attribute vray displacement control
cmds.select(vrayObjProp[0], replace=True, noExpand=True) # Select the AETemplate to be force-refreshed so that we can access the newly created attributes
cmds.refreshEditorTemplates # Refresh of selected AETemplate
cmds.setAttr(vrayObjProp[0]+".vrayDisplacementType", 0) # Set 2d displacement
cmds.setAttr(vrayObjProp[0]+".vray2dDisplacementResolution", 1024) # Texture size
cmds.setAttr(vrayObjProp[0]+".vray2dDisplacementFilterTexture", 0) # Turn texture filtering off