コード例 #1
0
def innerPanel():
    objs = rs.GetObjects("Select objects to add frame to", filter = 24, group = True,preselect = True)
    if objs is None:
        return
    dist = rs.GetReal("Offset Distance")
    if dist is None:
        return
    rs.EnableRedraw(False)
    
    srfs = []
    
    for obj in objs:
        if rs.IsPolysurface(obj):
            srfs = srfs + rs.ExplodePolysurfaces(obj)
        else:
            srfs.append(rs.CopyObject(obj))
    
    for srf in srfs:
        if rs.IsSurfacePlanar(srf):
            edgeCrvs = rs.DuplicateEdgeCurves(srf)
            border = rs.JoinCurves(edgeCrvs, True)
            innerEdge = rs.OffsetCurveOnSurface(border, srf, dist)
            #rs.SplitBrep(srf, innerEdge)
            rs.AddPlanarSrf(innerEdge)
            rs.DeleteObject(innerEdge)
            rs.DeleteObject(border)
        else:
            print "A surface was not planar"
    rs.DeleteObjects(srfs)
    rs.EnableRedraw(True)
コード例 #2
0
def squareSect(crv,width,height):
    sections=[]
    divPts=rs.DivideCurve(crv,10)
    keep=True
    for i in range(len(divPts)):
        param=rs.CurveClosestPoint(crv,divPts[i])
        tan=rs.CurveTangent(crv,param)
        plane=rs.PlaneFromNormal(divPts[i],tan)
        sect=rs.AddRectangle(plane,width,height)
        cpt=rs.CurveAreaCentroid(sect)[0]
        vec=rs.VectorCreate(divPts[i],cpt)
        sect=rs.MoveObject(sect,vec)
        if i>0:
            if testAlign(sect,oldSect)==False:
                sect=align(sect,oldSect,divPts[i],tan)
        oldSect=sect
        sections.append(sect)
    branch=rs.AddLoftSrf(sections,None,None,2,0,0,False)
    edges=rs.DuplicateEdgeCurves(branch)
    if width>height:
        testVal=height
    else:
        testVal=width
    for i in range(len(edges)):
        testPt=rs.CurveMidPoint(edges[i])
        for j in range(len(edges)):
            param=rs.CurveClosestPoint(edges[j],testPt)
            pt=rs.EvaluateCurve(edges[j],param)
            if rs.Distance(pt,testPt)<testVal/6:
                keep=False
    rs.DeleteObjects(sections)
    rs.DeleteObjects(edges)
    return branch
コード例 #3
0
def getSurfaces(HBZones):
    hb_hive = sc.sticky["honeybee_Hive"]()
    geometry = []
    HBO = hb_hive.callFromHoneybeeHive(HBZones)
    for b in HBO:
        crvs = []
        HBSurfaces = hb_hive.addToHoneybeeHive(
            b.surfaces, ghenv.Component.InstanceGuid.ToString())
        for s in HBSurfaces:
            edges = rs.DuplicateEdgeCurves(s)
            crvs.append(rs.JoinCurves(edges))
        geometry.append(crvs)
    return geometry
コード例 #4
0
def EdgeVectors(srf, pts):
    crvs = rs.DuplicateEdgeCurves(srf)
    edgeVectors = []
    for pt in pts:
        closestIndex = 0
        closestDist = 99999
        for i, crv in enumerate(crvs):
            tempPt = rs.EvaluateCurve(crv, rs.CurveClosestPoint(crv, pt))
            dist = rs.Distance(pt, tempPt)
            if dist < closestDist:
                closestDist = dist
                closestIndex = i
        
        tempPt = rs.EvaluateCurve(crvs[closestIndex], rs.CurveClosestPoint(crvs[closestIndex], pt))
        rs.AddLine(tempPt, pt)
        edgeVectors.append(rs.VectorCreate(tempPt, pt))
    return edgeVectors
