Command for Saving VRMAT Files

So I understand there is the SaveVisopt command to view and edit VRay Options.

vRay = rs.GetPlugInObject("V-Ray for Matrix")
vRay.SaveVisopt('c:/temp.vropt')

Is there a similar command to access the options of the VRay materials editor? SaveVismat doesn’t seem to exist!

Check this thread:

This might lead you in the right direction…

@dale

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.

@matt_newberg, anything you can add to this conversation would be great.

1 Like

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")
1 Like

You can also read/modify the materials by using the script functions:

GetMaterialParameterFloat
GetMaterialParameterBool
GetMaterialParameterInteger
GetMaterialParameterCompTransform
GetMaterialParameterString

SetMaterialParameterFloat
SetMaterialParameterBool
SetMaterialParameterInteger
SetMaterialParameterCompTransform
SetMaterialParameterString

Below is a sample of using one of these functions:

import clr  
clr.AddReference("System.Xml")  
import System.Xml
from Rhino import *
import rhinoscriptsyntax as rs

def changeAlpha():
	
	vRay = rs.GetPlugInObject("{E8CFE179-B60C-411A-8416-62A893334519}")
	
	alpha = clr.Reference[System.Object]()
	(result) = vRay.GetMaterialParameterFloat( "/Test", "alpha", alpha)
	
	alpha.Value -= 0.1
	
	RhinoApp.WriteLine(str(alpha.Value))
	
	vRay.SetMaterialParameterFloat( "/Test", "alpha", alpha)
	
changeAlpha()
2 Likes

@matt_newberg makes me a very lazy programmer because he leaves no room for exercising my own head :slight_smile: …only kidding; your help is much appreciated. Thanks!

Is System.Object a reference to Javascript?

Also, what is that plugin object string you passed to GetPlugInObject?

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.

1 Like

@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:

transparency.Value= "<r>1.000000</r> <g>1.000000</g> <b>1.000000</b>"

@krsnadas

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()
2 Likes

Thanks so much, @matt_newberg.