Exemplo n.º 1
0
def isShareEdge(srf1, srf2):
    border1 = rs.DuplicateSurfaceBorder(srf1)
    border2 = rs.DuplicateSurfaceBorder(srf2)
    edges1 = rs.ExplodeCurves(border1, True)
    edges2 = rs.ExplodeCurves(border2, True)

    shareMid = []
    threshold = 0.001
    flag = False
    for e1 in edges1:
        for e2 in edges2:
            mid1 = rs.CurveMidPoint(e1)
            mid2 = rs.CurveMidPoint(e2)
            if rs.Distance(mid1, mid2) < threshold:
                s1 = rs.CurveStartPoint(e1)
                s2 = rs.CurveStartPoint(e2)
                e1 = rs.CurveEndPoint(e1)
                e2 = rs.CurveEndPoint(e2)
                if rs.Distance(s1, s1) < threshold:
                    flag = True
                    break
                if rs.Distance(s1, e1) < threshold:
                    flag = True
                    break

    rs.DeleteObjects(edges1)
    rs.DeleteObjects(edges2)
    return flag
Exemplo n.º 2
0
def getTotalRun(landingEdges):
    run = 0.0
    for i in range(0, len(landingEdges), 2):
        a = rs.CurveMidPoint(landingEdges[i])
        b = rs.CurveMidPoint(landingEdges[i + 1])
        run = run + rs.Distance(a, b)
    return run
Exemplo n.º 3
0
def visualize_rays(room, keys=None, ref_order=None, layer='Default', dot=None):

    rs.CurrentLayer(layer)
    if not keys:
        keys = room.ray_lines.keys()
    for rk in keys:
        if ref_order:
            ref_k = ref_order
            if ref_k in room.ray_lines[rk]:
                u, v = room.ray_lines[rk][ref_k]
                line = rs.AddLine(u, v)
        else:
            lkeys = room.ray_lines[rk]
            for lk in lkeys:
                u, v = room.ray_lines[rk][lk]
                line = rs.AddLine(u, v)
                if dot == 'w':
                    w = room.ray_powers[rk][lk][
                        100]  # this needs to be better, user given
                    rs.AddTextDot(str(w), rs.CurveMidPoint(line))
                if dot == 't':
                    t = room.ray_times[rk][lk]
                    rs.AddTextDot(str(t), rs.CurveMidPoint(line))
                if dot == 'key':
                    rs.AddTextDot(str(lk), rs.CurveMidPoint(line))
Exemplo n.º 4
0
def write_strip_data(layer, point_ind):
    # get all surfaces on layer
    strips = rs.ObjectsByLayer(layer)
    strip_ind = 1
    strip_dict = {}
    for strip in strips:
        # get only surfaces
        if rs.IsSurface(strip):
            if rs.IsSurfacePlanar(strip):
                strip_dict['Strip=' + layer + str(strip_ind)] = []
                strip_brep = rs.coercebrep(strip)
                edges = Rhino.Geometry.Brep.DuplicateEdgeCurves(strip_brep)
                edge_ids = []
                ind = 0
                for edge in edges:
                    edge_id = sc.doc.Objects.AddCurve(edge)
                    if edge_id:
                        rs.ObjectName(edge_id, 'active' + str(ind))
                        edge_ids.append(edge_id)
                        ind += 1
                # Get strip geometry
                # change color to help find strip
                rs.ObjectColor(strip, color=(255, 0, 255))
                start_edge = rs.GetObject('Select start edge.', 4, False,
                                          False, active_strip_filter)
                start_length = rs.CurveLength(start_edge)
                sp = rs.CurveMidPoint(start_edge)
                rs.ObjectName(rs.AddPoint(sp), name='SP_' + str(point_ind))
                end_edge = rs.GetObject('Select end edge.', 4, False, False,
                                        active_strip_filter)
                end_length = rs.CurveLength(end_edge)
                ep = rs.CurveMidPoint(end_edge)
                rs.ObjectName(rs.AddPoint(ep), name='SP_' + str(point_ind))
                # Clean up
                rs.DeleteObjects(edge_ids)
                rs.ObjectColor(strip, color=(128, 0, 128))
                # write to json
                start = {
                    'Point': point_ind,
                    'GlobalX': round(sp.X, 4),
                    'GlobalY': round(sp.Y, 4),
                    'WALeft': round(start_length * 0.5, 4),
                    'WARight': round(start_length * 0.5, 4),
                    'Autowiden': 'No'
                }
                point_ind += 1
                end = {
                    'Point': point_ind,
                    'GlobalX': round(ep.X, 4),
                    'GlobalY': round(ep.Y, 4),
                    'WBLeft': round(end_length * 0.5, 4),
                    'WBRight': round(end_length * 0.5, 4),
                }
                strip_dict['Strip=' + layer + str(strip_ind)].append(start)
                strip_dict['Strip=' + layer + str(strip_ind)].append(end)
                point_ind += 1
                strip_ind += 1
    return strip_dict
