Example #1
0
    def to_dict(self):
        d = {}

        d.update( {'quantity':self.quantity} )
        d.update( {'_tolerance':self._tolerance} )
        d.update( {'aperture':self.aperture.to_dict()} )
        d.update( {'_shading_factor_winter':self._shading_factor_winter } )
        d.update( {'_shading_factor_summer':self._shading_factor_summer} )
        d.update( {'install_depth':self.install_depth} )
        d.update( {'variant_type':self.variant_type} )

        _edges = {}
        for k, v in self.window_edges._asdict().iteritems():
            _edges.update( {k:v.to_dict()} )
        d.update( {'_window_edges':_edges} )
        d.update( {'_glazing_edge_lengths':self.glazing_edge_lengths})
        
        _glazing_srfc = to_face3d(self.glazing_surface)
        if _glazing_srfc:
            d.update( {'_glazing_surface':_glazing_srfc[0].to_dict()} )
        
        if self.frame:
            d.update( {'_frame':self.frame.to_dict()} )

        if self.glazing:
            d.update( {'_glazing':self.glazing.to_dict()} )
        
        if self.installs:
            d.update( {'_installs':self.installs.to_dict()} )

        if self.shading_dimensions:
            d.update( {'shading_dimensions':self.shading_dimensions.to_dict() } )

        return d
def inset_LBT_Face3d(_face3d, _inset_dist=0.001):
    rhino_geom = from_face3d(_face3d)
    rhino_geom_inset = inset_rhino_surface(rhino_geom, _inset_dist)
    lbt_face3d = to_face3d(rhino_geom_inset)

    if lbt_face3d:
        return lbt_face3d[0]
    else:
        return None
Example #3
0
    def to_dict(self):
        d = {}

        d.update( {'id':self.id} )
        d.update( {'space_number':self.space_number} )
        d.update( {'space_name':self.space_name} )
        d.update( {'host_room_name':self.host_room_name} )
        d.update( {'params':self.params} )
        d.update( {'area_gross':self.area_gross} )
        d.update( {'depth':self.depth} )

        if self.surface:
            # Remeber, to_face3d returns a LIST of surfaces incase it triangulates
            # so for now, just getitng the first one in that list to pass along
            # Someday this'll break everything...

            lbt_surface = to_face3d(self.surface)
            
            d.update( {'surface_list': lbt_surface[0].to_dict()  } )

        return d
except ImportError as e:
    raise ImportError('\nFailed to import ladybug:\n\t{}'.format(e))

try:
    from ladybug_rhino.config import conversion_to_meters
    from ladybug_rhino.togeometry import to_joined_gridded_mesh3d, to_face3d, \
        to_vector3d
    from ladybug_rhino.fromgeometry import from_mesh3d, from_point3d
    from ladybug_rhino.grasshopper import all_required_inputs, hide_output
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))


if all_required_inputs(ghenv.Component) and _run:
    # set the default offset distance
    _height_limit_ = _height_limit_ if _height_limit_ is not None \
        else 100 / conversion_to_meters()

    # convert geometry, objstacles, and vectors to ladybug_geomtery
    study_mesh = to_joined_gridded_mesh3d(_geometry, _grid_size)
    obstacle_faces = [g for geo in _obstacles for g in to_face3d(geo)]
    sun_vectors = [to_vector3d(vec) for vec in _vectors]

    # compute the solar envelope
    solar_obj = SolarEnvelope(
        study_mesh, obstacle_faces, sun_vectors, _height_limit_, solar_rights_)
    lb_mesh = solar_obj.envelope_mesh()
    mesh = from_mesh3d(lb_mesh)
    points = [from_point3d(pt) for pt in lb_mesh.vertices]
    hide_output(ghenv.Component, 1)
    from ladybug_rhino.grasshopper import all_required_inputs, longest_list, \
        document_counter
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))

