コード例 #1
0
ファイル: rh_trial.py プロジェクト: tanyaroi/PyGH
def pre_process():
    # delete all previous user text
    all_objs = rs.AllObjects()
    for obj in all_objs:
        rh_obj = rs.coercerhinoobject(obj)
        rh_obj.Attributes.DeleteAllUserStrings()

    # remove all blocks
    for block in rs.BlockNames():
        rs.DeleteBlock(block)

    # set current layer
    rs.CurrentLayer(relevant_layers_dict["buildings"])

    # remove redundant layers
    for layer_name in rs.LayerNames():
        if layer_name not in relevant_layers_dict.values():
            rs.PurgeLayer(layer_name)

    # get all objects in building layer
    building_objs = rs.ObjectsByLayer(relevant_layers_dict["buildings"])

    for building_obj in building_objs:
        if rs.IsCurve(building_obj) and rs.IsCurveClosed(building_obj):

            # flatten curve to XY plane
            matrix = rs.XformPlanarProjection(rg.Plane.WorldXY)
            rs.TransformObject(building_obj, matrix, copy=False)

            # delete all object with a surface grater or smaller from MIN_BUILDING_AREA_SQ by TOLERANCE or just smaller than MIN_BUILDING_AREA_SQ
            TOLERANCE = 2
            if rs.CurveArea(building_obj)[0] < MIN_BUILDING_AREA_SQM or abs(
                    rs.CurveArea(building_obj)[0] -
                    MIN_BUILDING_AREA_SQM) < TOLERANCE:
                rs.DeleteObject(building_obj)
コード例 #2
0
ファイル: lbt_to_phpp.py プロジェクト: tejaskumar555/LBT-2-PH
def get_footprint(_surfaces):
    # Finds the 'footprint' of the building for 'Primary Energy Renewable' reference
    # 1) Re-build the Opaque Surfaces
    # 2) Join all the surface Breps into a single brep
    # 3) Find the 'box' for the single joined brep
    # 4) Find the lowest Z points on the box, offset another 10 units 'down'
    # 5) Make a new Plane at this new location
    # 6) Projects the brep edges onto the new Plane
    # 7) Split a surface using the edges, combine back into a single surface

    Footprint = namedtuple('Footprint',
                           ['Footprint_surface', 'Footprint_area'])

    #----- Build brep
    surfaces = (from_face3d(surface.Srfc) for surface in _surfaces)
    bldg_mass = ghc.BrepJoin(surfaces).breps
    bldg_mass = ghc.BoundaryVolume(bldg_mass)
    if not bldg_mass:
        return Footprint(None, None)

    #------- Find Corners, Find 'bottom' (lowest Z)
    bldg_mass_corners = [v for v in ghc.BoxCorners(bldg_mass)]
    bldg_mass_corners.sort(reverse=False, key=lambda point3D: point3D.Z)
    rect_pts = bldg_mass_corners[0:3]

    #------- Projection Plane
    projection_plane1 = ghc.Plane3Pt(rect_pts[0], rect_pts[1], rect_pts[2])
    projection_plane2 = ghc.Move(projection_plane1, ghc.UnitZ(-10)).geometry
    matrix = rs.XformPlanarProjection(projection_plane2)

    #------- Project Edges onto Projection Plane
    projected_edges = []
    for edge in ghc.DeconstructBrep(bldg_mass).edges:
        projected_edges.append(ghc.Transform(edge, matrix))

    #------- Split the projection surface using the curves
    l1 = ghc.Line(rect_pts[0], rect_pts[1])
    l2 = ghc.Line(rect_pts[0], rect_pts[2])
    max_length = max(ghc.Length(l1), ghc.Length(l2))

    projection_surface = ghc.Polygon(projection_plane2, max_length * 100, 4,
                                     0).polygon
    projected_surfaces = ghc.SurfaceSplit(projection_surface, projected_edges)

    #------- Remove the biggest surface from the set(the background srfc)
    projected_surfaces.sort(key=lambda x: x.GetArea())
    projected_surfaces.pop(-1)

    #------- Join the new srfcs back together into a single one
    unioned_NURB = ghc.RegionUnion(projected_surfaces)
    unioned_surface = ghc.BoundarySurfaces(unioned_NURB)

    return Footprint(unioned_surface, unioned_surface.GetArea())