def CrvSegmentMidPt(crv, n):
    if rs.IsPolyline(crv):
        verts = rs.PolylineVertices(crv)
        midPt = (verts[n] + verts[n + 1]) / 2
    elif rs.IsPolyCurve(crv):
        midPt = rs.CurveMidPoint(crv, n)
    else:
        midPt = rs.CurveMidPoint(crv)
    return midPt
def Extend_trim_crv(A, B, thickness):
    if mode == "extend":
        if rs.CurveLength(A) > rs.CurveLength(B):
            B = rs.OffsetCurve(A, rs.CurveMidPoint(B), thickness)
        else:
            A = rs.OffsetCurve(B, rs.CurveMidPoint(A), thickness)
    elif mode == "trim":
        if rs.CurveLength(A) > rs.CurveLength(B):
            A = rs.OffsetCurve(B, rs.CurveMidPoint(A), thickness)
        else:
            B = rs.OffsetCurve(A, rs.CurveMidPoint(B), thickness)
    return (A, B)
Exemplo n.º 7
0
def CheckRunLengths(runs):
    lengthComment = ''
    for i, run in enumerate(runs):
        dist = rs.Distance(rs.CurveStartPoint(run[0]),
                           rs.CurveStartPoint(run[1]))
        if dist > 360:
            lengthComment += 'Run {} requires a landing\n'.format(i + 1)
            templine = rs.AddLine(rs.CurveStartPoint(run[0]),
                                  rs.CurveStartPoint(run[1]))
            mdPt = rs.CurveMidPoint(templine)
            vec = rs.VectorCreate(mdPt, rs.CurveStartPoint(run[0]))
            landingCenter = rs.CopyObject(run[0], vec)
            vec = rs.VectorScale(rs.VectorUnitize(vec), 30)
            upperLine = rs.CopyObject(landingCenter, vec)
            vec = rs.VectorReverse(vec)
            lowerLine = rs.MoveObject(landingCenter, vec)
            rs.DeleteObject(templine)
            run.insert(1, lowerLine)
            run.insert(2, upperLine)

    flatList = []
    for item in runs:
        for each in item:
            flatList.append(each)

    pairs = []
    for i in range(0, len(flatList), 2):
        pairs.append([flatList[i], flatList[i + 1]])
    return pairs, lengthComment
def WindowLeftDistance():
    # Find midpoint of window left line
    midpoint_windowLeft = rs.CurveMidPoint(window_leftLine[1])

    # Find closest point in curve window left
    parameterLeftLine = rs.CurveClosestPoint(window_leftLine[1],
                                             midpoint_windowLeft)

    # Find curve window left Tangent
    windowLeft_Tangent = rs.CurveTangent(window_leftLine[1], parameterLeftLine)

    # find window left normal plane
    windowLeft_plane = rs.PlaneFromNormal(midpoint_windowLeft,
                                          windowLeft_Tangent)

    # find start and end points of ground line
    points_ll = []
    start_ll = bbox[0]
    end_ll = bbox[3]
    points_ll.append(start_ll)
    points_ll.append(end_ll)

    #find point on Surface Left line
    point_SurfLeftLine = rs.LinePlaneIntersection(points_ll, windowLeft_plane)
    #point_SurfLeftLine = rs.AddPoint(point_SurfLeftLine)

    Window_leftDistance = rs.Distance(midpoint_windowLeft, point_SurfLeftLine)

    return Window_leftDistance
