Create linear / rectangular lights in grasshopper!

Hi all

I am aware that Human has a Light component, but i want to create linear or rectangular lights in gh. Searched through the plugins, and i can’t find anything, maybe there is a way or, maybe someone knows how to iterate this in c# or python.

All help appreciated

thanks

Arkadius

found that there are instances like this:

‘rs.LightDirection’

‘rs.RectangularLightPlane’

in rhinoscriptsyntax, but i am unable to write python to this level.

Hi @arkadius.belov,

I’ve tried it inside GHPython and it doesn’t work. It seems as if the lights module is exclusive to Rhino Python (?), meaning that it doesn’t work in Grasshopper.

The scripting part isn’t that difficult though:

import rhinoscriptsyntax as rs

# Create two points for the direction of the light
start_pt = rs.AddPoint((0,5,2.5))
end_pt = rs.AddPoint((0,0,0))

# Create the light
rs.AddDirectionalLight(start_pt, end_pt)

Feel free to try it in Rhino Python, as it works there.

Runtime error (MissingMemberException): ‘GrasshopperDocument’ object has no attribute ‘Lights’

Traceback:
line 35, in AddDirectionalLight, “C:\Users***\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\light.py”
line 16, in script

this is the error i get

As mentioned above:

Yes mate, thanks for your help @diff-arch

@arkadius.belov have you tried the script in Rhino (not Grasshopper)? It sure works there!
Unfortunately, this means that you probably have to script your idea entirely in Rhino Python.

hi @diff-arch

yes thanks alot

for the meantime this looks like the only workaround,

cheers

1 Like

Hi guys. If you want to fiddle with the Rhino document from GHPython, you must explicitly set the script context to target the Rhino document. Here’s one approach:

import Rhino as rc
import scriptcontext as sc
import rhinoscriptsyntax as rs

# Set context to Rhino document and disable redraw
sc.doc = rc.RhinoDoc.ActiveDoc
rs.EnableRedraw(False)

# Fiddle with the Rhino document

# Set context back to Grasshopper
rs.EnableRedraw(True)
sc.doc = ghdoc
2 Likes