How do you apply Vray materials with python

I am able to load a visopt and the vismats I would like to use. How can I automatically apply these Vray materials to objects in Rhino? I’ve gathered that the objects should be on different layers depending on what material I would like to use… but as far as linking a vismat to a layer I am coming up short.

Thank you for any help

I’m not sure. @andy do you know if there is way “from any SDK” to do this? If you know how to do it in C++, I can probably figure out a solution in python.

Hi Steve,

it looks like this is not yet fully exposed in plain rhino-python. In RhinoScript you can return and change the material index of a layer using:

Call Rhino.LayerMaterialIndex(strLayerName, intMaterialIndex) 

which assigns the V-Ray material if it has been loaded before, while in Python i´ve found only the method to return the material index of a layer:

intIndex = rs.LayerMaterialIndex(strLayerName)

Speaking of the RhinoScript example, the preloaded V-Ray material gets assigned to the layer and it even renders regardless of the layers material source. (Which is not set to “plugin” yet). To set it to plugin i´ve used this in RhinoScript as a Rhino.Command after setting the layer`s material index:

_-Layer _Material "LayerName" _Plugin "V-Ray for Rhino" _EnterEnd

The result is identical as using the UI in Rhino to assign a V-Ray material to a layer. So if one clicks in the Layer dialog on the layer’s material name, the proper dialog offering the “browse”, “edit” and “match” buttons comes up having the “plugin” toggle checked.

@pfahy are you aware that V-Ray can be accessed as object via scripting too ?

c.

I just added the optional index parameter to python’s LayerMaterialIndex function. This will be available in SR6. If you want to use this before SR6 is released, you can get rhinoscriptsyntax’s layer.py from github at
https://github.com/mcneel/rhinopython/blob/master/scripts/rhinoscript/layer.py

Thanks Steve.

It is a great learning source as well.

c.

Do you have an example for this in rhino? I just found this which is not too helpful:
http://forum.flyingarchitecture.com/index.php?/topic/714-figuring-out-functions-exposed-by-vray-for-rhino-plugin/

Is this documented somewhere?

Thanks
M

Hi Manuel,

i´ve did the same in the past as described in your link to find out about the functions provided by the plugin. Some of them are located in this file:

C:\ProgramData\ASGVIS\VfR564\VRayForRhinoExports.h

However, only a few functions seemed to work. Getting access to the materials was only partially possible so I´ve stopped working on it since i did not find a way to access byte-string-arrays.

I´ve contacted chaosgroup some time ago and asked about documentation, here is there response about accessing V-Ray via COM:

Hello Clement,

This question falls outside of what we can help with though our normal support 
channels. Support does not get you in touch with programmers, their time is more 
expensive then a someone like me. Here we help with installation and everyday use.

The best place for something like this is our free forums:
http://chaosgroup.com/forums/vbulletin/

The odds are very good you ll find the help you need there.

Best Regards,
Chaos Group USA

in order to get further, you might try to get help in the chaosgroup forum for V-Ray for Rhino. I´m sorry i cannot be of more help at the moment.

c.

They, chaosgroup, promised to improve the scripting side time ago but, today, only render option are exposed, and not really all of them.
I found a way to assign mat to object but only via rhino.command.
Not possible to layer or any kind of real scripting.
They do simple command line also for their RhinoExpress :wink:
At certain point a news about an SDK was released but then nothing.
And not talk about scripting the lights…

Hi Riccardo, does the script below work on your side to assign a loaded VRay material to a layer ? (i don´t have it installed currently).

VRayAssignMaterialToLayer.rvb (1.1 KB)

c.

1 Like

Hi @clement I’m at home with mob phone.
Here it’s 9 in the night.
Sorry I can’t try it before tomorrow morning.
I’ll let you know.
Could be useful also for my SimpleMat.

Hi All,

I’ve found myself in a similar situation where I would like to apply vray materials to a large number of geometric elements. The materials would be assigned by object not by layer. Any leads would be great.
Thanks,

Hi @charlie_portell, are you using RhinoScript or Python ?

c.

Hi @clement I’m using python but a rhinoscript solution would suffice.

Hi @charlie_portell, below are two RhinoScripts which might help. Should work with multiple objects as well after slight changes, tested on VRay 2.00.25962.

VRayAssignMaterialToObject.rvb (828 Bytes)
VRayAssignLoadedMaterialToObject.rvb (895 Bytes)

c.

1 Like

A post was split to a new topic: Setting random materials