def SillHeight():
    # Find mid point of sill line
    midpointSill = rs.CurveMidPoint(window_sillLine[1])
    #midpointSill = rs.AddPoint(midpointSill)

    # Find closest point in curve
    parameterSill = rs.CurveClosestPoint(window_sillLine[1], midpointSill)

    # Find curve Tangent
    sill_Tangent = rs.CurveTangent(window_sillLine[1], parameterSill)

    # find normal plane
    sill_plane = rs.PlaneFromNormal(midpointSill, sill_Tangent)

    # find start and end points of ground line
    points_gl = []
    start_gl = rs.CurveStartPoint(groundLine[1])
    end_gl = rs.CurveEndPoint(groundLine[1])
    points_gl.append(start_gl)
    points_gl.append(end_gl)

    #find point on ground line
    pointGroundLine = rs.LinePlaneIntersection(points_gl, sill_plane)
    #pointGroundLine = rs.AddPoint(pointGroundLine)

    sill_Height = rs.Distance(midpointSill, pointGroundLine)

    return sill_Height
Exemplo n.º 10
0
def offsetext():
    def RepresentsInt(s):
        try: 
            int(s)
            return True
        except ValueError:
            return False
    
    
    viste = rs.ViewNames()
    for viewport in viste:
        rs.ViewDisplayMode(viewport,"Shaded")
    diametro = rs.StringBox("dimensione della punta","10","scontornatura")
    if RepresentsInt(diametro):
        diametro = int(diametro)
    else:
        diametro = 10
    brep =  rs.GetObjects("dammi un solido",16)
    brepexp = rs.ExplodePolysurfaces(brep)
    get_val = rs.GetEdgeCurves("dammi le curve")
    surf_edge = []
    
    for i in get_val:
        surf_edge.append(i[0])
    surf_edge = rs.coerceguidlist(surf_edge)
    if len(surf_edge)>1:
        surf_edge = rs.JoinCurves(surf_edge,True)
    surface = rs.GetObjects("conferma la selezione",8,False,True,1,1)

    print surf_edge
    uv= []
    temp_edge = rs.ExplodeCurves(surf_edge,False)
    new_surface = rs.CopyObject(surface,(0,0,0))
    list_evpt =[]
    for i in temp_edge:
        evpt =rs.CurveMidPoint(i)
        print evpt
        list_evpt.append(evpt)
    for i in list_evpt:
        bord= rs.SurfaceClosestPoint(new_surface,i)
        uv.append(bord)
    for i in uv:
        rs.ExtendSurface(new_surface,i,diametro*10)
    edge = rs.OffsetCurveOnSurface(surf_edge,new_surface,-diametro)
    print edge
    if rs.CurveLength(edge)<rs.CurveLength(surf_edge):
        rs.DeleteObject(edge)
        edge =  rs.OffsetCurveOnSurface(surf_edge,new_surface,diametro)
    surf_edge = rs.ExplodeCurves(surf_edge,True)
    print edge
    
    rs.ObjectColor(edge,(0,0,255))
    for i in brepexp:
        rs.DeleteObject(i)
    for i in temp_edge:
        rs.DeleteObject(i)
    for i in surf_edge:
        rs.DeleteObject(i)
    
    rs.DeleteObjects([new_surface,surface])
Exemplo n.º 11
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
def construct_mesh_center(points):

    meshes = []

    ### calc center point
    bbox = rs.BoundingBox(points)
    line = rs.AddLine(bbox[0], bbox[6])
    c = rs.CurveMidPoint(line)

    ### set new point list
    points.append(c)

    ###
    c_index = len(points) - 1
    # print(c_index)

    for j in xrange(len(points) - 1):
        if j < (len(points) - 2):
            vertex_ = [(c_index, int(j), int(j) + 1, int(j) + 1)]
            # print(vertex_)
            m = rs.AddMesh(points, vertex_)
            meshes.append(m)
        else:
            vertex_ = [(c_index, int(j), 0, 0)]
            # print(vertex_)
            m = rs.AddMesh(points, vertex_)
            meshes.append(m)

    mesh_joined = rs.JoinMeshes(meshes)

    return mesh_joined
Exemplo n.º 13
0
def main():
    crv = rs.GetObject("Select Curve to offset repeatedly:", 4)
    ptCrvMid = rs.CurveMidPoint(crv)
    #### Use the following lines to offset by count
    #dir = rs.GetPoint("Direction of Offset:");
    #count = rs.GetInteger("Number of Offsets:");
    tupCount = getCount(ptCrvMid)
    recursiveOffset(crv, tupCount[1], tupCount[2], tupCount[0], 0)
 def Keep(self, curves, index, axis=1):
     meta = [(i, rs.CurveMidPoint(curves[i])[axis])
             for i in range(len(curves))]
     meta.sort(key=lambda iy: iy[1])
     for i in range(len(meta)):
         if i != index:
             rs.DeleteObject(curves[meta[i][0]])
     return curves[meta[index][0]]
