# Python: cannot modify newly created vray attributes

**URL:** <https://forums.chaos.com/t/python-cannot-modify-newly-created-vray-attributes/44542>\
**Category:** Issues\
**Created:** [March 13, 2013, 11:39am UTC](https://forums.chaos.com/t/python-cannot-modify-newly-created-vray-attributes/44542 "2013-03-13T11:39:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fredrik\_Averpil](https://dub1.discourse-cdn.com/chaosprd/user_avatar/forums.chaos.com/fredrik_averpil/32/35925_2.png) [@Fredrik\_Averpil](https://forums.chaos.com/u/Fredrik_Averpil)\
**Post date:** [March 13, 2013, 11:39am UTC](https://forums.chaos.com/t/python-cannot-modify-newly-created-vray-attributes/44542/1 "2013-03-13T11:39:14Z")

</div>

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?

```auto
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

```

---

<div class="post-metadata">

**Author:** ![bigbossfr](https://dub1.discourse-cdn.com/chaosprd/user_avatar/forums.chaos.com/bigbossfr/32/50480_2.png) [@bigbossfr](https://forums.chaos.com/u/bigbossfr)\
**Post date:** [March 13, 2013, 11:42am UTC](https://forums.chaos.com/t/python-cannot-modify-newly-created-vray-attributes/44542/2 "2013-03-13T11:42:10Z")

</div>

> [@Fredrik\_Averpil](#):
>
> 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?
> 
> ```auto
> 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.

---

<div class="post-metadata">

**Author:** ![Fredrik\_Averpil](https://dub1.discourse-cdn.com/chaosprd/user_avatar/forums.chaos.com/fredrik_averpil/32/35925_2.png) [@Fredrik\_Averpil](https://forums.chaos.com/u/Fredrik_Averpil)\
**Post date:** [March 13, 2013, 12:53pm UTC](https://forums.chaos.com/t/python-cannot-modify-newly-created-vray-attributes/44542/3 "2013-03-13T12:53:01Z")

</div>

I can’t get that to work either. Same problem. Can’t set the attributes…

I first tried this:

```auto
# 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:

```auto
# 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?

---

<div class="post-metadata">

**Author:** ![ivaylo.ivanov](https://avatars.discourse-cdn.com/v4/letter/i/eb8c5e/32.png) [@ivaylo.ivanov](https://forums.chaos.com/u/ivaylo.ivanov)\
**Post date:** [March 13, 2013, 1:25pm UTC](https://forums.chaos.com/t/python-cannot-modify-newly-created-vray-attributes/44542/4 "2013-03-13T13:25:51Z")

</div>

It’s working here. You probably need a newer build.

---

<div class="post-metadata">

**Author:** ![Fredrik\_Averpil](https://dub1.discourse-cdn.com/chaosprd/user_avatar/forums.chaos.com/fredrik_averpil/32/35925_2.png) [@Fredrik\_Averpil](https://forums.chaos.com/u/Fredrik_Averpil)\
**Post date:** [March 13, 2013, 1:36pm UTC](https://forums.chaos.com/t/python-cannot-modify-newly-created-vray-attributes/44542/5 "2013-03-13T13:36:07Z")

</div>

> [@ivaylo.ivanov](#):
>
> It’s working here. You probably need a newer build.

Yep, that was it. Thanks to both of you! 🙂
