Hello,
I’m trying to write a python script to perform some repetitive actions, but I am struggling with the V-Ray Script Access Documentation (V-Ray for Rhino).
I’d like to perform the following actions for each item in a list of material names:
- Create a new material duplicated from a template material
- Rename the new material
- Swap it’s diffuse bitmap for a new bitmap from a list
Is this possible with the tools provided by Chaos?
Hi,
In short:
1) Yes
2) Yes
3) Yes
Consider that you have a template V-Ray material already existing
Since every V-Ray material has a Rhino material table entry, you all non V-Ray changes using a regular Rhino API calls.
Afterwards you use V-Ray API calls to take care of the V-Ray specific materials
Here is what you need to do.
import Rhino
import rhVRay as vray
mtlTable = Rhino.RhinoDoc.ActiveDoc.RenderMaterials
templateMtl = mtlTable[0]
# make copy of the template material, and change its name.
newMat = templateMtl.MakeCopy()
newMat.Name = "/MyNewMat"
# Add the new material to the material table
mtlTable.Add(newMat)
# Modify V-Ray properties - e.g. change the diffuse texture bitmap
with vray.Scene.Transaction() as f:
vray.Scene.Plugin("/MyNewMat/VRay Mtl/Bitmap/Bitmap").file = r"D:\y5.png"
And here is the result if you run the script
Thank you Nikolay! This is very helpful and I will go this route next time 
This time the solution I found (with my limited scripting knowledge) was to manipulate .vrmat files as they are saved in plain text format. Your solution makes much more sense!
Manipulating .vrmats is also an option. There is an API for that as well, so you do mot need to parse XML files, or have certain knowledge about the format.
Can you point me towards the documentation for that API please?
You can check the VRay::Internal::StructuredVRMat class in the AppSDK.
There is no official documentation, but the API is fairly simple to use
Hey Nikolay, I’m trying to use the AppSDK in RhinoPython, but i seem to be getting this error message. Am I doing something wrong?
RhinoPython runs ironpython 2.7.12. Is that a problem?
imput:
import vray
output:
Message: cannot import vray from python27
Traceback:
line 37, in import_module, "C:\Program Files\Rhino 7\Plug-ins\IronPython\Lib\importlib\__init__.py"
line 17, in <module>, "C:\Program Files\Chaos Group\V-Ray\AppSDK\python\vray.py"
line 1, in <module>, "C:\Users\charlie\AppData\Local\Temp\TempScript.py"
that won’t work. RhinoPython is IronPython 2.7, and appsdk is implemented on CPuthon
it should work with Rhino 8 though. They switched to CPython 3.9 there