Exemplo n.º 15
0
def DropBlockToSurface():
    try:

        obj = rs.GetObjects('Select Objects',
                            rs.filter.curve | rs.filter.instance
                            | rs.filter.mesh | rs.filter.surface
                            | rs.filter.subd | rs.filter.light
                            | rs.filter.polysurface,
                            preselect=True)
        srf = rs.GetObject('Select Surface')

        if obj:
            if srf:

                rs.EnableRedraw(False)

                # Check if srf is a mesh, if so convert to Nurb
                isMesh = rs.IsMesh(srf)
                if isMesh == True:
                    srf = rs.MeshToNurb(srf)

                # For each object send test rays up and down in Z coord
                # Move each object to the ray test that hits a srf
                for i in obj:
                    bndBox = rs.BoundingBox(i)
                    pt1 = bndBox[0]
                    pt2 = bndBox[2]
                    crv = rs.AddLine(pt1, pt2)

                    if crv:
                        midcrv = rs.CurveMidPoint(crv)
                        rs.DeleteObject(crv)

                    ray_pt_up = rs.ShootRay(srf,
                                            midcrv, (0, 0, 1),
                                            reflections=1)
                    ray_pt_down = rs.ShootRay(srf,
                                              midcrv, (0, 0, -1),
                                              reflections=1)

                    if ray_pt_up:
                        vector = rs.VectorCreate(ray_pt_up[1], midcrv)
                        rs.MoveObject(i, vector)

                    if ray_pt_down:
                        vector = rs.VectorCreate(ray_pt_down[1], midcrv)
                        rs.MoveObject(i, vector)

                # deleate any created srf
                if isMesh == True:
                    rs.DeleteObject(srf)
                rs.EnableRedraw(True)

    except:
        print("Failed to execute")
        rs.EnableRedraw(True)
        return
Exemplo n.º 16
0
def Findclosestpt(crvs):
	dict_dist = {}
	list_midpt = [rs.CurveMidPoint(crv) for crv in crvs]
	count = 0
	while count != len(crvs):
		list_distance = [int(rs.Distance(list_midpt[count], i)) for i in list_midpt]
		dict_dist[count] = sorted(range(len(list_distance)), key=lambda k: list_distance[k])
		count += 1
	return dict_dist
Exemplo n.º 17
0
def RunCommand(is_interactive):
    global params

    pitch_line = rs.GetObject(message="Select pitch line",
                              filter=rs.filter.curve,
                              preselect=True)
    if pitch_line is None:
        return 1  # Cancel

    if not rs.IsLine(pitch_line):
        print "Selected curve is not a line!"
        return 1  # Cancel

    rs.SelectObjects(pitch_line)

    m = rs.GetReal(message="Rack module", number=params["m"])
    pa = rs.GetReal(message="Pressure angle",
                    number=params["pa"],
                    minimum=0,
                    maximum=45)

    if m is None or pa is None:
        return 1  # Cancel

    params["m"] = m
    params["pa"] = pa

    pitch_line_center = rs.CurveMidPoint(pitch_line)
    pitch_line_start = rs.CurveStartPoint(pitch_line)
    pitch_line_end = rs.CurveEndPoint(pitch_line)
    angle, reflex_angle = rs.Angle2(line1=((0, 0, 0), (1, 0, 0)),
                                    line2=(pitch_line_start, pitch_line_end))

    x_vector = rs.VectorCreate(pitch_line_end, pitch_line_start)
    y_vector = rs.VectorRotate(x_vector, 90.0, [0, 0, 1])
    cplane = rs.PlaneFromFrame(origin=pitch_line_center,
                               x_axis=x_vector,
                               y_axis=y_vector)

    xform = rs.XformChangeBasis(cplane, rs.WorldXYPlane())

    rs.EnableRedraw(False)
    old_plane = rs.ViewCPlane(plane=rs.WorldXYPlane())

    rack = draw_rack(length=rs.CurveLength(pitch_line),
                     module=params["m"],
                     pressure_angle=params["pa"])

    rs.ViewCPlane(plane=old_plane)
    rs.TransformObjects(rack, xform)

    rs.EnableRedraw(True)
    rs.UnselectAllObjects()
    rs.SelectObjects(rack)

    return 0  # Success
