I was looking for a python or mel script that apply a VRay Attributes “subdivision” level to each selected object at once.
I found something on the web, but looks like something is wrong.
Didnt work that script for me.
import maya.cmds as cmds
import maya.mel as mel
def makeVrayAttributes(startID=1):
sel = cmds.ls(sl=1)
currentID=startID
for i in sel:
# get renderable shape nodes relative to transform, iterate through and apply subdivision
shapes = cmds.listRelatives(i,s=1,ni=1)
if shapes:
for s in shapes:
melCmd = “vray addAttributesFromGroup “+s+” vray_subdivision 1”
mel.eval(melCmd)
melCmd = “vray addAttributesFromGroup “+s+” vray_subquality 1”
mel.eval(melCmd)
# apply object ID to xform. i don’t like giving individual shapes IDs.
melCmd = “vray addAttributesFromGroup “+i+” vray_objectID 1”
mel.eval(melCmd)
cmds.setAttr(i+‘.vrayObjectID’,currentID)
currentID += 1
Do you have any idea how to write a script to turn on the subdivision for each selected object at once?
I tried also to apply this over the VRay Shelf but you need to do this also manually and it will make a lot of nodes.
I will appreciate any help because I have a lot of objects in my scene (just 2505 objects that require some time if I do one by one)
The indenting of the script is broken. Python scripts require proper indenting in order to work.
Do you have the link to the original script?
Also this script assigns consecutive objectIDs to your objects. Do you want this?
And the last problem is that this script just defines a function. You need to execute it to get the result you’re after.
The modified script that seems to work:
import maya.cmds as cmds
import maya.mel as mel
def makeVrayAttributes(startID=1):
sel = cmds.ls(sl=1)
currentID=startID
for i in sel:
# get renderable shape nodes relative to transform, iterate through and apply subdivision
shapes = cmds.listRelatives(i,s=1,ni=1)
if shapes:
for s in shapes:
melCmd = "vray addAttributesFromGroup "+s+" vray_subdivision 1"
mel.eval(melCmd)
melCmd = "vray addAttributesFromGroup "+s+" vray_subquality 1"
mel.eval(melCmd)
# apply object ID to xform. i don't like giving individual shapes IDs.
melCmd = "vray addAttributesFromGroup "+i+" vray_objectID 1"
mel.eval(melCmd)
cmds.setAttr(i+'.vrayObjectID',currentID)
currentID += 1
makeVrayAttributes()
You can remove the code after “# apply object ID” to prevent the script from adding object id attributes to your nodes.
Well Im not a script pro. Have only basic knowledge using mel script.
Here is the original post.
What do mean with:
- this script assigns consecutive objectIDs to your objects.
consecutive
Well I just want to active some properties for each selected object.
1. VRay Attributes Subdivisions
2. Subdivision and Displacement Quality
3. Displacement control
4. Object ID
Everything that is under the VRay Attributes tab.
At the moment I was only testig the “subdivisions” and the “object ID”
Another option is to connect all objects to a V-Ray displacement override set and to add subdivision attributes to it (without really using the displacement functionality).
this is my script that I use all the time. Select your objects in the outliner, viewport or however you like. Press “Cursor down” to get the shape node and then run this script
Unfortunately your script didnt work for me.
I tried also in that way without adding a vray addAttributesFromGroup.
This is new for me, but even with your script nothing happens :neutral:
Im using the t.petrov s script wich work just AWESOME!