if all_required_inputs(ghenv.Component):
    # duplicate the initial objects and process the construction
    rooms = [room.duplicate() for room in _rooms]
    if isinstance(_construction, str):
        _construction = opaque_construction_by_identifier(_construction)

    # determine whether the input _geo_or_area is geometry or floats
    try:
        areas = [float(num) for num in _geo_or_area]
    except AttributeError:  # assume that the input is a list of geometry
        geo = [f for geo in _geo_or_area for f in to_face3d(geo)]
        conversion = conversion_to_meters()**2
        areas = [0 for room in rooms]
        for i, room in enumerate(rooms):
            for face in geo:
                if room.geometry.is_point_inside(face.center):
                    areas[i] += face.area * conversion

    # create the internal mass objects and assign them to the rooms
    for i, room in enumerate(rooms):
        area = longest_list(areas, i)
        if area != 0:
            if len(_name_) == 0:  # make a default Room name
                display_name = 'Internal Mass {}'.format(
                    document_counter('mass_count'))
            else:
except ImportError as e:
    raise ImportError('\nFailed to import ladybug:\n\t{}'.format(e))

try:
    from ladybug_rhino.togeometry import to_gridded_mesh3d, to_mesh3d, \
        to_face3d, to_vector3d
    from ladybug_rhino.fromgeometry import from_mesh3d, from_point3d, from_vector3d
    from ladybug_rhino.grasshopper import all_required_inputs
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))

if all_required_inputs(ghenv.Component):
    # check the input and generate the mesh.
    _offset_dist_ = _offset_dist_ or 0
    if quad_only_:  # use Ladybug's built-in meshing methods
        lb_faces = to_face3d(_geometry)
        try:
            x_axis = to_vector3d(quad_only_)
            lb_faces = [
                Face3D(f.boundary, Plane(f.normal, f[0], x_axis), f.holes)
                for f in lb_faces
            ]
        except AttributeError:
            pass  # no plane connected; juse use default orientation
        lb_meshes = [
            geo.mesh_grid(_grid_size, offset=_offset_dist_) for geo in lb_faces
        ]
        if len(lb_meshes) == 1:
            lb_mesh = lb_meshes[0]
        elif len(lb_meshes) > 1:
            lb_mesh = Mesh3D.join_meshes(lb_meshes)
    if len(_program_) != 0:
        raise ValueError('_program_ has been specified but dragonfly-energy '
                         'has failed to import.\n{}'.format(e))
    elif len(_constr_set_) != 0:
        raise ValueError(
            '_constr_set_ has been specified but dragonfly-energy '
            'has failed to import.\n{}'.format(e))
    elif len(conditioned_) != 0:
        raise ValueError(
            'conditioned_ has been specified but dragonfly-energy '
            'has failed to import.\n{}'.format(e))

if all_required_inputs(ghenv.Component):
    room2d = []  # list of room2ds that will be returned
    face3ds = [face for geo in _geo
               for face in to_face3d(geo)]  # convert to lb geo
    for i, geo in enumerate(face3ds):
        # get the name for the Room2D
        if len(_name_) == 0:  # make a default Room2D name
            display_name = 'Room_{}'.format(document_counter('room_count'))
        else:
            display_name = '{}_{}'.format(longest_list(_name_, i), i + 1) \
                if len(_name_) != len(face3ds) else longest_list(_name_, i)
        name = clean_and_id_string(display_name)

        # create the Room2D
        room = Room2D(name,
                      geo,
                      longest_list(_flr_to_ceiling, i),
                      tolerance=tolerance)
        room.display_name = display_name
Example #8
0
        raise ValueError('rad_mod_ has been specified but honeybee-radiance '
                         'has failed to import.\n{}'.format(e))

if all_required_inputs(ghenv.Component):
    shades = []  # list of shades that will be returned
    for j, geo in enumerate(_geo):
        if len(_name_) == 0:  # make a default Shade name
            name = display_name = clean_and_id_string('Shade')
        else:
            display_name = '{}_{}'.format(longest_list(_name_, j), j + 1) \
                if len(_name_) != len(_geo) else longest_list(_name_, j)
            name = clean_and_id_string(display_name)
        is_detached = not longest_list(attached_,
                                       j) if len(attached_) != 0 else True

        lb_faces = to_face3d(geo)
        for i, lb_face in enumerate(lb_faces):
            shd_name = '{}_{}'.format(name, i) if len(lb_faces) > 1 else name
            hb_shd = Shade(shd_name, lb_face, is_detached)
            hb_shd.display_name = display_name

            # try to assign the energyplus construction
            if len(ep_constr_) != 0:
                ep_constr = longest_list(ep_constr_, j)
                if isinstance(ep_constr, str):
                    ep_constr = shade_construction_by_identifier(ep_constr)
                hb_shd.properties.energy.construction = ep_constr

            # try to assign the energyplus transmittance schedule
            if len(ep_trans_sch_) != 0:
                ep_trans_sch = longest_list(ep_trans_sch_, j)
