vray addAttributesFromGroup - BigRoy/mayaVrayCommandDocs GitHub Wiki

In many situations I've had the need to automate the creation, removal or changing values of many vray attributes in Maya. In the course of looking for good documentation I haven't found a good resource and there seems to be no general or standard approach to doing this.

Many python scripts I've found online seem to be using mel in many cases, which isn't required.

For example:

""" Adding subdivision attributes """
import maya.mel as mel
import maya.cmds as mc

shapes = mc.ls(sl=1, dag=1, lf=1, s=1)
for shape in shapes:
    mel.eval("vray addAttributesFromGroup \"" + shape + "\" vray_subdivision 1")

This could be easily written without using the mel module, like this:

""" Adding subdivision attributes """
import maya.cmds as mc

shapes = mc.ls(sl=1, dag=1, lf=1, s=1)
for shape in shapes:
    mc.vray("addAttributesFromGroup", shape, "vray_subdivision", 1)

Of course the Maya commands module isn't really Pythonic either, but it's already a lot cleaner!

We can use it from the maya.cmds (or in mel as well) because the command is defined in the Vray for Maya plug-in (so not all are just .mel files). Thanks Chaosgroup; now only if there was some documentation for it!

The vray command is a multifunctional one, it's used in a variety of ways. One way is adding/removing vray attributes. To do that you would do:

import maya.cmds as mc

mc.vray("addAttributesFromGroup", node, attr, state)

Where: node is the node to apply the command to. (this should be of the correct type) attr is the attribute type/group to create. (see below for some variations) state is a boolean (1,0) to either create or remove the attributes.

Note: When using this function with a wrong node type and attribute group combination it doesn't give an error. It will create the attributes on the WRONG node. This can be very confusing, so make sure that if you write your own functions that use this that it filters to the correct types. I.e. adding vray_subdivision attributes to a nurbsSurface or transform node will not raise an error and will create the attributes. Though it doesn't subdivide anything during rendertime, it's pretty much useless.

Flags

######node

The node flag should be the name of a single node.

######attr

The attr flag should be one of the following. Though make sure that the command you are setting is correct for the node type you're setting it on, otherwise you'll end up with attributes on a note that don't do anything.

So here's some possibilities for attr when doing addAttributesFromGroup:

  • vray-materials:

    • Material ID: vray_material_id
    • V-Ray material override: vray_specific_mtl
    • Closed Volume Shading: vray_closed_volume
  • materials:

    • Material ID: vray_material_id
    • V-Ray material override: vray_specific_mtl
  • mesh:

    • Subdivision: vray_subdivision
    • Subdivision and Displacement Quality: vray_subquality
    • Displacement control: vray_displacement
    • Round edges: vray_roundedges
    • User attributes: vray_user_attributes
    • Object ID: vray_objectID
    • Fog fade out radius: vray_fogFadeOut
    • Phoenix Object Properties: vray_phoenix_object (since 2.4 nightlies?)
  • nurbsCurve:

    • Renderable : vray_nurbscurve_renderable
  • nurbsSurface:

    • NURBS attributes: vray_nusrbsStaticGeom (the typo is 'correct')
    • Object ID : vray_objectID
    • User attributes : vray_user_attributes
  • transform:

    • User attributes : vray_user_attributes
    • Skip Rendering: vray_skip_export
  • camera:

    • Physical Camera: vray_cameraPhysical
    • Camera Settings : vray_cameraOverrides
    • Dome Camera : vray_cameraDome
  • file:

    • Texture input gamma: vray_file_gamma (also for VRayPTex, Substance, imagePlane)
    • Allow negative colors: vray_file_allow_neg_colors (also for Substance, imagePlane)
    • Image file list (IFL) : vray_file_ifl
    • Texture filter : vray_texture_filter (also for VRayPTex, Substance, imagePlane)
  • imagePlane:

    • Texture input gamma: vray_file_gamma
    • Allow negative colors: vray_file_allow_neg_colors
  • place2dTexture:

    • 2D Placement Options: vray_2d_placement_options
  • samplerInfo:

    • Additional outputs: vray_samplerinfo_extra_tex
  • pointLight, spotLight:

    • Light Attributes: vray_pointLight
  • directionalLight:

    • Light Attributes: vray_directlight
  • ambientLight:

    • Light Attributes: vray_light
  • areaLight:

    • Light Attributes: vray_arealight
  • vray-lights:

    • Object ID: vray_objectID (except VRayLightIESShape)

For more information about what v-ray attributes there are and what they (can) do have a look at Extra V-Ray Attributes in the Chaosgroup documentation: V-Ray for Maya, version 2.0 (documentation)

######state

The state flag should be a boolean value, that is: 0 or 1.

In python you can NOT do True or False. Anything other than 0 will be interpreted as a 1 thus creating the attribute group. So writing False will not delete the attribute group but will create it.