I’m trying to write a gh/python script to render multiple sun settings (dates) of a scene for a sun study. Ideally I’d like to input my dates to render and then have gh and vray do the rest.
I found a very useful C# component to access the sun through gh (link) but I’m not very familiar with C#. with python, I’m not able to loop over my list of date inputs and update the sun before I render, because the python script only updates its output once it completed the whole python component.
Is it possible to update the python component output (date_out) in realtime, while looping over my list?
Probably a better solution would be to access the Rhino sun directly through that same script. I tried sun.SetPosition(DT, float(LAT), float(LON)) but it always set the time to my system DateTime, I somehow never managed to use my input DateTime. (see screenshot. I don’t really understand the documentation…)
What am I missing?
I dug through my old script bits (from a pretty cool sun study ramp image generator I made for inhouse use) that might help you along:
You have to turn on SUN and the global position in the panel first though. This is just to set the sun.
### Simple set hour for sun study by HOLO ###
import Rhino
import rhinoscriptsyntax as rs
def SetDateTime(YEAR,MONTH,DAY,HOURS,MINUTES):
from datetime import datetime
date = datetime(YEAR, MONTH, DAY, HOURS, MINUTES)
print "DATE "+str(YEAR)+","+str(MONTH)+","+str(DAY)+" TIME: "+str(HOURS)+","+str(MINUTES)
RhinoSun = Rhino.RhinoDoc.ActiveDoc.Lights.Sun
latitude = RhinoSun.Latitude
longitude = RhinoSun.Longitude
Rhino.Render.Sun.SetPosition(RhinoSun, date, latitude, longitude)
HOUR = rs.GetInteger(message="Set Hour", number=None, minimum=0, maximum=24)
MINUTES = 0
MONTH=05
DAY=01
YEAR=2019
SetDateTime(YEAR,MONTH,DAY,HOUR,MINUTES)
And to inspire your further development, her is the result of the sunstudy tool I made for our use.
It uses a custom display mode with all white objects and recalculates all pixles from gray scale to a color scale to strengthen the perseption of what is in sun light and what is in shade, and to make it look cool and professional of course
(I can not share the code for that though)
Thanks for your code!
I won’t be home until later today but I‘ll definitely try your script. Your sun display mode looks pretty cool, that’s a great idea!
After playing with it using simple 3D scene, I got it to render all the frames (dates) using Rhino’s render. But when switching to V-Ray engine, it outputs 4 of the 8 frames correctly, and the other 4 are 100% black images.
I was asked if one can set multiple times for the sun study and here is a simple version for that:
### Simple set sun animation by Holo - version 2.0 ###
import Rhino
import rhinoscriptsyntax as rs
def SetDateTime(YEAR,MONTH,DAY,HOURS,MINUTES):
from datetime import datetime
date = datetime(YEAR, MONTH, DAY, HOURS, MINUTES)
print "DATE "+str(YEAR)+","+str(MONTH)+","+str(DAY)+" TIME: "+str(HOURS)+":"+str(MINUTES)
RhinoSun = Rhino.RhinoDoc.ActiveDoc.Lights.Sun
# Make sure the sun is "on"
if not RhinoSun.Enabled: RhinoSun.Enabled = True
latitude = RhinoSun.Latitude
longitude = RhinoSun.Longitude
Rhino.Render.Sun.SetPosition(RhinoSun, date, latitude, longitude)
rs.Redraw()
HOUR = 0
MINUTES = 0
MONTH=05
DAY=01
YEAR=2019
# Set i as a variable that goes from 8 to 18; one step for each hour the sun is up
for i in range(8,18):
# Set ii as a variable that goes from 0 to 6 and is then multiplied by 10 in the command to make 10 minutes increments for each hour
for ii in range(6):
# Now set the time for each ten minutes of each hour
SetDateTime(YEAR,MONTH,DAY,HOUR+i,MINUTES+(ii*10))
# Here you can add other features too, like saving the images.