Vray SDK add default material if none exists

Hi @matt_newberg

I am using vray sdk for rhino.

I would like to ask if it possible to add materials to asset editor / material tab via vray sdk - a default white material if no materials exists?

I check all materials in rhino vray by this:

List<string> materials = VRayForRhinoNETInterface.VRayInterface.GetSceneMaterialNames();

if(materials.Count == 0){
   I would like to add one simple diffuse material

Could you please give me an example how to write this?

Have you tried the function LoadVismat(“c:\PathToDefault.vrmat”):

That should allow you to load any vrmat, vismat you want as a default vismat if none are found. There is no way to generate a material without loading it from file at this time.

Thank you for a reply. I have following.

Is it possible to add mesh to vray engine without assigning material if none exists?

This one requires material string name.
VRayInterface.AddNonDocObjectToRender( mesh, material)

If there is no possibility like this, then is it possible to create .vrmat file via scripting?

If the material name is not found, it will use the first material it finds in the rhino document. Does this meet your needs?

It would be helpful to know what is the final goal of this. Maybe there is an easy way to work around this issue.

Yes it does.

The issue is simple.

I use vray sdk to add grasshopper meshes to vray render engine then render the geometry.
I add object to vray render by calling command from vray sdk : VRayInterface.AddNonDocObjectToRender(mesh,material name) and call render command: Rhino.RhinoApp.RunScript("_render", false);
However it ask for material name is asset editor. Which I usually create myself via rhino.

But there is situation when I forget to create material, and asset editor material table is empty, for instance when I open new rhino window.

How to render geometry in this case when no materials are created and I just opened rhino and want to render geometry from grasshopper?


There is a Grasshopper Component in C:\Program Files\Chaos Group\V-Ray\V-Ray 3.4 for Rhinoceros 5\GrasshopperComponents

Is there a reason you are not using that. It has many edges cases covered in the component code. Everything you are doing sounds like it is already in VRay Document Render Component.

I know, but I just have my custom workflow for myself.
Maybe I will decompile one of them and look at inside code.

Ah ok, there is now way to create material from VRayForRhinoNETInterface.dll that is both on vray 2.0 and 3.4.1