I've wanted for a long time to MEL script turning on some of Vray's custom attributes (e.g. OpenSubdiv) for all selected objects so that they don't all have to be done manually. I'm not much of a scripter so usually rely on feedback in the script editor for pointers, but when testing with a single object I've never been able to determine which parts of the code that is returned does the work. With Echo All Commands turned on in the script ed. you get a lot of UI callbacks, but I can't find anything like a setAttr or addAttr command. All I want to do is create some simple for-in loops as procedures so that we can turn some of these attrs on and off easily. Can someone point me in the right direction?
Announcement
Collapse
No announcement yet.
Script Vray attributes?
Collapse
X
-
template code for iterating through any number of shapes and adding roundedges, displacemnt and the controls
be sure to select the shape node of your objects (down arrow key if you select the Transform Node in the Outliner, I guess it's the default selection)
if you want to add another Vray-Custom attribute you have to look up the name in den Documentation in the "Scripting"-Section and change the name in this line vray addAttributesFromGroup $obj "custom_vray_attribute" 1;
{
string $selection[] = `ls -selection -long`;
for($obj in $selection)
{
vray addAttributesFromGroup $obj "vray_roundedges" 1;
vray addAttributesFromGroup $obj "vray_displacement" 1;
vray addAttributesFromGroup $obj "vray_subquality" 1;
vray addAttributesFromGroup $obj "vray_subdivision" 1;
setAttr($obj + ".vrayDisplacementAmount",200);
setAttr($obj + ".vrayMaxSubdivs",16);
setAttr($obj + ".vrayEdgeLength",1);
setAttr($obj + ".vrayDisplacementKeepContinuity",1);
setAttr($obj + ".vrayDisplacementShift",0);
setAttr($obj + ".smoothLevel",0);
setAttr($obj + ".useSmoothPreviewForRender",0);
setAttr($obj + ".renderSmoothLevel",1);
setAttr($obj + ".vrayDisplacementStatic",0);
setAttr($obj + ".vrayDisplacementKeepContinuity",1);
setAttr($obj + ".vrayMaxSubdivs",6);
setAttr($obj + ".vrayDisplacementAmount",.15);
setAttr($obj + ".vrayDisplacementType",0);
}
}
Kind Regards
Pirmin
-
Thanks. Which "Scripting" section are you talking about -- in the Vray help docs or Maya help docs? I would assume they must be in the Vray docs, but that is part of the problem -- I've never been able to find this, and the lack of intuitive script editor feedback on adding, say, the object ID attribute has made identifying these attrs by name difficult.
Comment
-
Most of the time, there is a scripting section at the bottom of the documentation like in the screenshot I attached.
Another good trick is to "Echo All Commands" in your ScriptEditor under the "History" Tab at the top. It fetches a lot of code but sometimes it's usefull and you may find something that you are looking for
Kind Regards
Pirmin1 Photo
Comment
-
Got it, thanks -- never noticed that "Scripting" section at the bottom of the page.
You can remove the need to select your shape nodes manually like this:
$objs = `ls -sl`;
$shapes = `listRelatives -shapes`;
select $shapes;
for($shape in $shapes)
{
vray addAttributesFromGroup $shape "vray_objectID" 1;
}
Comment
-
Ah yes, the scripting sections on the docs - if you think of ways for us to make this more obvious / useful on the docs - just let me know and we'll think of something.
Comment
-
Well, now that I know they are there.... The script examples are very useful. That said, there seem to be some pages that don't have any at all. Given that some UI actions don't seem to generate any script ed feedback at all it would be useful to have a more thorough list of nodes and attributes (perhaps there is one that I don't know about?). An example that came up today -- was trying to script the color of a dirt map node. Doing this manually doesn't create any feedback at all, so I had to identify the attribute name. The only way I could think of doing it was to RMB and go to "Create Expression".
Comment
-
Hm, so based on this it seems that the vrayAddRenderElement command is actually calling a script: https://github.com/BigRoy/mayaVrayCo...RenderElements
Does that mean it's not possible to change the default naming of these nodes?
Comment
-
Originally posted by SonyBoy View PostAn example that came up today -- was trying to script the color of a dirt map node. Doing this manually doesn't create any feedback at all, so I had to identify the attribute name. The only way I could think of doing it was to RMB and go to "Create Expression".
See if that's the case with you. In the meantime, I made a note to add script examples wherever they're missing.Last edited by yolov; 04-09-2018, 10:57 PM.
Comment
-
Originally posted by SonyBoy View PostHm, so based on this it seems that the vrayAddRenderElement command is actually calling a script: https://github.com/BigRoy/mayaVrayCo...RenderElements
Does that mean it's not possible to change the default naming of these nodes?
So something like this should work for you, hopefully:
Code:string $createCustomVRayLSRE = `vrayAddRenderElement LightSelectElement`; rename $createCustomVRayLSRE "myCustomLightSelect";
Code:import maya.cmds as cmds import maya.mel as mel createCustomVRayLSRE = mel.eval('vrayAddRenderElement LightSelectElement') cmds.rename(createCustomVRayLSRE, 'myCustomLightSelect')
So if after creation, renaming etc you want to list by type - all vray render elements will be of type VRayRenderElement, but the Light Select will be of type VRayRenderElementSet.
Also another thing that might help - if you select a render element from the list in the render settings, the script editor will echo some help for the command to call to create it.
Let me know if this helps.Last edited by yolov; 04-09-2018, 10:58 PM.
Comment
-
Whenever you create a RenderElement with code like vrayAddRenderElement "diffuseChannel"; it is automatically selected by Maya. You can then use the ls command to fetch it into a variable and then use rename to give it a new name
Template Code:
{
vrayAddRenderElement "diffuseChannel";
string $RenderE[] = `ls -sl`;
print $RenderE[0];
rename $RenderE[0] "Your_Pass_Name";
}
Kind Regards
Pirmin
//EDIT: It seems yolov was faster and his code seems to be even shorter :O
Comment
Comment