Render Sun Study

Hi there,

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.

My questions:

  1. Is it possible to update the python component output (date_out) in realtime, while looping over my list?
  2. 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?

Any help is much appreciated, thanks!

M (18.6 KB)

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

    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)


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 :wink:
(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!

Alright, with the help of your code I managed to finish my script. Rhino.RhinoDoc.ActiveDoc.Lights.Sun is what I was missing.

Works fine now. Thank you!

import rhinoscriptsyntax as rs
import Rhino

sun = Rhino.RhinoDoc.ActiveDoc.Lights.Sun
rendered_dates = []
count = 0

if active:
    if GMT:  # Set Time Zone
        sun.TimeZone = int(GMT)
    if DST:  # Turn on Day Saving Time 
        sun.DaylightSaving = DST
    if N:  # Adjust North angle. Default = 90°
        sun.North = int(N)
        sun.North = 90
    for date in date_in:
        count += 1
        sun.SetPosition(date, float(LAT), float(LON))
        date = str(date)[:-2]
        date = date.replace(' ', '_').replace('/', '-').replace(':', '')
        filename = filepath + prefix + '_' + str(count) + '_' + date + ".png"
        rs.Command("_-SaveRenderWindowAs \n\"" + filename + "\"\n") 

    print("Rendered: " + "\n" + "\n".join(rendered_dates)) (10.7 KB)

1 Like