Announcement

Collapse
No announcement yet.

Python: cannot modify newly created vray attributes

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Python: cannot modify newly created vray attributes

    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?

    Code:
    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
    Best Regards,
    Fredrik

  • #2
    Originally posted by Fredrik Averpil View Post
    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?

    Code:
    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
    Hi,
    Use evalDeferred command and not eval.
    www.deex.info

    Comment


    • #3
      I can't get that to work either. Same problem. Can't set the attributes...

      I first tried this:
      Code:
      # Select an object and then...
      mel.eval("evalDeferred \"vray objectProperties add_single VRayDisplacement\"")
      mel.eval("evalDeferred \"vray addAttributesFromGroup vrayDisplacement vray_displacement 1;\"")
      cmds.evalDeferred('cmds.setAttr("vrayDisplacement.vrayDisplacementType", 0)')
      Then I went with this:
      Code:
      # Select an object and then...
      cmds.evalDeferred('mel.eval("vray objectProperties add_single VRayDisplacement")')
      cmds.evalDeferred('mel.eval("vray addAttributesFromGroup vrayDisplacement vray_displacement 1;")')
      cmds.evalDeferred('cmds.setAttr("vrayDisplacement.vrayDisplacementType", 0)')
      Am I doing something wrong?
      Best Regards,
      Fredrik

      Comment


      • #4
        It's working here. You probably need a newer build.
        V-Ray/PhoenixFD for Maya developer

        Comment


        • #5
          Originally posted by ivaylo.ivanov View Post
          It's working here. You probably need a newer build.
          Yep, that was it. Thanks to both of you!
          Best Regards,
          Fredrik

          Comment

          Working...
          X