Exemplo n.º 18
0
def plotPoint(pOne, pTwo):
    line = rs.AddLine(pOne, pTwo)
    coordinates = rs.CurveMidPoint(line)
    point = rs.AddPoint(coordinates)
    rs.DeleteObject(line)
    translation = rs.Distance(pOne, pTwo)
    rs.MoveObject(point, (0, 0, translation))
    result = rs.PointCoordinates(point)
    rs.DeleteObject(point)
    return result
def addVertLineAtMid():
    objs = rs.GetObjects("select lines you want to add a vertical line at mid",
                         rs.filter.curve)
    vector1 = rs.VectorCreate((0, 0, 0), (0, 0, 200))

    if objs:
        for obj in objs:
            midPoint = rs.CurveMidPoint(obj)
            midPointMoved = midPoint
            rs.MoveObject(midPointMoved, vector1)
            rs.AddLine(midPoint, midPointMoved)
Exemplo n.º 20
0
def Getendpoints(Curve):
    x = rs.CurveStartPoint(Curve)
    y = rs.CurveEndPoint(Curve)
    z = rs.CurveMidPoint(Curve)
    startP = x.X, x.Y, x.Z
    MidP = z.X, z.Y, z.Z
    EndP = y.X, y.Y, y.Z
    if rs.CurveDegree(Curve) == 2:
        return str(startP) + "," + str(MidP) + "," + str(EndP)
    elif rs.CurveDegree(Curve) == 1:
        return str(startP) + "," + str(EndP)
    else:
        return "Invalid Curve"
Exemplo n.º 21
0
def Findclosestpt(crvs):
    dict_dist = {}
    list_midpt = [rs.CurveMidPoint(crv) for crv in crvs]
    count = 0
    while count != len(crvs):
        list_distance = [
            int(rs.Distance(list_midpt[count], i)) for i in list_midpt
        ]
        list_sorted = zip(list_distance, range(len(crvs)))
        list_sorted.sort()
        list_distance, list_sortindex = zip(*list_sorted)
        dict_dist[count] = list_sortindex
        count += 1
    return dict_dist
Exemplo n.º 22
0
def Previewwall(dict, index, crvs, zoommode):# 壁を作る
	# get_adjustの中身で処理を決める
	if dict[index][2] == 1:
		A = crvs[dict[index][0]]
		B = rs.OffsetCurve(crvs[dict[index][0]], rs.CurveMidPoint(crvs[dict[index][1]]), dict[index][3])
	elif dict[index][2] == 2:
		A = rs.OffsetCurve(crvs[dict[index][1]], rs.CurveMidPoint(crvs[dict[index][0]]), dict[index][3])
		B = crvs[dict[index][1]]
	elif dict[index][2] == 3:
		A = rs.OffsetCurve(crvs[dict[index][1]], rs.CurveMidPoint(crvs[dict[index][0]]), dict[index][3])
		B = crvs[dict[index][1]]
	elif dict[index][2] == 4:
		A = crvs[dict[index][0]]
		B = rs.OffsetCurve(crvs[dict[index][0]], rs.CurveMidPoint(crvs[dict[index][1]]), dict[index][3])

	obj_srf = rs.AddLoftSrf([A, B])
	obj_height = rs.AddLine((0,0,0), (0,0,dict[index][4]))
	obj_wall = rs.ExtrudeSurface(obj_srf, obj_height)

	if zoommode:# 壁と曲線で箱を作り、箱をズーム
		obj_zoom = rs.BoundingBox([obj_wall, crvs[dict[index][0]], crvs[dict[index][1]]])
		rs.ZoomBoundingBox(obj_zoom)

	return obj_wall
Exemplo n.º 23
0
def createMidPointFromCurve(curve):
    split_num = 2
    point_list = []
    domain = rs.CurveDomain(curve)
    t = (domain[1] - domain[0]) / split_num

    for int in range(split_num):
        dt = t * int
        point = rs.EvaluateCurve(curve, dt)
        point_list.append(point)

    # 直線の中心点を求める
    line = rs.AddLine(point_list[0], point_list[1])
    mid_point = rs.CurveMidPoint(line)

    return mid_point