try:  # import ladybug_rhino dependencies
    from ladybug_rhino.grasshopper import all_required_inputs
    from ladybug_rhino.togeometry import to_mesh3d, to_face3d
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))

if all_required_inputs(ghenv.Component):
    # set the default name and process the points to tuples
    name = clean_and_id_rad_string('SensorGrid') if _name_ is None else _name_
    pts = [(pt.X, pt.Y, pt.Z) for pt in _positions]

    # create the sensor grid object
    id = clean_rad_string(name) if '/' not in name else clean_rad_string(
        name.split('/')[0])
    if len(_directions_) == 0:
        grid = SensorGrid.from_planar_positions(id, pts, (0, 0, 1))
    else:
        vecs = [(vec.X, vec.Y, vec.Z) for vec in _directions_]
        grid = SensorGrid.from_position_and_direction(id, pts, vecs)

    # set the display name
    if _name_ is not None:
        grid.display_name = _name_
    if '/' in name:
        grid.group_identifier = \
            '/'.join(clean_rad_string(key) for key in name.split('/')[1:])
    if mesh_ is not None:
        grid.mesh = to_mesh3d(mesh_)
    if base_geo_ is not None:
        grid.base_geometry = to_face3d(base_geo_)
    perim_offset_ = 0 if perim_offset_ is None else perim_offset_
    buildings = []  # list of buildings that will be returned
    for i, geo in enumerate(_footprint_geo):
        # get the name for the Building
        if len(_name_) == 0:  # make a default Building name
            display_name = 'Building_{}'.format(document_counter('bldg_count'))
            name = clean_and_id_string(display_name)
        else:
            display_name = '{}_{}'.format(longest_list(_name_, i), i + 1) \
                if len(_name_) != len(_footprint_geo) else longest_list(_name_, i)
            name = clean_string(display_name)

        # create the Building
        building = Building.from_footprint(
            name,
            footprint=to_face3d(geo),
            floor_to_floor_heights=_floor_to_floor,
            perimeter_offset=perim_offset_,
            tolerance=tolerance)
        building.display_name = display_name

        # assign the program
        if len(_program_) != 0:
            program = longest_list(_program_, i)
            if isinstance(program, str):
                program = program_type_by_identifier(program)
            building.properties.energy.set_all_room_2d_program_type(program)
        else:  # generic office program by default
            try:
                building.properties.energy.set_all_room_2d_program_type(
                    office_program)
Example #11
0
        _rooms: Honeybee Rooms which will have their Face boundary conditions set
            based on their spatial relation to the _ground geometry below.
        _ground: Rhino Breps or Meshes that represent the Ground.

    Returns:
        rooms: The input Rooms with their Ground boundary conditions set.
