Ejemplo n.º 1
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))
Ejemplo n.º 2
0
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