コード例 #3
0
def calcFootprint(_zoneObjs, _opaqueSurfaces):
    # Finds the 'footprint' of the building for 'Primary Energy Renewable' reference
    # 1) Re-build the zone Breps
    # 2) Join all the zone Breps into a single brep
    # 3) Find the 'box' for the single joined brep
    # 4) Find the lowest Z points on the box, offset another 10 units 'down'
    # 5) Make a new Plane at this new location
    # 6) Projects the brep onto the new Plane

    #-----
    zoneBreps = []
    for zone in _zoneObjs:
        zoneSurfaces = []
        for srfc in _opaqueSurfaces:
            if srfc.HostZoneName == zone.ZoneName:
                zoneSurfaces.append(ghc.BoundarySurfaces(srfc.Boundary))
        zoneBrep = ghc.BrepJoin(zoneSurfaces).breps
        zoneBreps.append(zoneBrep)

    bldg_mass = ghc.SolidUnion(zoneBreps)

    if bldg_mass == None:
        return None

    #------- Find Corners, Find 'bottom' (lowest Z)
    bldg_mass_corners = [v for v in ghc.BoxCorners(bldg_mass)]
    bldg_mass_corners.sort(reverse=False, key=lambda point3D: point3D.Z)
    rect_pts = bldg_mass_corners[0:3]

    #------- Project Brep to Footprint
    projection_plane1 = ghc.Plane3Pt(rect_pts[0], rect_pts[1], rect_pts[2])
    projection_plane2 = ghc.Move(projection_plane1, ghc.UnitZ(-10)).geometry
    matrix = rs.XformPlanarProjection(projection_plane2)
    footprint_srfc = rs.TransformObjects(bldg_mass, matrix, copy=True)
    footprint_area = rs.Area(footprint_srfc)

    #------- Output
    Footprint = namedtuple('Footprint',
                           ['Footprint_surface', 'Footprint_area'])
    fp = Footprint(footprint_srfc, footprint_area)

    return fp
コード例 #4
0
ファイル: rh_trial.bak.py プロジェクト: tanyaroi/PyGH
# set current layer
rs.CurrentLayer(relevant_layers_dict["buildings"])

# remove redundant layers
for layer_name in rs.LayerNames():
    if layer_name not in relevant_layers_dict.values():
        rs.PurgeLayer(layer_name)

# get all objects in building layer
building_objs = rs.ObjectsByLayer(relevant_layers_dict["buildings"])

for building_obj in building_objs:
    if rs.IsCurve(building_obj) and rs.IsCurveClosed(building_obj):
        # flatten curve to XY plane
        matrix = rs.XformPlanarProjection(rg.Plane.WorldXY)
        rs.TransformObject(building_obj, matrix, copy=False)

##########################################################################################################################################

# set current working dir
os.chdir(working_dir_path)

# Add attributes to buildings
with open(proc_attributes_path, "r") as input_handle:
    rdr = csv.reader(input_handle)

    # read attribure labels (first row)
    attribute_labels_list = next(rdr)

    # get x, y, z attributes indices
コード例 #5
0
def MultiNestedBoundaryTrimCurves():
    msg="Select closed boundary curves for trimming"
    TCrvs = rs.GetObjects(msg, 4, preselect=False)
    if not TCrvs: return
    
    cCrvs=[crv for crv in TCrvs if rs.IsCurveClosed(crv)]
    if len(cCrvs)==0:
        print "No closed trim curves found"
        return
    rs.LockObjects(cCrvs)
    
    origCrvs = rs.GetObjects("Select curves to trim", 4)
    rs.UnlockObjects(cCrvs)
    if not origCrvs : return
    
    #plane which is active when trim curve is chosen
    refPlane = rs.ViewCPlane()
    
    if sc.sticky.has_key("TrimSideChoice"):
        oldTSChoice = sc.sticky["TrimSideChoice"]
    else:
        oldTSChoice=True
    
    choice = [["Trim", "Outside", "Inside"]]
    res = rs.GetBoolean("Side to trim away?", choice, [oldTSChoice])
    if not res: return
    trimIns = res[0] #False=Outside
    
    tol=sc.doc.ModelAbsoluteTolerance
    bb=rs.BoundingBox(origCrvs,refPlane) #CPlane box, world coords
    if not bb: return
    zVec=refPlane.ZAxis
    
    rs.EnableRedraw(False)
    botPlane=Rhino.Geometry.Plane(bb[0]-zVec,zVec) #check
    xform=rs.XformPlanarProjection(botPlane)
    cutCrvs=rs.TransformObjects(cCrvs,xform,True)
    ccc=CheckPlanarCurvesForCollision(cutCrvs)
    if ccc:
        msg="Boundary curves overlap, results may be unpredictable, continue?"
        res=rs.MessageBox(msg,1+32)
        if res!= 1: return
    bSrfs=rs.AddPlanarSrf(cutCrvs)
    rs.DeleteObjects(cutCrvs)
    if bSrfs == None: return
    
    line=rs.AddLine(bb[0]-zVec,bb[4]+zVec)
    vols=[]
    for srf in bSrfs:
        ext=rs.ExtrudeSurface(srf,line,True)
        if ext != None: vols.append(ext)
    rs.DeleteObjects(bSrfs)
    rs.DeleteObject(line)
    if len(vols)==0: return
    exGroup=rs.AddGroup()
    rs.AddObjectsToGroup(vols,exGroup)
    
    rs.Prompt("Splitting curves...")
    rs.SelectObjects(origCrvs)
    rs.Command("_Split _-SelGroup " + exGroup + " _Enter", False)
    splitRes=rs.LastCreatedObjects()
    rs.DeleteGroup(exGroup)
    
    rs.Prompt("Classifying trims...")
    noSplit=[]
    for crv in origCrvs:
        #add curve to list if it has not been split (still exists in doc)
        id=sc.doc.Objects.Find(crv)        
        if id != None: noSplit.append(crv)
        
    errors=0
    if splitRes:
        if len(noSplit)>0: splitRes.extend(noSplit)
        for crv in splitRes:
            inside=MultiTestInOrOut(crv,vols)
            if inside != None:
                if (inside and trimIns) or (not inside and not trimIns):
                    rs.DeleteObject(crv)
            else:
                errors+=1
    rs.DeleteObjects(vols)
    if errors>0: print "Problems with {} curves".format(errors)
    sc.sticky["TrimSideChoice"] = trimIns
コード例 #6
0
import rhinoscriptsyntax as rs
import operator

hatch = rs.GetObject(message="Pick any hatch", filter=rs.filter.hatch)
trim_lines = rs.GetObjects(message="Select cutting lines", filter=rs.filter.curve)

# Project trim_lines to cplane
plane = rs.ViewCPlane()
matrix = rs.XformPlanarProjection(plane)
rs.TransformObjects(trim_lines, matrix, copy=False)

selected_objects = []
selected_objects.append(trim_lines)

if hatch:
    # Store original hatch settings
    hatch_pattern = rs.HatchPattern(hatch)
    hatch_rotation = rs.HatchRotation(hatch)
    hatch_scale = rs.HatchScale(hatch)
    
    # Make hatch solid so we able to explode it and get surface instead
    if hatch_pattern != "Solid":
        rs.HatchPattern(hatch, "Solid")
    dup_border_surface = []
    dup_border_surface.append(rs.ExplodeHatch(hatch)[0])
    rs.SurfaceIsocurveDensity(dup_border_surface, 100)
    selected_objects.append(dup_border_surface)
    reduced_selected_objects = reduce(operator.add, selected_objects)
    rs.SelectObjects(reduced_selected_objects)
    rs.HideObject(hatch)
    rs.Command("_Trim")
コード例 #7
0
def projectLayersToClpane(layers):
    for layer in layers:
        curves = rs.ObjectsByLayer(layer)

        xform = rs.XformPlanarProjection(rs.WorldXYPlane())
        rs.TransformObjects(curves, xform, False)