I guess that discussion is a little different because it’s for loading environment maps.What I’m trying to do is this: I want to make my script access the vrmat file of a particular material in the design and change a couple of its settings which I would manually do on the VRay Materials Editor (picture below)
So I might have just found the solution to this. And, that is current_scene_materials.xml which I found in C:\ProgramData\VRAYMATRIX2\VfMatrix64. This xml file has all the material parameter settings of the current scene.
Below is how to save a vrmat of the material named Test.
vRay = rs.GetPlugInObject("{E8CFE179-B60C-411A-8416-62A893334519}")
vRay.SaveMaterialToFile("/Test" , "c:/test.vrmat")
# this will prompt for file name
#vRay.SaveMaterial("/Test")
@matt_newberg makes me a very lazy programmer because he leaves no room for exercising my own head …only kidding; your help is much appreciated. Thanks!
No it is the Iron Python type needed to receive the data from the RhinoScript object.
It is the plugin GUID, you can also use the Plug-In name V-Ray For Rhino / V-Ray For Matrix. But since the plugin name can change base off of version, the GUID is a safer bet.
@matt_newberg I’m not sure how to use GetMaterialParameterString. What value should I set for the max_value_length parameter? I tried passing an arbitrary integer value but I get the error message 'Could not convert argument 0 for call to GetMaterialParameterString'.
Also, I’m wondering if I can pass use SetMaterialParameterString to change a parameter of type ‘color’ in this way:
Attached is an example of using GetMaterialParameterString and SetMaterialParameterString with colors
GetMaterialParameterString usage is less than ideal with color types as you can see from the parsing code, but the attached example should work in most cases, this is something I will work on in a future build of VRayForRhino.
import clr
clr.AddReference("System.Xml")
import System.Xml
from Rhino import *
import rhinoscriptsyntax as rs
def changeColor():
vRay = rs.GetPlugInObject("{E8CFE179-B60C-411A-8416-62A893334519}")
color = clr.Reference[System.Object]()
(result) = vRay.GetMaterialParameterString( "/Blue_Ink/VRayBRDF", "diffuse_color", "color" , color)
colorStr = str(color)
colorStr = colorStr.translate(None, "'")
RhinoApp.WriteLine(colorStr)
r = 0.0
g = 0.0
b = 0.0
try:
if (len(colorStr) == 3) :
r = float.Parse(colorStr[0:1])
g = float.Parse(colorStr[1:2])
b = float.Parse(colorStr[2:3])
elif (len(colorStr) > 6) :
rp = colorStr.find(".", 0)
gp = colorStr.find(".", rp+1)
bp = colorStr.find(".", gp+1)
r = float.Parse(colorStr[rp - 1: gp -2])
g = float.Parse(colorStr[gp - 1: bp -2])
b = float.Parse(colorStr[bp - 1:])
except:
RhinoApp.WriteLine("Error Parse")
r = min( 0.99 , r + 0.1)
g = min( 0.99 , g + 0.1)
b = min( 0.99, b + 0.1)
newColor = "<r>" + str(r) + "</r> <g>" + str(g) + "</g> <b>" + str(b) + "</b>"
vRay.SetMaterialParameterString( "/Blue_Ink/VRayBRDF", "diffuse_color", "color", newColor)
changeColor()