Hi everyone. I am working with sun analysis tools in API and I need to set the sun position based on a specific time and date. I searched in commands and I could just found the option for defining the sun position based on the frame number. Is there any command for setting the sun position based on time and date?
and finally, In this method, I can get the sun direction for each day and time
def SunDirection ():
t=Transaction(doc, “Assigning the values”)
settings.SunAndShadowType = SunAndShadowType.StillImage
return specTime, e180/(math.pi)
I have written this function to get the sun Azimuth. the only problem is that the sun position does not update based on the given date and time and gets this info from the sun setting pannel in Revit. does anybody know the sun position can be updated?
I did not look to much into it but the code I did might help you to get there
There is an issue, probably a know one, with the sun (physical geometry in the trajectory) that does not update in terms of location if you don’t ‘touch’ it. The trick I use is to set a parameter to a certain value in another transaction and then set it back to its previous value.
import clr clr.AddReference('System') import System from pyrevit import DB, revit, script, HOST_APP output = script.get_output() # Close other output when launched several times close_other_output = output.close_others(all_open_outputs=True) doc = revit.doc view = doc.ActiveView uidoc = HOST_APP.uidoc DT = System.DateTime.Now with revit.Transaction ('Set sun Date and Time to Now'): settings_sun = view.SunAndShadowSettings settings_sun.StartDateAndTime = DT # or settings_sun.EndDateAndTime = DT # Make newly created view active uidoc.RequestViewChange(view) # Maybe overkill uidoc.RefreshActiveView() doc.Regenerate() with revit.Transaction ('Touch and Go'): # as the physical sun does not seem to move even though the parameters are really passed through, a touch and go is mandatory to refresh its position in the active view sun_path_size = settings_sun.get_Parameter(DB.BuiltInParameter.VIEW_GRAPH_SUN_PATH_SIZE).AsInteger() temp_sun_path_size = sun_path_size param = settings_sun.Parameter[DB.BuiltInParameter.VIEW_GRAPH_SUN_PATH_SIZE] param.Set(10) param.Set(temp_sun_path_size) print (view.Name) print (DT) print (param.AsInteger())
I hope that helped a bit
Sorry for my late reply. it is great and working as I expected. thank you so much