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

Sun_test.gh (18.6 KB)

1 Like

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 :wink:
(I can not share the code for that though)

2 Likes

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)
    else:
        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("!_-Render")
        rs.Command("_-SaveRenderWindowAs \n\"" + filename + "\"\n") 
        rs.Command("_-CloseRenderWindow")
        rendered_dates.append(filename)

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

sun_mf.gh (10.7 KB)

2 Likes

Hi 7556,

First of all, thanks for sharing your GH code!

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.

Have any idea why that happens?

Thanks!
H.

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.