Script that returns environment texture file name


#1

I am trying to find a way to code the steps below and just return a file name, it would be a bonus if it would let me know if it’s a broken path.

From Vray Options under environment I need the full file name of the background. I have been looking through the VRayForRhino.tlb file under the ProgramData folder, but I haven’t found a solution.


(Dale Fugier) #2

@matt_newberg is this something you can help with?


#3

@ariel

Currently there is no way to set that via the rhinoscript interface. The best way to go about changing/reading a setting like that is saving/reading the visopt via SaveVisopt and LoadVisopt.

Here is an example

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

def test():
	
	vRay = rs.GetPlugInObject("V-Ray for Rhino")
	vRay.SaveVisopt('c:/temp.vropt')
	
	xmldoc = System.Xml.XmlDocument()  
	xmldoc.Load('c:/temp.vropt')
	
	itemurl = ""
	items = xmldoc.ChildNodes[0].ChildNodes
	for item in items:  
		if item.Attributes["url"].Value == "/SettingsEnvironment/bg_tex":
			for child in item.FirstChild.FirstChild.FirstChild.ChildNodes:
				if child.Attributes["name"].Value == "color_a":
					itemurl = child.InnerText
					
	bitmapBufferurl = ""
	for item in items:  
		if item.Attributes["url"].Value == itemurl:
			for child in item.FirstChild.FirstChild.FirstChild.ChildNodes:
				if child.Attributes["name"].Value == "bitmap":
					bitmapBufferurl = child.InnerText
					
	filename = ""
	for item in items:  
		if item.Attributes["url"].Value == bitmapBufferurl:
			for child in item.FirstChild.FirstChild.FirstChild.ChildNodes:
				if child.Attributes["name"].Value == "file":
					filename = child.InnerText
	
	RhinoApp.WriteLine(filename)

test()

What are you trying to do with the background HDR?


#4

It is for logging purposes. I honestly want to make sure the path to the background HDR isn’t broken. Also interested in changing the multiplier value of the background HDR to 0.85.


#5

@matt_newberg Do you know how to script the multiplier value of the background HDR? (picture in the post above)


#6

@ariel

Attached is a python script that does what you want.

In a future version of V-Ray for Rhino we will have Rhinoscript functions to access these variables without saving and loading the xml.

import clr  
clr.AddReference("System.Xml")  
import System.Xml
from System.IO import Directory, Path
from Rhino import *
import rhinoscriptsyntax as rs

def changeMultiplier():
	
	tempFilenameSave = Path.GetTempFileName() + ".vropt"
	tempFilenameLoad = Path.GetTempFileName() + ".vropt"
	
	vRay = rs.GetPlugInObject("V-Ray for Rhino")
	vRay.SaveVisopt(tempFilenameSave)
	
	xmldoc = System.Xml.XmlDocument()  
	xmldoc.Load(tempFilenameSave)
	xmldoc.Save(tempFilenameSave)
	
	amountString = "0.85"
	
	items = xmldoc.ChildNodes[0].ChildNodes
	for item in items:  
		if item.Attributes["url"].Value == "/SettingsEnvironment/bg_tex":
			for child in item.FirstChild.FirstChild.FirstChild.ChildNodes:
				if child.Attributes["name"].Value == "mult_a":
					child.InnerXml = "<value>" + amountString + "</value>"
					
	items = xmldoc.ChildNodes[0].ChildNodes
	for item in items:  
		if item.Attributes["url"].Value == "/SettingsEnvironment":
			for child in item.FirstChild.FirstChild.FirstChild.ChildNodes:
				if child.Attributes["name"].Value == "bg_tex_mult":
					child.InnerXml = "<value>" + amountString + "</value>"
	
	xmldoc.Save(tempFilenameLoad)
	vRay.LoadVisopt(tempFilenameLoad)
	

changeMultiplier()

#7

Matt,

Thank you so much!


#8

@matt_newberg

Thanks for sharing this script. It is being very useful. Are there any System.Xml methods to write into the XML file? What I’m trying to do is load a HDR Environment Map into VRay using the script so I plan to call the HDR file’s path here in the parameter values of the XML document.

Thank you!


#9

Also, my script is returning an error that ‘vRay.SaveVisopt’ is not identified.


#10

SaveVisopt has been in the V-Ray for Rhino interface for years, I am guessing there is something else wrong with your script.


#11

Below is what you need to read and set the filename:

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

def test():
	
	vRay = rs.GetPlugInObject("V-Ray for Rhino")
	vRay.SaveVisopt('c:/temp.vropt')
	
	xmldoc = System.Xml.XmlDocument()  
	xmldoc.Load('c:/temp.vropt')
	
	itemurl = ""
	items = xmldoc.ChildNodes[0].ChildNodes
	for item in items:  
		if item.Attributes["url"].Value == "/SettingsEnvironment/bg_tex":
			for child in item.FirstChild.FirstChild.FirstChild.ChildNodes:
				if child.Attributes["name"].Value == "color_a":
					itemurl = child.InnerText
					
	bitmapBufferurl = ""
	for item in items:  
		if item.Attributes["url"].Value == itemurl:
			for child in item.FirstChild.FirstChild.FirstChild.ChildNodes:
				if child.Attributes["name"].Value == "bitmap":
					bitmapBufferurl = child.InnerText
					
	filename = ""
	for item in items:  
		if item.Attributes["url"].Value == bitmapBufferurl:
			for child in item.FirstChild.FirstChild.FirstChild.ChildNodes:
				if child.Attributes["name"].Value == "file":
					filename = child.InnerText
	
	RhinoApp.WriteLine(filename)
	
	newFile = "c:/ProgramData/ASGVIS/Options/RhinoDefault.exr"
	filename = ""
	for item in items:  
		if item.Attributes["url"].Value == bitmapBufferurl:
			for child in item.FirstChild.FirstChild.FirstChild.ChildNodes:
				if child.Attributes["name"].Value == "file":
					child.InnerXml = "<value>" + newFile + "</value>"
					filename = child.InnerText
	
	xmldoc.Save('c:/temp.vropt')
	vRay.LoadVisopt('c:/temp.vropt')
	
	RhinoApp.WriteLine(filename)

test()

#12

Thanks a lot, Matthew! This is a mountain of help :-]


#13

@matt_newberg I’m just curious why we have to obtain bitmapbufferurl before obtaining filename. Can we not just directly parse for “/SettingsEnvironment/TextureBG/BitmapBuffer”?


#14

@krsnadas That is done to match exactly how V-Ray For Rhino looks for the environment texture, if you control your visopt/vropt setting you can skip that step.


#15

Ah, that makes sense. I suspected that would be the case. Thanks again, Matt :-]