Exemplo n.º 24
0
 def label_and_len_lines(self):
     # f = open('{0}/{1}.txt'.format(dir_path, self.outFile), 'w')
     # dists = []
     for i in range(0, len(self.all_lines)):
         curr_len = rs.CurveLength(self.all_lines[i])
         # rs.AddPipe(self.all_lines[i], 0, 0.09375, 0, 1)
         if math.fabs(curr_len - self.FLAT_LENGTH) > 0.000001:
             # dists.append('%.3f' % curr_len)
             mp = rs.CurveMidPoint(self.all_lines[i])
             text = 'line{0}'.format(i)
             rs.AddText(text, mp, 0.3)
             start = rs.AddLine(rs.CurveStartPoint(self.all_lines[i - 1]),
                                rs.CurveEndPoint(self.all_lines[i - 1]))
             mid = rs.AddLine(rs.CurveStartPoint(self.all_lines[i]),
                              rs.CurveEndPoint(self.all_lines[i]))
             end = rs.AddLine(rs.CurveStartPoint(self.all_lines[i + 1]),
                              rs.CurveEndPoint(self.all_lines[i + 1]))
             self.createPipe(start, mid, end, text)
Exemplo n.º 25
0
 def appendEdgeDirection(self):
     """
     Calculate the unit vector of offset directions for self.edges and append in list: self.offsetDirection.
     :rtype: None (result in self.offsetDirection)
     """
     for edge in self.edges:
         # make vertical vector
         curveVector = rs.VectorCreate(rs.CurveStartPoint(edge), rs.CurveEndPoint(edge))
         midPoint = rs.CurveMidPoint(edge)
         vec1 = rs.VectorRotate(curveVector, 90.0, [0, 0, 1])
         vec2 = rs.VectorRotate(curveVector, -90.0, [0, 0, 1])
         midToCenterVec = rs.VectorCreate(midPoint, self.center)
         offsetVec = ""
         if rs.VectorDotProduct(vec1, midToCenterVec) > 0:
             offsetVec = vec1
         else:
             offsetVec = vec2
         offsetVec = rs.VectorUnitize(offsetVec)
         # result
         self.offsetDirection.append(offsetVec)
def CreatingNodeFun(Pt, Lines, BeamRad, BeamLength):
    Beams = []
    for i in Lines:
        MidPt = rs.CurveMidPoint(i)
        DirVe = MidPt - Pt
        DirVecUni = rs.VectorUnitize(DirVe)
        TrVec = rs.VectorScale(DirVecUni, BeamLength)
        PtToMove = rs.AddPoint(pt)
        EndPt = rs.MoveObject(PtToMove, TrVec)
        Plane01 = rs.PlaneFromNormal(pt, DirVe)
        Plane02 = rs.PlaneFromNormal(PtToMove, DirVe)

        Ids = []
        Cir01 = rs.AddCircle(Plane01, BeamRad)
        Cir02 = rs.AddCircle(Plane02, BeamRad)
        Ids.append(Cir01)
        Ids.append(Cir02)

        Beam = rs.AddLoftSrf(Ids)
        Beams.append(Beam)
    return Beams
Exemplo n.º 27
0
def dogbone(curves, diam, diam_barrenos, tol):
    for curve in curves:
        if rs.CloseCurve(curve):
            centroid = rs.CurveAreaCentroid(curve)[0]
        else:
            centroid = rs.CurveMidPoint(curve)
        if diam_barrenos == -1:
            rs.AddPoint(centroid)
        elif diam_barrenos == 0:
            pass
        else:
            rs.AddCircle(centroid, diam_barrenos * .5)

        curve = rs.ConvertCurveToPolyline(curve, delete_input=True)
        tol_curve = rs.OffsetCurve(curve, centroid, -tol) if tol else curve
        ocurve = rs.OffsetCurve(tol_curve,
                                rs.CurveAreaCentroid(curve)[0], diam * .3)
        circles = [rs.AddCircle(i, diam / 2) for i in rs.CurvePoints(ocurve)]
        rs.CurveBooleanUnion(circles + [tol_curve])
        rs.DeleteObjects([ocurve, tol_curve] + circles)
        if curve: rs.DeleteObject(curve)