"""

ghenv.Component.Name = 'HB Custom Ground'
ghenv.Component.NickName = 'CustomGround'
ghenv.Component.Message = '1.2.1'
ghenv.Component.Category = 'Honeybee'
ghenv.Component.SubCategory = '0 :: Create'
ghenv.Component.AdditionalHelpFromDocStrings = '0'

try:  # import the ladybug_rhino dependencies
    from ladybug_rhino.config import tolerance, angle_tolerance
    from ladybug_rhino.togeometry import to_face3d
    from ladybug_rhino.grasshopper import all_required_inputs
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))


if all_required_inputs(ghenv.Component):
    rooms = [room.duplicate() for room in _rooms]  # duplicate to avoid editing input
    ground_faces = [g for geo in _ground for g in to_face3d(geo)]  # convert to lb geometry

    # loop through the rooms and set the ground boundary conditions
    for room in rooms:
        room.ground_by_custom_surface(ground_faces, tolerance, angle_tolerance)
Example #12
0
ghenv.Component.NickName = 'Terrain'
ghenv.Component.Message = '1.2.0'
ghenv.Component.Category = 'Dragonfly'
ghenv.Component.SubCategory = '4 :: AlternativeWeather'
ghenv.Component.AdditionalHelpFromDocStrings = '2'

try:  # import the dragonfly_uwg dependencies
    from dragonfly_uwg.terrain import Terrain
except ImportError as e:
    raise ImportError('\nFailed to import dragonfly_uwg:\n\t{}'.format(e))

try:
    from ladybug_rhino.togeometry import to_face3d
    from ladybug_rhino.grasshopper import all_required_inputs
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))

if all_required_inputs(ghenv.Component):
    # process the input geometry
    geo = [face for rh_geo in _terrain_geo for face in to_face3d(rh_geo)]

    # assign default values for the pvement properties
    _albedo_ = _albedo_ if _albedo_ is not None else 0.1
    _thickness_ = _thickness_ if _thickness_ is not None else 0.5
    _conductivity_ = _conductivity_ if _conductivity_ is not None else 1.0
    _vol_heat_cap_ = _vol_heat_cap_ if _vol_heat_cap_ is not None else 1.6e6

    # create the terrain
    terrain = Terrain(geo, _albedo_, _thickness_, _conductivity_,
                      _vol_heat_cap_)
Example #13
0
def polygon_to_brep(polygon, z_height):
    """Convert a ladybug Polygon2D or list of polygon2D into Rhino breps."""
    if isinstance(polygon, list):  # face with holes
        verts = []
        for poly in polygon:
            verts.append([Point3D(pt.x, pt.y, z_height) for pt in poly])
        return from_face3d(Face3D(verts[0], holes=verts[1:]))
    else:
        verts = [Point3D(pt.x, pt.y, z_height) for pt in polygon]
        return from_face3d(Face3D(verts))


if all_required_inputs(ghenv.Component):
    # first extract the straight skeleton from the geometry
    polyskel, boundaries, hole_polygons = [], [], []
    for face in to_face3d(_floor_geo):
        # convert the input geometry into Polygon2D for straight skeleton analysis
        boundary = Polygon2D.from_array([(pt.x, pt.y) for pt in face.boundary])
        if boundary.is_clockwise:
            boundary = boundary.reverse()
        holes, z_height = None, face[0].z
        if face.has_holes:
            holes = []
            for hole in face.holes:
                h_poly = Polygon2D.from_array([(pt.x, pt.y) for pt in hole])
                if not h_poly.is_clockwise:
                    h_poly = h_poly.reverse()
                holes.append(h_poly)
        boundaries.append(boundary)
        hole_polygons.append(holes)
        # compute the skeleton and convert to line segments
            display_name = '{}_{}'.format(longest_list(_name_, i), i + 1) \
                if len(_name_) != len(_bldg_geo) else longest_list(_name_, i)
            name = clean_string(display_name)

        # interpret the input _floor_to_floor information
        min, max = geo_min_max_height(geo)
        floor_heights, interpreted_f2f = interpret_floor_height_subdivide(
            _floor_to_floor, max, min)

        # get the floor geometries of the building
        floor_breps = split_solid_to_floors(geo, floor_heights)
        floor_faces = []
        for flr in floor_breps:
            story_faces = []
            for rm_face in flr:
                story_faces.extend(to_face3d(rm_face))
            floor_faces.append(story_faces)

        # create the Building
        building = Building.from_all_story_geometry(
            name, floor_faces, floor_to_floor_heights=interpreted_f2f,
            perimeter_offset=perim_offset_, tolerance=tolerance)
        building.display_name = display_name

        # assign the program
        if len(_program_) != 0:
            program = longest_list(_program_, i)
            if isinstance(program, str):
                program = program_type_by_identifier(program)
            building.properties.energy.set_all_room_2d_program_type(program)
        else:  # generic office program by default
if all_required_inputs(ghenv.Component) and _run:
    perim_offset_ = 0 if perim_offset_ is None else perim_offset_
    buildings = []  # list of buildings that will be returned
    for i, geo in enumerate(_footprint_geo):
        # get the name for the Building
        if len(_name_) == 0:  # make a default Building name
            display_name = 'Building_{}'.format(document_counter('bldg_count'))
            name = clean_and_id_string(display_name)
        else:
            display_name = '{}_{}'.format(longest_list(_name_, i), i + 1) \
                if len(_name_) != len(_footprint_geo) else longest_list(_name_, i)
            name = clean_string(display_name)

        # create the Building
        building = Building.from_footprint(
            name, footprint=to_face3d(geo), floor_to_floor_heights=_floor_to_floor,
            perimeter_offset=perim_offset_, tolerance=tolerance)
        building.display_name = display_name

        # assign the program
        if len(_program_) != 0:
            program = longest_list(_program_, i)
            if isinstance(program, str):
                program = program_type_by_identifier(program)
            building.properties.energy.set_all_room_2d_program_type(program)
        else:  # generic office program by default
            try:
                building.properties.energy.set_all_room_2d_program_type(office_program)
            except (NameError, AttributeError):
                pass  # honeybee-energy is not installed
    from honeybee.typing import clean_and_id_rad_string, clean_rad_string
except ImportError as e:
    raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e))

try:
    from honeybee_radiance.dynamic import StateGeometry
except ImportError as e:
    raise ImportError('\nFailed to import honeybee_radiance:\n\t{}'.format(e))

try:  # import the ladybug_rhino dependencies
    from ladybug_rhino.togeometry import to_face3d
    from ladybug_rhino.grasshopper import all_required_inputs
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))


if all_required_inputs(ghenv.Component):
    geo = []  # list of geometries that will be returned

    # set default name
    name = clean_and_id_rad_string('StateGeo') if _name_ is None \
        else clean_and_id_rad_string(_name_)

    # create the StateGeometry
    i = 0  # iterator to ensure each geometry gets a unique name
    for rh_geo in _geo:
        for lb_face in to_face3d(rh_geo):
            hb_geo = StateGeometry('{}_{}'.format(name, i), lb_face, _modifier_)
            if _name_ is not None:
                hb_geo.display_name = _name_
            geo.append(hb_geo)
                         'has failed to import.\n{}'.format(e))


if all_required_inputs(ghenv.Component):
    context = []  # list of context shades that will be returned
    for i, geo in enumerate(_geo):
        # get the name for the ContextShade
        if len(_name_) == 0:  # make a default name
            display_name = 'Context_{}'.format(document_counter('context_count'))
        else:
            display_name = '{}_{}'.format(longest_list(_name_, i), i + 1) \
                if len(_name_) != len(_geo) else longest_list(_name_, i)
        name = clean_and_id_string(display_name)

        # create the ContextShade object
        df_shd = ContextShade(name, to_face3d(geo))
        df_shd.display_name = display_name

        # try to assign the energyplus construction
        if len(ep_constr_) != 0:
            ep_constr = longest_list(ep_constr_, i)
            if isinstance(ep_constr, str):
                ep_constr = shade_construction_by_identifier(ep_constr)
            df_shd.properties.energy.construction = ep_constr

        # try to assign the energyplus transmittance schedule
        if len(ep_trans_sch_) != 0:
            ep_trans_sch = longest_list(ep_trans_sch_, i)
            if isinstance(ep_trans_sch, str):
                ep_trans_sch = schedule_by_identifier(ep_trans_sch)
            df_shd.properties.energy.transmittance_schedule = ep_trans_sch
Example #18
0
        raise ValueError('ep_constr_ has been specified but honeybee-energy '
                         'has failed to import.\n{}'.format(e))

try:  # import the honeybee-radiance extension
    from honeybee_radiance.lib.modifiers import modifier_by_identifier
except ImportError as e:
    if rad_mod_ is None:
        raise ValueError('rad_mod_ has been specified but honeybee-radiance '
                         'has failed to import.\n{}'.format(e))

if all_required_inputs(ghenv.Component):
    # process the inputs
    rooms = [room.duplicate()
             for room in _rooms]  # duplicate to avoid editing input
    guide_faces = [g for geo in _guide
                   for g in to_face3d(geo)]  # convert to lb geometry
    if type_ is not None and type_ not in face_types:
        type_ = face_types.by_name(type_)
    if bc_ is not None and bc_ not in boundary_conditions:
        bc_ = boundary_conditions.by_name(bc_)
    if isinstance(ep_constr_, str):
        ep_constr_ = opaque_construction_by_identifier(ep_constr_)
    if isinstance(rad_mod_, str):
        rad_mod_ = modifier_by_identifier(rad_mod_)

    # loop through the rooms and set the face properties
    for room in rooms:
        select_faces = room.faces_by_guide_surface(
            guide_faces, tolerance=tolerance, angle_tolerance=angle_tolerance)
        for hb_face in select_faces:
            if type_ is not None: