V-Ray Render Using a Python Script in Grasshopper

Hi,

I’m trying to learn how to use VRayForGrasshopper library in ghpythonlib.components. I created a simple example geometry and tried to render that using a python script. As I understand my script should trigger Vray to render an image and save it in the defined location. I’m not getting any errors when running the script, but the render process is not triggered.

The script I’m running inside a python script component is:


import ghpythonlib.components as ghcomp
import Rhino as r

#create a box
box1 = ghcomp.Box2Pt(‘0,0,0’, ‘5,5,5’, ghcomp.XYPlane(‘0,0,0’))
#create a mesh
box_m = r.Geometry.Mesh.CreateFromBox(box1,1,1,1)
#camera setup
camera_pos = ghcomp.ConstructPoint(-20,-20,10)
camera_target = ghcomp.ConstructPoint(-10,-10,7)
camera1 = ghcomp.VRayForGrasshopper.V_RayCamera(camera_pos,camera_target,fov=50,physical_exposure_on=False)[0]
#save location
imagePath = r"C:\vray_test\paa.png"
#image size
imageSize = [800,600]
#vray render geometry
render_geo = ghcomp.VRayForGrasshopper.V_RayGeometry(box_m)
#vray light rig
lightrig1 = ghcomp.VRayForGrasshopper.V_RayLightRigSimple()
#render
ghcomp.VRayForGrasshopper.V_RayRender(0,1,0,2,imagePath,imageSize,camera1,lightrig1,render_geo )


If get the imagePath, imageSize,camera, lightrig and reneder geometry variables as outputs from my python script component and plug the into a VRay Render component in Grasshopper, then right click on that component, it will render and and save the image in the specified location.

Does anyone know what I’m doing wrong? Should the ghcomp.VRayForGrasshopper.V_RayRender function trigger the render process or do I need to still trigger the render process somehow?

Hi, Antti Rantamaki

It works on my machine

import ghpythonlib.components as ghcomp

#create a box
box1 = ghcomp.Box2Pt(‘0,0,0’, ‘5,5,5’, ghcomp.XYPlane(‘0,0,0’))
#camera setup
camera_pos = ghcomp.ConstructPoint(-20,-20,10)
camera_target = ghcomp.ConstructPoint(-10,-10,7)

a = 0
b = 1
c = 0
d = 2
e = r"D:\paa.png"
f = [800,600]
g = ghcomp.VRayForGrasshopper.V_RayCamera(camera_pos,camera_target,fov=50,physical_exposure_on=False)[0]
h = ghcomp.VRayForGrasshopper.V_RayGeometry(box1)

image

It does render and saves to an image file

thanks for your reply Nikolay! Sorry if my original post was a bit cryptic… If I understand your reply correctly, you are using the VRay Render grasshopper component to trigger the rendering. What I was trying to do was to trigger the render inside the script i.e. without using the VRay Render component and without having to manually right click to trigger the rendering. I thought the VRayForGrasshopper.V_RayRender() function would do that.

Currently there is no exposed API for that. Your only option is to call private methods using reflection. On your own risk.
I get such a request twice now, we should probably do something…

okay, thanks for the info. Calling private functions seems a bit too difficult for me. I can get a list of methods usings pythons dir() function, but I can’t really figure out what method to use and how. Anyway, I feel like having this option available would be quite useful.