mentalray userdata: one material, different textures

At least i was success with this simple task- one materials with different textures on different object in mentalray.
So for now we need maya 2012.
Create userdata.mi(see bottom of the page) and put it to C:\Program Files\Autodesk\Maya2012\mentalray\include
Edit mentalraycustomnodeclass.mel (see bottom of the page)
If you install srevice pack 1- you dont need to create userdata.mi and correct customNodeClass.mel

Now in miscellaneous section of MR in hypershade we have userdata shaders(mib_data_bool, mib_data_get_bool etc).

On every object(transform node) create attribute "miData":
addAttr -ln miData -at message OBJ_TRANSFORM_NAME;
Also, miData can be multi: addAttr -ln miData -at message -multi OBJ_TRNSF_NAME;
For this example i`ve create pPlane1, add miData attribute to it and dublicate plane 2 times, so we get 3 poly plane with miData on extra attributes of transform nodes.

Create MR shader, for example mia_material_X_passes and assighn it to all objects(pPlanes).
Create one mib_data_get_shader_color and plug it to diffuse color of mia.
Create 2 mib_data_shader nodes.

mib_data_get_shader_color will "catch" data from mib_data_shader and output it to diffuse color of mia.
Create 3 solid color ramps. Connect output of ramp1 to default attribute of mib_data_get_shader_color1 through multiplyDevide node(in input1, input 2 set to 1).
Connect ramp2 and ramp3 to mib_data_shader1 and mib_data_shader2 also through multiplyDevide nodes.
Set "Name" attribute
of mib_data_shader and mib_data_get_shader_color nodes to something descriptive, for example "Color".
Connect message of mib_data_shader1 to miData of pPlane2, message of mib_data_shader2 to miData of 3. Thats all.






Code for userdata.mi:
#-------------------------------------------- Maps
declare shader
scalar "mib_map_get_scalar" (
string "field_name"
)
version 1
apply texture
end declare

declare shader
integer "mib_map_get_integer" (
string "field_name"
)
version 1
apply texture
end declare

declare shader
vector "mib_map_get_vector" (
string "field_name"
)
version 1
apply texture
end declare

declare shader
color "mib_map_get_color" (
string "field_name"
)
version 1
apply texture
end declare

declare shader
transform "mib_map_get_transform" (
string "field_name"
)
version 1
apply texture
end declare

declare shader
color "mib_map_get_scalar_array" (
string "field_name"
)
version 1
apply texture
end declare

declare shader
color "mib_map_get_integer_array" (
string "field_name"
)
version 1
apply texture
end declare

mentalraycustomnodeclass.mel edit:
// Data Conversion

if ($nodeType == "mib_data_bool" ||
$nodeType == "mib_data_bool_array" ||
$nodeType == "mib_data_color" ||
$nodeType == "mib_data_color_array" ||
$nodeType == "mib_data_get_bool" ||
$nodeType == "mib_data_get_color" ||
$nodeType == "mib_data_get_int" ||
$nodeType == "mib_data_get_scalar" ||
$nodeType == "mib_data_get_shader" ||
$nodeType == "mib_data_get_shader_bool" ||
$nodeType == "mib_data_get_shader_color" ||
$nodeType == "mib_data_get_shader_int" ||
$nodeType == "mib_data_get_shader_scalar" ||
$nodeType == "mib_data_get_shader_vector" ||
$nodeType == "mib_data_get_string" ||
$nodeType == "mib_data_get_texture" ||
$nodeType == "mib_data_get_vector" ||
$nodeType == "mib_data_int" ||
$nodeType == "mib_data_int_array" ||
$nodeType == "mib_data_scalar" ||
$nodeType == "mib_data_scalar_array" ||
$nodeType == "mib_data_shader" ||
$nodeType == "mib_data_shader_array" ||
$nodeType == "mib_data_string" ||
$nodeType == "mib_data_string_array" ||
$nodeType == "mib_data_texture" ||
$nodeType == "mib_data_texture_array" ||
$nodeType == "mib_data_vector" ||
$nodeType == "mib_data_vector_array" )

return "rendernode/mentalray/conversion:swatch/mentalRaySwatchGen";

Scene
Userdata and CustomnodeClass

Python scripts for automatization.