def _inset_floor_surfaces( _floor_surface, _inset_dist, _ghenv ): '''Shrinks/Insets the surface by the specified amount ''' try: rh_srfc = from_face3d(_floor_surface.geometry) except Exception as e: msg = 'Error. Can not convert floor surface: "{}" to Rhino geometry?'.format( _floor_surface ) _ghenv.Component.AddRuntimeMessage(ghK.GH_RuntimeMessageLevel.Remark, msg) return None if _inset_dist < 0.001: return rh_srfc #----------------------------------------------------------------------- srfcPerim = ghc.JoinCurves( ghc.BrepEdges(rh_srfc)[0], preserve=False ) # Get the inset Curve srfcCentroid = Rhino.Geometry.AreaMassProperties.Compute(rh_srfc).Centroid plane = ghc.XYPlane(srfcCentroid) srfcPerim_Inset_Pos = ghc.OffsetCurve(srfcPerim, _inset_dist, plane, 1) srfcPerim_Inset_Neg = ghc.OffsetCurve(srfcPerim, _inset_dist*-1, srfcCentroid, 1) # Choose the right Offset Curve. The one with the smaller area srfcInset_Pos = ghc.BoundarySurfaces( srfcPerim_Inset_Pos ) srfcInset_Neg = ghc.BoundarySurfaces( srfcPerim_Inset_Neg ) area_Pos = ghc.Area(srfcInset_Pos).area area_neg = ghc.Area(srfcInset_Neg).area if area_Pos < area_neg: return srfcInset_Pos else: return srfcInset_Neg
def _get_verts(obj): brp_edges = ghc.DeconstructBrep(obj).edges brp_perim = ghc.JoinCurves(brp_edges, True) brp_verts = ghc.ControlPoints(brp_perim).points brpC = ghc.CullDuplicates(brp_verts, 0.0).points verts = (ev.from_Rh_points(vert) for vert in brpC) #brp_verts return list(verts)
def brep_polyloops(brep): """ Returns the polyloop of all faces for a brep""" faces = ghc.DeconstructBrep(brep)[0] polyloops = [] for face in faces: edges = ghc.DeconstructBrep(face)[1] polyline = ghc.JoinCurves(edges, False) vertices = ghc.Explode(polyline, recursive=True)[1] polyloops.append(vertices) return polyloops
def getWindowBasics(_in): with idf2ph_rhDoc(): # Get the Window Geometry geom = rs.coercegeometry(_in) windowSurface = ghc.BoundarySurfaces(geom) # Inset the window just slightly. If any windows touch one another or the zone edges # will failt to create a proper closed Brep. So shink them ever so slightly. Hopefully # not enough to affect the results. windowPerim = ghc.JoinCurves(ghc.DeconstructBrep(windowSurface).edges, preserve=False) try: windowPerim = ghc.OffsetonSrf( windowPerim, 0.004, windowSurface) # 0.4mm so hopefully rounds down except: windowPerim = ghc.OffsetonSrf(windowPerim, -0.004, windowSurface) windowSurface = ghc.BoundarySurfaces(windowPerim) # Pull in the Object Name from Rhino Scene windowName = None try: windowName = rs.ObjectName(_in) except: warning = "Can't get the Window name from Rhino for some reason?\n"\ "If you are passing in Rhino Geometry, double check you have named all the surfaces?\n"\ "If you are passing in Grasshopper geometry though, ignore this message." ghenv.Component.AddRuntimeMessage( ghK.GH_RuntimeMessageLevel.Remark, warning) windowName = windowName if windowName != None else 'Unnamed_Window' windowName = cleanUpName(windowName) # Double check that the surface Normal didn't get flipped c1 = ghc.Area(geom).centroid n1 = rs.SurfaceNormal(geom, c1) c2 = ghc.Area(windowSurface).centroid n2 = rs.SurfaceNormal(windowSurface, c2) normAngleDifference = ghc.Degrees(ghc.Angle(n1, n2).angle) if round(normAngleDifference, 0) != 0: # Flip the surface if it doesn't match the source windowSurface = ghc.Flip(windowSurface).surface return windowName, windowSurface
def set_values_by_hb_room(self, _hb_room): """ Finds the Floor-Type face(s) in a Honeybee Room and gets Params Resets self.floor_area and self.floor_U_value based on the values found in the Honeybee Zone. If more than one Floor face is found, creates a weighted U-Value average of all the faces. Args: self: _hb_room: A Single Honeybee Room object Returns: None """ def is_floor(_face): if str(face.type) != 'Floor': return False if str(face.boundary_condition) != 'Ground' and str( face.boundary_condition) != 'Outdoors': return False return True #----------------------------------------------------------------------- # Get all the data from the HB-Room Floor surfaces floor_areas = [] area_weighted_u_values = [] perim_curve_lengths = [] for face in _hb_room: if not is_floor(face): continue u_floor = face.properties.energy.construction.u_factor floor_areas.append(face.area) area_weighted_u_values.append(u_floor * face.area) face_surface = from_face3d(face.geometry) perim_curve = ghc.JoinCurves( list(face_surface.DuplicateEdgeCurves()), False) perim_curve_lengths.append(ghc.Length(perim_curve)) #----------------------------------------------------------------------- # Set the Floor Element params if floor_areas and area_weighted_u_values: self.floor_area = sum(floor_areas) self.floor_U_value = sum(area_weighted_u_values) / sum(floor_areas) self.perim_len = sum(perim_curve_lengths)
def inset_rhino_surface(_srfc, _inset_dist=0.001, _srfc_name=""): """ Insets/shrinks a Rhino Brep some dimension Arg: _srfc: A Rhino Brep _inset_dist: float: Default=0.001m _srfc_name: str: The name of the surface, used for error messages Returns: new_srfc: A new Rhino surface, shrunk/inset by the specified amount """ #----------------------------------------------------------------------- # Get all the surface params needed srfc_Center = ghc.Area(_srfc).centroid srfc_normal_vector = brep_avg_surface_normal(_srfc) srfc_edges = ghc.DeconstructBrep(_srfc).edges srfc_perimeter = ghc.JoinCurves(srfc_edges, False) #----------------------------------------------------------------------- # Try to inset the perimeter Curve inset_curve = rs.OffsetCurve(srfc_perimeter, srfc_Center, _inset_dist, srfc_normal_vector, 0) #----------------------------------------------------------------------- # In case the new curve goes 'out' and the offset fails # Or is too small and results in multiple offset Curves if len(inset_curve)>1: warning = 'Error. The surface: "{}" is too small. The offset of {} m"\ "can not be done. Check the offset size?'.format(_srfc_name, _inset_dist) print(warning) inset_curve = rs.OffsetCurve(srfc_perimeter, srfc_Center, 0.001, srfc_normal_vector, 0) inset_curve = rs.coercecurve( inset_curve[0] ) else: inset_curve = rs.coercecurve( inset_curve[0] ) new_srfc = ghc.BoundarySurfaces(inset_curve) return new_srfc
def joinTouchingTFAsurfaces(_tfaSrfcObjs, _HBzoneObjs): # Takes in a set of TFA Surface Objects that are touching # Returns a new single TFA Surface Obj with averaged / joined values srfcExtPerims = [] AreaGross = [] TFAs = [] # Figure out the new joined room's Ventilation Flow Rates ventFlowRates_Sup = [] ventFlowRates_Eta = [] ventFlowRates_Tran = [] # Get all the already input flow rates for the TFA Surfaces (if any) for srfcObj in _tfaSrfcObjs: ventFlowRates_Sup.append(srfcObj.V_sup) ventFlowRates_Eta.append(srfcObj.V_eta) ventFlowRates_Tran.append(srfcObj.V_trans) # Use the max values from the input set as the new Unioned objs' vent flow rates unionedSrfcVentRates = [ max(ventFlowRates_Sup), max(ventFlowRates_Eta), max(ventFlowRates_Tran) ] for srfcObj in _tfaSrfcObjs: TFAs.append(srfcObj.getArea_TFA()) AreaGross.append(srfcObj.Area_Gross) srfcExtEdges = ghc.BrepEdges(rs.coercebrep(srfcObj.Surface))[0] srfcExtPerims.append(ghc.JoinCurves(srfcExtEdges, preserve=False)) unionedSrfc = ghc.RegionUnion(srfcExtPerims) unionedTFAObj = PHPP_TFA_Surface(unionedSrfc, _HBzoneObjs, unionedSrfcVentRates, _inset=0, _offsetZ=0) # Set the TFA Surface Attributes unionedTFAObj.Area_Gross = sum(AreaGross) unionedTFAObj.TFAfactor = sum(TFAs) / sum(AreaGross) unionedTFAObj.RoomNumber = _tfaSrfcObjs[0].RoomNumber unionedTFAObj.RoomName = _tfaSrfcObjs[0].RoomName return unionedTFAObj
points.append(curve_point) return points else: segment.Domain = reparam normal = ghc.CrossProduct(tangents, global_Z, True) curve_point = ghc.EvaluateCurve(segment, 0.5)[0] curve_point, _ = ghc.Move(curve_point, normal[0][0] * distance) return [curve_point] # Standardize surfaces rooms = [standardize_surfaces(room) for room in rooms] # Convert brep to polylines room_segments = [ghc.DeconstructBrep(room)[1] for room in rooms] room_polylines = [ghc.JoinCurves(segments, True) for segments in room_segments] # Main script for i, room_polyline in enumerate(room_polylines): connect = set() for segment in room_segments[i]: points = create_outside_points(segment) P.append(points) if type(points) in [list, tuple]: for p in points: for j, pl in enumerate(room_polylines): if j not in connect: relation, _ = ghc.PointInCurve(p, pl) if relation > 0: connect.add(j) connectivity.append(list(connect))
# AR3B011 EARTHY (2019/20 Q1) # Zaatari refugee camp Hammam project: "Janat Al-Tohr #Group Members: Nikoleta Sidiropoulou, Hans Gamerschlag, Noah van den Berg, Rick van Dijk, Maximilian Mandat, Hamidreza Shahriari import rhinoscriptsyntax as rs import ghpythonlib.components as ghc lst = [] edges = [] Mess = [] bollen = [] face = [] Inv = [] #Finding the naked edges of the Mesh meshEdg = ghc.MeshEdges(mesh)[0] Edg = ghc.JoinCurves(meshEdg, True) #Finding the boundary lines of the mesh faceBound = ghc.FaceBoundaries(mesh) #colliding the naked edges with boundary face of the mesh to find the faces touching the naked edges coll = ghc.CollisionOneXMany(faceBound, Edg)[0] meshCull = ghc.CullFaces(mesh, coll) # Sepprating the faces touching the naked edges meshCullInv = ghc.CullFaces(mesh, [not i for i in coll]) Inv.append(meshCullInv) lst.append(meshCull) bollen.append(coll) face.append(faceBound) i = 0
def set_perim_edge_values(self, _crv_guids, _ud_psi): """Pulls Rhino Scene parameters for a list of Curve Objects Takes in a list of curve GUIDs and goes to Rhino. Looks in their UserText to get any user applied parameter data. Calculates the sum of all curve lengths (m) in the list, as well as the total Psi-Value * Length (W/m) of all curves in the list. Will return tuple(0, 0) on any trouble getting parameter values or any fails Args: self: _perimCrvs (list): A list of Curve GUIDs to look at in the Rhino Scene Returns: totalLen, psiXlen (tuple): The total length of all curves in the list (m) and the total Psi*Len value (W/m) """ def _getLengthIfNumber(_in, _psi): try: length = float(_in) except: length = None try: psi = float(_psi) except: psi = self.default_perim_psi return length, psi if _crv_guids == None: return None if len(_crv_guids) == 0: return None psiXlen = 0 totalLen = 0 for crvGUID in _crv_guids: # See if its just Numbers passed in. If so, use them and break out length, crvPsiValue = _getLengthIfNumber(crvGUID, _ud_psi) if length and crvPsiValue: totalLen += length psiXlen += (length * crvPsiValue) continue isCrvGeom = rs.coercecurve(crvGUID) isBrepGeom = rs.coercebrep(crvGUID) if isCrvGeom: crvLen = ghc.Length(isCrvGeom) try: crvPsiValue = float(_ud_psi) except: crvPsiValue, warning = self._get_curve_psi_value(crvGUID) totalLen += crvLen psiXlen += (crvLen * crvPsiValue) elif isBrepGeom: srfcEdges = ghc.DeconstructBrep(isBrepGeom).edges srfcPerim = ghc.JoinCurves(srfcEdges, False) crvLen = ghc.Length(srfcPerim) try: crvPsiValue = float(_ud_psi) except: crvPsiValue = self.default_perim_psi # Default 0.05 W/mk warning = 'Note: You passed in a surface without any Psi-Values applied.\n'\ 'I will apply a default {} W/mk Psi-Value to ALL the edges of the\n'\ 'surface passed in.'.format( self.default_perim_psi ) self.ghenv.Component.AddRuntimeMessage( ghK.GH_RuntimeMessageLevel.Warning, warning) totalLen += crvLen psiXlen += (crvLen * crvPsiValue) else: warning = 'Error in GROUND: Input into _exposedPerimCrvs is not a Curve or Surface?\n'\ 'Please ensure inputs are Curve / Polyline or Surface only.' self.ghenv.Component.AddRuntimeMessage( ghK.GH_RuntimeMessageLevel.Warning, warning) self.perim_len = totalLen self.perim_psi_X_len = psiXlen