コード例 #5
0
    def detectParalellSurface(self):
        #fix layer height

        #self.paralellIntersectedCurve
        #self.indexParalellSurfaces

        explodedSurfaces = rs.ExplodePolysurfaces(self.addtiveObj)

        for surface in explodedSurfaces:
            #normals.append(rs.SurfaceNormal(surface))
            tmpNormal = rs.SurfaceNormal(surface, [0, 0])

            gotAngle = rs.VectorAngle(tmpNormal, self.normalVec)
            if gotAngle == 0 or gotAngle == 180:

                tmpPoints = rs.SurfaceEditPoints(surface)
                tmpPlane = rs.PlaneFromNormal(tmpPoints[0], self.normalVec)

                distance = rs.DistanceToPlane(tmpPlane, self.basePointForPlane)

                distance *= (1.0 / math.cos(math.radians(self.angleOfSurface)))
                print("distance")
                print(distance)

                paralellLayer = int(distance / self.fixedLayerHeight)
                if paralellLayer < 0:
                    paralellLayer *= -1

                if paralellLayer == int(
                        self.distancePrinting /
                        self.fixedLayerHeight) or int(distance) == 0:
                    continue

                self.indexParalellSurfaces.append(int(paralellLayer))
                print("paralellLayer")
                print(paralellLayer)
                print("layer num")
                print(self.distancePrinting / self.fixedLayerHeight)
                #there is object to delete
                self.paralellIntersectedCurves.append(
                    rs.JoinCurves(rs.DuplicateEdgeCurves(surface)))

        rs.DeleteObjects(explodedSurfaces)
        """
コード例 #6
0
ファイル: shlCutTerrain.py プロジェクト: SHLFab/shl-toolbox
def get_frame_brep(outline_srf, border_thickness, thickness):
    """get the frame brep. This is a solid that is booleaned with the slices of
	terrain to make a border when border mode is on."""
    edge_crvs = rs.DuplicateEdgeCurves(outline_srf)
    outline_crv = rs.JoinCurves(edge_crvs)
    pt, _ = rs.CurveAreaCentroid(outline_crv)
    inner_crv = rs.OffsetCurve(outline_crv, pt, border_thickness, [0, 0, 1])
    rs.MoveObjects([outline_crv, inner_crv], [0, 0, thickness * 2])

    path_line = rs.AddLine([0, 0, 0], [0, 0, -thickness * 4])
    inner_brep = rs.ExtrudeCurve(inner_crv, path_line)
    outer_brep = rs.ExtrudeCurve(outline_crv, path_line)
    rs.CapPlanarHoles(inner_brep)
    rs.CapPlanarHoles(outer_brep)

    frame_brep = rs.BooleanDifference([outer_brep], [inner_brep])
    rs.DeleteObjects([outline_crv, inner_crv])
    rs.DeleteObjects(edge_crvs)
    rs.DeleteObject(path_line)
    return frame_brep
コード例 #7
0
def nurbs_to_mesh(srf,trg_len,vis):
    
    crvs = rs.DuplicateEdgeCurves(srf) 
    
    if len(crvs)>1:
        joint = rs.JoinCurves(crvs,True)
        if joint:
            if len(joint) > 2:
                print "hole" 
    else:
        if rs.IsCurveClosed(crvs[0]):
            joint = [crvs[0]]
            print "closed"#e.g. if it is a disk
        else:
            print "Surface need to be split"#e.g. if it is a sphere
            return None
         

    
    #sort curves (this is cheating: the longer curve is not necessarily the outer boundary!) 
    #todo: an inside outside comparison in uv space
    crvs_len = [rs.CurveLength(crv) for crv in joint] 
    crvs  = [x for (_,x) in sorted(zip(crvs_len,joint))]
    
    outer_crv =  crvs[-1]
    inner_crvs = crvs[:-1]
    
    outer_bound_pts = get_boundary_points(outer_crv,trg_len)
    if inner_crvs: inner_bounds_pts = [get_boundary_points(crvs,trg_len) for crvs in inner_crvs]
    
    all_pts = copy.copy(outer_bound_pts)
    if inner_crvs: 
        for pts in inner_bounds_pts:
            all_pts += pts
    
    outbound_keys = get_boundary_indecies(outer_bound_pts,all_pts)

    inbounds_keys = []
    if inner_crvs:
        for inner_bound_pts in inner_bounds_pts:
            inbounds_keys.append(get_boundary_indecies(inner_bound_pts,all_pts))   
     

    rs.DeleteObjects(crvs)        

    all_pts_uv = convert_to_uv_space(srf,all_pts) 
    tris = delaunay(all_pts_uv,outbound_keys,inbounds_keys)
    
    mesh = Mesh()
    
    for i,pt in enumerate(all_pts):
        mesh.add_vertex(str(i),{'x' : pt[0], 'y' : pt[1], 'z' : pt[2]})
    for tri in tris:
        mesh.add_face(tri)  
    
    edge_lengths = []
    for u, v in mesh.edges():
        edge_lengths.append(mesh.edge_length(u, v))
    
    target_start = max(edge_lengths)/2

    rs.EnableRedraw(False)
    
    srf_id = rs.coerceguid(srf, True)
    brep = rs.coercebrep(srf_id, False)   
    tolerance = rs.UnitAbsoluteTolerance()
    
    fixed = outbound_keys+[item for sublist in inbounds_keys for item in sublist]
    user_func = wrapper(brep,tolerance,fixed,vis)
    

    remesh(mesh,trg_len,
       tol=0.1, divergence=0.01, kmax=300,
       target_start=target_start, kmax_approach=150,
       verbose=False, allow_boundary=False,
       ufunc=user_func)
 
    for k in xrange(10):
        mesh_smooth_centroid(mesh,fixed=fixed,kmax=1) 
        user_func(mesh,k)
    
    return draw_light(mesh,temp = False) 
    

    
    
    


    
コード例 #8
0
Dimensions = [[[-1 for col in range(3)] for col in range(Nfaces)]
              for row in range(N_blocks)
              ]  # face size in x-, y- and z-direction
Block_center = [0 for row in range(N_blocks)
                ]  # x-, y-, z-coordinates of block center
Volume = [-1 for row in range(N_blocks)]  # block volume
maxLength = 0  # max block length (used for defining tolerance)

# Extract block face dimensions, block face center, max block length
for ii in range(N_blocks):
    faces[ii] = rs.ExplodePolysurfaces(
        ALL_BLOCKS[ii]
    )  # explode blocks into surfaces represeting the block faces
    for jj in range(Nfaces):
        lines[ii][jj] = rs.DuplicateEdgeCurves(
            faces[ii][jj]
        )  # sketch lines along face edges (!) dev. hint: this is time consuming and can be improved
        curves[ii][jj] = rs.JoinCurves(
            lines[ii]
            [jj])  # join the lines to create polyline along face adges
        for kk in range(3):
            face_center[ii][jj][kk] = round(
                rs.CurveAreaCentroid(curves[ii][jj])[0][kk],
                RoundUnit)  # read coordinates of face center
        if jj == 1 or jj == 3:  # faces belonging to yz-plane
            Dimensions[ii][jj][0] = face_center[ii][jj][
                0]  # x-coordinate of face center
            Dimensions[ii][jj][1] = round(rs.CurveLength(
                lines[ii][jj][1]), RoundUnit)  # face size in y-direction
            Dimensions[ii][jj][2] = round(rs.CurveLength(
                lines[ii][jj][0]), RoundUnit)  # face size in z-direction
コード例 #9
0
def alingBlock(block_a, block_b, model_inside):
    """
    Scale box to the correct dimentions
    Align box a and what is inside to box b
    The dimention of the box is expected to be equal lenght
    :param block_a:
    :param block_b: block to align block_a to
    :param model_inside: models inside block_a
    """

    # Find center of box_a
    exp_a = rs.ExplodePolysurfaces(block_a)
    cen_a = Vector3d(0, 0, 0)
    for exp in exp_a:
        cen_a += rs.SurfaceAreaCentroid(exp)[0]
    cen_a /= 6.0

    # Find center of box_b
    exp_b = rs.ExplodePolysurfaces(block_b)
    cen_b = Vector3d(0, 0, 0)
    for exp in exp_b:
        cen_b += rs.SurfaceAreaCentroid(exp)[0]
    cen_b /= 6.0

    # Find side Lenght
    c = rs.DuplicateEdgeCurves(exp_a[0])
    L = float(rs.CurveLength(c[0]))

    def sqrt_length(a, b, c):
        return math.sqrt(a * a + b * b + c * c)

    def create_matrix(a, b, c, d):
        M = [[a[0], a[1], a[2], d[0]], [b[0], b[1], b[2], d[1]],
             [c[0], c[1], c[2], d[2]], [0, 0, 0, 1]]
        return M

    # find basic function of box_a
    basic_0 = cen_a - rs.SurfaceAreaCentroid(exp_a[0])[0]
    basic_0 /= sqrt_length(basic_0[0], basic_0[1], basic_0[2])

    basic_1 = rs.SurfaceAreaCentroid(exp_a[1])[0] - cen_a
    basic_1 /= sqrt_length(basic_1[0], basic_1[1], basic_1[2])

    basic_2 = cen_a - rs.SurfaceAreaCentroid(exp_a[4])[0]
    basic_2 /= sqrt_length(basic_2[0], basic_2[1], basic_2[2])

    # create tranformation matrix
    M = create_matrix(basic_0, basic_1, basic_2, [0, 0, 0])

    # scale
    rs.ScaleObjects([block_a] + model_inside, cen_a,
                    [200 / L, 200 / L, 200 / L])

    # move to [0,0,0]
    rs.MoveObjects([block_a] + model_inside, -cen_a)

    # rotate
    rs.TransformObjects([block_a] + model_inside, M)

    # move to object
    rs.MoveObjects([block_a] + model_inside, cen_b)

    rs.DeleteObjects(exp_a)
    rs.DeleteObjects(exp_b)

    rs.DeleteObjects(c)
コード例 #10
0
def nurbs_to_mesh_ani(srf,trg_len_min,trg_len_max,vis):
    trg_len = trg_len_max
    
    
    u_div = 30
    v_div = 30
    u_domain = rs.SurfaceDomain(srf, 0)
    v_domain = rs.SurfaceDomain(srf, 1)
    u = (u_domain[1] - u_domain[0]) / (u_div - 1)
    v = (v_domain[1] - v_domain[0]) / (v_div - 1)
    

    gauss = []
    for i in xrange(u_div):
        for j in xrange(v_div):
            data = rs.SurfaceCurvature (srf, (u_domain[0] + u * i, v_domain[0] + v * j))
            gauss.append(abs(data[7]))
            pt = rs.EvaluateSurface(srf,u_domain[0] + u * i, v_domain[0] + v * j)
            #rs.AddTextDot(round(abs(data[7]),3),pt)
    gauss_max = max(gauss)
    gauss_min = min(gauss)
    
    print gauss_max
    print gauss_min
    

            
    crvs = rs.DuplicateEdgeCurves(srf) 
    
    if len(crvs)>1:
        joint = rs.JoinCurves(crvs,True)
        if joint:
            if len(joint) > 2:
                print "hole" 
    else:
        if rs.IsCurveClosed(crvs[0]):
            joint = [crvs[0]]
            print "closed"#e.g. if it is a disk
        else:
            print "Surface need to be split"#e.g. if it is a sphere
            return None
         

    
    #sort curves (this is cheating: the longer curve is not necessarily the outer boundary!) 
    #todo: an inside outside comparison in uv space
    crvs_len = [rs.CurveLength(crv) for crv in joint] 
    crvs  = [x for (_,x) in sorted(zip(crvs_len,joint))]
    
    outer_crv =  crvs[-1]
    inner_crvs = crvs[:-1]
    
    outer_bound_pts = get_boundary_points(outer_crv,trg_len)
    if inner_crvs: inner_bounds_pts = [get_boundary_points(crvs,trg_len) for crvs in inner_crvs]
    
    all_pts = copy.copy(outer_bound_pts)
    if inner_crvs: 
        for pts in inner_bounds_pts:
            all_pts += pts
    
    outbound_keys = get_boundary_indecies(outer_bound_pts,all_pts)

    inbounds_keys = []
    if inner_crvs:
        for inner_bound_pts in inner_bounds_pts:
            inbounds_keys.append(get_boundary_indecies(inner_bound_pts,all_pts))   
     

    rs.DeleteObjects(crvs)        

    all_pts_uv = convert_to_uv_space(srf,all_pts) 
    tris = delaunay(all_pts_uv,outbound_keys,inbounds_keys)
    
    mesh = Mesh()
    
    for i,pt in enumerate(all_pts):
        mesh.add_vertex(str(i),{'x' : pt[0], 'y' : pt[1], 'z' : pt[2]})
    for tri in tris:
        mesh.add_face(tri)  
    
    edge_lengths = []
    for u, v in mesh.edges():
        edge_lengths.append(mesh.edge_length(u, v))
    
    target_start = max(edge_lengths)/22

    rs.EnableRedraw(False)
    
    srf_id = rs.coerceguid(srf, True)
    brep = rs.coercebrep(srf_id, False)   
    tolerance = rs.UnitAbsoluteTolerance()
    
    fixed = outbound_keys+[item for sublist in inbounds_keys for item in sublist]
    user_func = wrapper(brep,tolerance,fixed,vis)
    

    remesh_ani(srf,mesh,trg_len_min,trg_len_max,gauss_min,gauss_max,
       tol=0.1, divergence=0.008, kmax=400,
       target_start=target_start, kmax_approach=200,
       verbose=False, allow_boundary=False,
       ufunc=user_func)
 
    for k in xrange(1):
        mesh_smooth_on_local_plane(mesh,k=1,d=0.2,fixed=fixed)  
        user_func(mesh,k)
    
    return draw_light(mesh,temp = False)    
    
    


    
コード例 #11
0
import uuid

hb_hive = sc.sticky["honeybee_Hive"]()

geometry = []
if dir != None:
    dir += "\\"  #Add \ in case is missing

HBO = hb_hive.callFromHoneybeeHive(_HBZones)
for b in HBO:
    crvs = []
    HBSurfaces = hb_hive.addToHoneybeeHive(
        b.surfaces,
        ghenv.Component.InstanceGuid.ToString() + str(uuid.uuid4()))
    for s in HBSurfaces:
        edges = rs.DuplicateEdgeCurves(s)
        crvs.append(rs.JoinCurves(edges))
    geometry.append(crvs)


def list_to_tree(input, none_and_holes=True, source=[0]):
    """Transforms nestings of lists or tuples to a Grasshopper DataTree"""
    # written by Giulio Piacentino, [email protected]
    from Grasshopper import DataTree as Tree
    from Grasshopper.Kernel.Data import GH_Path as Path
    from System import Array

    def proc(input, tree, track):
        path = Path(Array[int](track))
        if len(input) == 0 and none_and_holes:
            tree.EnsurePath(path)
コード例 #12
0
ファイル: ramp.py プロジェクト: tmwarchitecture/PCPA_TOOLS
def Ramp_HeightSlope(path, width, slope):
    #Variables
    rampThickness = 6
    handrailOffset = 3
    handrailRadius = 1.5
    handrailHeight = 34
    if width < 36:
        width = 36
    width = width + (handrailOffset * 2)
    comments = ''

    handrailCenterlineOffset = (handrailOffset - handrailRadius / 2)

    rs.SimplifyCurve(path)

    runs = MakeRampRuns(path, width)

    if slope > .05:
        runData = CheckRunLengths(runs)
        runs = runData[0]
        comments += runData[1]

    runGeo = []
    hdrls = []
    finalHandrails = []
    vertMove = (0, 0, 0)

    for run in runs:
        length = rs.Distance(rs.CurveStartPoint(run[0]),
                             rs.CurveStartPoint(run[1]))

        stHeight = vertMove
        vertMove = (0, 0, length * slope)

        rs.MoveObject(run[-1], vertMove)
        rs.MoveObjects(run, stHeight)

        vertMove = rs.VectorAdd(stHeight, vertMove)

        srf = rs.AddLoftSrf(run)

        norm = rs.SurfaceNormal(srf[0], [.5, .5])
        if norm.Z < 0:
            rs.FlipSurface(srf[0], True)
            runGeo.append(srf[0])
        else:
            runGeo.append(srf[0])

        hdrls.append(MakeHandrailFromRuns(run, handrailCenterlineOffset))

        rs.DeleteObjects(run)

    #Get highest and lowest lines
    landingEdges = []
    for run in runGeo:
        curves = rs.DuplicateEdgeCurves(run)
        highestIndex = None
        highestValue = -999999
        lowestIndex = None
        lowestValue = 999999
        for i, curve in enumerate(curves):
            crvZ = rs.CurveMidPoint(curve)[2]
            if crvZ < lowestValue:
                lowestIndex = i
                lowestValue = crvZ
            if crvZ > highestValue:
                highestIndex = i
                highestValue = crvZ
        lowestEdge = rs.CopyObject(curves[lowestIndex])
        highestEdge = rs.CopyObject(curves[highestIndex])
        landingEdges.append(lowestEdge)
        rs.ReverseCurve(highestEdge)
        landingEdges.append(highestEdge)
        rs.DeleteObjects(curves)
    comments += 'Total ramp height {}"\n'.format(str(highestValue))

    #Make Landings
    landingGeos = MakeRampLandings(landingEdges, handrailCenterlineOffset)
    landings = landingGeos[0]
    hdrls += landingGeos[1]
    allHandrails = []
    for hdrl in hdrls:
        for each in hdrl:
            allHandrails.append(each)
    longRails = rs.JoinCurves(allHandrails, True)

    #Handrail Extension
    for rail in longRails:
        stPt = rs.CurveStartPoint(rail)
        stVec = rs.CurveTangent(rail, 0)
        stVecProj = rs.VectorScale(
            rs.VectorReverse(rs.VectorUnitize((stVec[0], stVec[1], 0))), 12)
        endPt = rs.CurveEndPoint(rail)
        endParam = rs.CurveClosestPoint(rail, endPt)
        endVec = rs.CurveTangent(rail, endParam)
        endVecProj = rs.VectorScale(
            rs.VectorUnitize((endVec[0], endVec[1], 0)), 12)
        stPtTemp = rs.CurveStartPoint(rail)
        endPtTemp = rs.CurveEndPoint(rail)
        stPtOffset = rs.MoveObject(stPtTemp, stVecProj)
        endPtOffset = rs.MoveObject(endPtTemp, endVecProj)
        stProj = rs.AddLine(stPt, stPtOffset)
        endProj = rs.AddLine(endPt, endPtOffset)
        finalHandrails.append(rs.JoinCurves([stProj, rail, endProj], True)[0])

        rs.DeleteObject(stPtOffset)
        rs.DeleteObject(endPtOffset)

    #Move handrails up
    for rail in finalHandrails:
        rs.MoveObject(rail, (0, 0, handrailHeight))

    #Make solid geometry
    topSurface = rs.JoinSurfaces(runGeo + landings, True)
    if topSurface is None: topSurface = runGeo

    btmSurface = rs.CopyObject(topSurface, (0, 0, -rampThickness))

    edgeCurves = rs.DuplicateSurfaceBorder(topSurface)

    extrusionLine = rs.AddLine((0, 0, 0), (0, 0, -rampThickness))
    extrusionGeo = rs.ExtrudeCurve(edgeCurves, extrusionLine)
    rs.DeleteObject(extrusionLine)
    rs.DeleteObject(edgeCurves)

    finalGeo = rs.JoinSurfaces([topSurface, btmSurface, extrusionGeo], True)

    #rs.EnableRedraw(True)
    #print "A"
    if slope <= .05:
        rs.DeleteObjects(finalHandrails)
        return [finalGeo, comments]
    else:
        return [finalGeo, comments, finalHandrails]
コード例 #13
0
def shape_edges(shape):
    ref = shape.realize()
    return ref.map(lambda r: map(shape_from_ref, rh.DuplicateEdgeCurves(r)))