Exemplo n.º 28
0
def Section2D():
    #"Create cross-section and rotate to 2D plane"

    # Select objects to draw section from
    objects = rs.GetObjects("Select objects to rotate", rs.filter.curve)
    # Select cross section plane
    sectionplane = rs.GetObject("Select cross-section line", rs.filter.curve)

    # Calculate orientation of cross-section plane
    startpt = rs.CurveStartPoint(sectionplane)
    midpt = rs.CurveMidPoint(sectionplane)
    endpt = rs.CurveEndPoint(sectionplane)

    x1, y1 = startpt[0], startpt[1]
    x2, y2 = endpt[0], endpt[1]

    rad2deg = 180 / math.pi
    angle = math.atan((y2 - y1) / (x2 - x1)) * rad2deg

    # rotate cross-section objects to 2D plane
    rs.RotateObjects(objects, midpt, -angle)
    rs.RotateObjects(objects, midpt, -90, [1, 0, 0])
Exemplo n.º 29
0
def addConstructionLine(point_a):
    # Color to use when drawing dynamic lines
    line_color_1 = System.Drawing.Color.FromArgb(200, 200, 200)
    line_color_2 = System.Drawing.Color.FromArgb(255, 0, 0)

    # This is a function that is called whenever the GetPoint's
    # DynamicDraw event occurs
    def GetPointDynamicDrawFunc(sender, args):
        point_b = args.CurrentPoint
        point_C = Rhino.Geometry.Point3d((point_a.X + point_b.X) / 2,
                                         (point_a.Y + point_b.Y) / 2,
                                         (point_a.Z + point_b.Z) / 2)
        #Rhino.Geometry.Transform.Translation(
        vec = rs.VectorCreate(point_b, point_a)
        rs.VectorUnitize(vec)
        vec2 = rs.VectorScale(vec, 500)
        vec3 = rs.coerce3dpoint(rs.VectorAdd(point_b, vec2))
        rs.VectorReverse(vec2)
        vec4 = rs.coerce3dpoint(rs.VectorSubtract(point_b, vec2))

        args.Display.DrawLine(point_a, vec3, line_color_1, 1)
        args.Display.DrawLine(point_a, vec4, line_color_1, 1)
        args.Display.DrawPoint(point_a, Rhino.Display.PointStyle.ControlPoint,
                               3, line_color_1)
        args.Display.DrawPoint(point_b, Rhino.Display.PointStyle.ControlPoint,
                               3, line_color_2)

    # Create an instance of a GetPoint class and add a delegate
    # for the DynamicDraw event
    gp = Rhino.Input.Custom.GetPoint()
    gp.DynamicDraw += GetPointDynamicDrawFunc
    gp.Get()
    if (gp.CommandResult() == Rhino.Commands.Result.Success):
        pt = gp.Point()
        line = rs.AddLine(point_a, pt)
        c = rs.CurveMidPoint(line)
        scaled = rs.ScaleObject(line, c, [500, 500, 500])
        rs.ObjectColor(scaled, [199, 199, 199])
Exemplo n.º 30
0
    def resample_polyline(self, length):
        try:
            rs_poly = rs.AddPolyline(self.polyline.points)
            if length <= self.polyline.length:
                a = rs.DivideCurveLength(rs_poly, length, False)
                num_div = len(
                    rs.DivideCurveLength(rs_poly, length, False, False))
                new_pts = rs.DivideCurve(rs_poly, num_div, False, True)

                new_rs_poly = rs.AddPolyline(new_pts)
                segs = rs.ExplodeCurves(new_rs_poly)

            else:
                print('it is a line!')
                segs = [
                    rs.AddLine(rs.CurveStartPoint(rs_poly),
                               rs.CurveEndPoint(rs_poly))
                ]
                print(segs)

            out_pts = []
            out_vec = []

            for seg in segs:
                new_pt = rs.CurveMidPoint(seg)
                v = rs.VectorCreate(rs.CurveEndPoint(seg),
                                    rs.CurveStartPoint(seg))
                new_pt = [new_pt.X, new_pt.Y, new_pt.Z]
                new_vec = [v.X, v.Y, v.Z]
                new_vec = compas.geometry.normalize_vector(new_vec)
                out_pts.append(new_pt)
                out_vec.append(new_vec)
            # print('succesfully resampled')
            return out_pts, out_vec

        except Exception:
            print('Polyline could not be resampled.')
            return None, None