예제 #1
0
def set_sun(location, hoy, north=0):
    """Set the sun in the Rhino scene to correspond to a given location and DateTime.

    Args:
        location: A Ladybug Location object to set the latitude, longitude and
            time zone of the Rhino sun path.
        hoy: A number between 0 and 8760 that represent the hour of the year at
            which to evaluate the sun position. Note that this does not need to
            be an integer and decimal values can be used to specify date times
            that are not on the hour mark.
        north: A number between -360 and 360 for the counterclockwise
            difference between the North and the positive Y-axis in degrees.
            90 is West and 270 is East. (Default: 0).

    Returns:
        The Rhino sun object.
    """
    # process the hoy into a .NET date/time
    lb_dt = DateTime.from_hoy(hoy)
    rh_dt = System.DateTime(lb_dt.year, lb_dt.month, lb_dt.day, lb_dt.hour,
                            lb_dt.minute, 0)

    # enable the sun and set its position based on the location and date/time
    sun_position = doc.Lights.Sun
    sun.Enabled.SetValue(sun_position, True)
    sun.TimeZone.SetValue(sun_position, location.time_zone)
    sun.SetPosition(sun_position, rh_dt, location.latitude, location.longitude)

    # set the north of the sun, ensuring the the y-axis is North
    sun.North.SetValue(sun_position, 90 + north)
    return sun
예제 #2
0
def main(location, month, day, hour, north, lb_preparation):
    # Set defaults
    if month == None:
        month = 12
    if day == None:
        day = 21
    if hour == None:
        hour = 12

    # From _location split and referense latitude, longitude and timezone
    lat = (location.split("\n"))[2]
    latitude = lat.split(",")[0]
    long = (location.split("\n"))[3]
    longitude = long.split(",")[0]
    off = (location.split("\n"))[4]
    offset = off.split(",")[0]
    offset = int(math.ceil(float(offset)))

    h = int(math.modf(hour)[1])
    m = int(60 * (math.modf(hour)[0]))
    date = ghp.ConstructDate(2017, month, day, h, m, 0)
    sunPosition = Rhino.RhinoDoc.ActiveDoc.Lights.Sun
    sun.Enabled.SetValue(sunPosition, True)
    sun.TimeZone.SetValue(sunPosition, offset)
    sun.SetPosition(sunPosition, date, float(latitude),
                    float(longitude))  #Adjust _location and Date of Rhino Sun

    print "Sun position latitude / longitude set to: " + str(
        latitude) + " / " + longitude
    print "Sun position date set to: " + str(date)

    if sun.Altitude.Info.GetValue(sunPosition) > 0:
        #set Orientation
        if north == None:
            sun.North.SetValue(sunPosition, 90)
        else:
            northAngle, northVector = lb_preparation.angle2north(north)
            sun.North.SetValue(sunPosition, (90 + math.degrees(northAngle)))
            print "North angle set to : " + str(math.degrees(northAngle))
