Control intensity light python

Is it possible to control the light intensity of a rectangular light or other type with script python?

May not be the most correct method but works here:

import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc
    
#get the guid
light = rs.GetObject('pick light')
#get the rhino doc object
rObject = rs.coercerhinoobject(light)
#get the rhino geometry of the doc object
lightGeometry = rObject.Geometry
#print intensity value as a check
print lightGeometry.Intensity
#get new intensity value from user
newIntensity = rs.GetReal('enter new intensity (0.0-1.0):', number=None, minimum=0.0, maximum=1.0)
#set new intensity value in light geometry
lightGeometry.Intensity = newIntensity
#print as a check
print lightGeometry.Intensity
#call the commit on the rhino doc object which pushes the new intensity from geometry to document
rObject.CommitChanges()
#redraw the viewports
rs.Redraw()

Nathancoatney, thank you very much. Works well

Is there a way to do this when V-Ray is involved? Nathancoatney’s code worked for me when using the Rhino Renderer but will not stick when using V-Ray. Maybe @matt_newberg might have some clues?

Are you looking to change the light intensity in V-Ray 2 for Rhino or V-Ray 3 for Rhino?

V-Ray 3

Hopefully this should meet your needs, if you need anything more complicated let me know.

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

def changeLight():
    
    vRay = rs.GetPlugInObject("{E8CFE179-B60C-411A-8416-62A893334519}")
    
    objectName = "V-Ray Spot Light"
    
    intensity = clr.Reference[System.Object]()
    (result) = vRay.GetLightParameterFloat( "/" +objectName, "intensity", intensity)
    
    print objectName
    print "Intensity:" , intensity.Value;
    
    if result:
        intensity.Value = min(100 , max( 0.0 , intensity.Value + 1))
         
        vRay.SetLightParameterFloat( "/" +objectName, "intensity", intensity)
     
changeLight()

Thanks @matt_newberg, that totally worked!

Sorry to bother you since it is an old post. I’m wondering whether it is possible to use python script to control the intensities of the spotlights by inputting an array which represents the intensities of each lights? By the way I am using V-ray2 for Rhino.
Thank you so much.

@matt_newberg
Is there any documentation on accessing Vray with rhinocommon? I looked at help docs on chaosgroup site but can’t seem to find anything.

Thanks.

@nathancoatney

There is a .NET DLL that is not documented:

C:\Program Files\Chaos Group\V-Ray\V-Ray 3.4 for Rhinoceros 5\VRayForRhinoNETInterface.dll

and

C:\ProgramData\ASGVIS\VfR564\VRayForRhinoNETInterface.dll

Adding that reference to your C Sharp project and viewing all the functions would be a good first step.

A few functions do not work in V-Ray 3, so if something doesn’t work right away please post.

What are you trying to do and in what language? Maybe I can write a little demo up.

@matt_newberg

Ok thanks. I will see if I still have these dlls from the demo install.

I don’t have a specific need currently, I am just trying to decide if I want to purchase V-Ray 3. If there is some api exposure for material creation/assignment and instancing then that makes it easier to decide.

@nathancoatney

With V-Ray 3 and the new online licensing the demo install is the exact same exe as the full version. We just limit the number of days you can use it via online licensing.

The V-Ray material format is XML, you can edit the XML in a file, and then load and apply the material with the current interface. The two functions you would use are:

bool LoadVismat(string filename)
bool ApplyVRayMaterialToObjects(string filename, ICollection<Rhino.DocObjects.RhinoObject> objects)

That will most likely meet your needs, but it would be helpful to know more about your final goal.

@matt_newberg
Sorry to bother you since it is an old post. I’m wondering whether it is possible to use python script to control the intensities of the spotlights on V-ray 2.0 for Rhino?
Thank you so much.

@lytsophy haven’t tested this in 2.0, but this should work:

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

def changeLight():
    
    vRay = rs.GetPlugInObject("{E8CFE179-B60C-411A-8416-62A893334519}")
    
    light = rs.GetObject("Select a light")
    
    intensity = clr.Reference[System.Object]()
    (result) = vRay.GetLightParameterFloat( "/" + str(light), "intensity", intensity)
    
    print str(light)
    print "Intensity:" , intensity.Value;
    
    if result:
        intensity.Value = min(100 , max( 0.0 , intensity.Value + 1))
        
    
        vRay.SetLightParameterFloat( "/" +str(light), "intensity", intensity)
     
changeLight()