def main():
    if _runIt == True:
        #Give priority to analysisPeriod over Month/Day/Hour.
        if analysisPeriod_ != None:
            Months = int((analysisPeriod_)[0][0])
            Days = int((analysisPeriod_)[0][1])
            for hourRange in range((int((analysisPeriod_)[0][2]) * 100), (int(
                (analysisPeriod_)[1][2]) * 100), int((1 / _timeStep_) * 100)):
                H = int(math.modf(hourRange / 100)[1])
                M = int(60 * (math.modf(hourRange / 100)[0]))
                Date = ghp.ConstructDate(
                    2015, Months, Days, H, M,
                    0)  #Date = ghp.ConstructDate(2015,Months,Days,H,M,0)
                Sunposition = Rhino.RhinoDoc.ActiveDoc.Lights.Sun  #Link grasshopper definition to Rhino Sun system
                sun.Enabled.SetValue(Sunposition, True)
                sun.TimeZone.SetValue(Sunposition, offset)
                sun.SetPosition(
                    Sunposition, Date, float(Latitude),
                    float(Longitude))  #Adjust _location and Date of Rhino Sun
                if sun.Altitude.Info.GetValue(Sunposition) > 10:
                    #set Orientation
                    if North_ == None:
                        sun.North.SetValue(Sunposition, 90)
                    else:
                        if type(North_) is float:
                            sun.North.SetValue(Sunposition, (90 - North_))
                        else:
                            #Set North
                            zero = Rhino.Geometry.Vector3d(1.0, 0.0, 0.0)
                            Xaxis = Rhino.Geometry.Vector3d(0.0, 0.0, 1.0)
                            Origin = Rhino.Geometry.Point3d(0.0, 0.0, 0.0)
                            Plane = Rhino.Geometry.Plane(Origin, Xaxis)
                            angle = Rhino.Geometry.Vector3d.VectorAngle(
                                zero, North_, Plane)
                            sun.North.SetValue(Sunposition,
                                               math.degrees(angle))
                    if _render_ == True:
                        rs.Command(
                            "!_render"
                        )  #send the command to render on your active renderer
                        if _save_ == True:  #Enable to save the view as a .png
                            dir = str(
                                _workingDir_
                            )  #Define the path, if path does not exist, create, otherwise use existing one
                            rs.Command("_-SaveRenderWindowAs \"" + (dir) +
                                       "\\" + str(StrMonth[int(Months) - 1]) +
                                       "_" + str(H) + "_" + str(M) + ".png\"")
                            rs.Command(
                                "_-CloseRenderWindow"
                            )  #close the rendered window when in saving mode to avoid stacking a series of renderWindows when running on Rhino renderer.
                    else:
                        if _save_ == True:
                            dir = str(
                                _workingDir_
                            )  #Define the path, if path does not exist, create, otherwise use existing one
                            rs.Command("_-ViewCaptureToFile \"" + dir + "\\" +
                                       str(StrMonth[int(Months) - 1]) + "_" +
                                       str(H) + "_" + str(M) + ".png\"" +
                                       " w " + str(viewWidth_) + " " + "h " +
                                       str(viewHeight_) + " " + " enter")
                else:
                    DarkHours = (str(StrMonth[int(Months) - 1]) + "_" +
                                 str(H) + "_" + str(M) + " is Nighttime")
        else:
            Hours = _Hour_
            Months = _Month_
            Days = _Day_
            H = int(math.modf(Hours)[1])
            M = int(60 * (math.modf(Hours)[0]))
            Date = ghp.ConstructDate(
                2015, Months, Days, H, M,
                0)  #Date = ghp.ConstructDate(2015,Months,Days,H,M,0)
            Sunposition = Rhino.RhinoDoc.ActiveDoc.Lights.Sun  #Link grasshopper definition to Rhino Sun system
            sun.Enabled.SetValue(Sunposition, True)
            sun.TimeZone.SetValue(Sunposition, offset)
            sun.SetPosition(
                Sunposition, Date, float(Latitude),
                float(Longitude))  #Adjust _location and Date of Rhino Sun
            if sun.Altitude.Info.GetValue(Sunposition) > 10:
                #set Orientation
                if North_ == None:
                    sun.North.SetValue(Sunposition, 90)
                else:
                    if type(North_) is float:
                        sun.North.SetValue(Sunposition, (90 - North_))
                    else:
                        #Set North
                        zero = Rhino.Geometry.Vector3d(1.0, 0.0, 0.0)
                        Xaxis = Rhino.Geometry.Vector3d(0.0, 0.0, 1.0)
                        Origin = Rhino.Geometry.Point3d(0.0, 0.0, 0.0)
                        Plane = Rhino.Geometry.Plane(Origin, Xaxis)
                        angle = Rhino.Geometry.Vector3d.VectorAngle(
                            zero, North_, Plane)
                        sun.North.SetValue(Sunposition, math.degrees(angle))
                if _render_ == True:
                    rs.Command(
                        "!_render"
                    )  #send the command to render on your active renderer
                    if _save_ == True:  #Enable to save the view as a .png
                        dir = str(
                            _workingDir_
                        )  #Define the path, if path does not exist, create, otherwise use existing one
                        if os.path.exists(dir) == False:
                            os.mkdir(dir)
                        rs.Command("_-SaveRenderWindowAs \"" + (dir) + "\\" +
                                   str(StrMonth[int(Months) - 1]) + "_" +
                                   str(H) + "_" + str(M) + ".png\"")
                        rs.Command(
                            "_-CloseRenderWindow"
                        )  #close the rendered window when in saving mode to avoid stacking a series of renderWindows when running on Rhino renderer.
                        imagePath = (dir + "\\" +
                                     str(StrMonth[int(Months) - 1]) + "_" +
                                     str(H) + "_" + str(M) + ".png")
                        return imagePath
                else:
                    if _save_ == True:
                        dir = str(
                            _workingDir_
                        )  #Define the path, if path does not exist, create, otherwise use existing one
                        rs.Command("_-ViewCaptureToFile \"" + (dir) + "\\" +
                                   str(StrMonth[int(Months) - 1]) + "_" +
                                   str(H) + "_" + str(M) + ".png\"" + " w " +
                                   str(viewWidth_) + " " + "h " +
                                   str(viewHeight_) + " " + " enter")
                        imagePath = (dir + "\\" +
                                     str(StrMonth[int(Months) - 1]) + "_" +
                                     str(H) + "_" + str(M) + ".png")
                        return imagePath
            else:
                pass
    else:
        return -1