Example #1
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])
 def CreateRadial(self, x0, x1, d, z):
     return rs.JoinCurves([
         rs.AddLine((x0, -d, z), (x1, -d, z)),
         rs.AddArc3Pt((x1, -d, z), (x1, d, z), (x1 + d, 0, z)),
         rs.AddLine((x1, d, z), (x0, d, z)),
         rs.AddArc3Pt((x0, d, z), (x0, -d, z), (x0 - d, 0, z))
     ], True)
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)
Example #4
0
 def fillet_lines(self):
     self.lines = []
     for i in range(0, len(self.line_lists)):
         fillets = []
         new_line = []
         for j in range(0, len(self.line_lists[i]) - 1):
             fillets.append(
                 rs.AddFilletCurve(self.line_lists[i][j],
                                   self.line_lists[i][j + 1], 1))
         for k in range(0, len(self.line_lists[i])):
             line = self.line_lists[i][k]
             if (k < len(self.line_lists[i]) - 1):
                 line_domain = rs.CurveDomain(line)
                 line_intersect = rs.CurveCurveIntersection(
                     line, fillets[k])[0][5]
                 line = rs.TrimCurve(self.line_lists[i][k],
                                     (line_domain[0], line_intersect), True)
             if (k > 0):
                 line_domain = rs.CurveDomain(line)
                 line_intersect = rs.CurveCurveIntersection(
                     line, fillets[k - 1])
                 line = rs.TrimCurve(line,
                                     (line_intersect[0][5], line_domain[1]),
                                     True)
             new_line.append(line)
             if (k < len(self.line_lists[i]) - 1):
                 new_line.append(fillets[k])
         self.lines.append(rs.JoinCurves(new_line))
Example #5
0
    def hatchthis(s):

        #offset all segments
        s = rs.coercecurve(s)
        offsets = s.Offset(plane, scale / 2, tol, style)
        if offsets:
            p1, p2, curve1 = getPointsAndLines(offsets)
        offsets = s.Offset(plane, -scale / 2, tol, style)
        if offsets:
            p3, p4, curve2 = getPointsAndLines(offsets)
        if not (p1 and p2 and p3 and p4):
            return

        #create end lines between the two offset curves
        line1 = rs.AddLine(p1, p3)
        line2 = rs.AddLine(p2, p4)
        polyline = rs.JoinCurves([line1, line2, curve1, curve2], True, tol)

        # FINALLY: hatch the bloody thing
        hatch = rs.AddHatch(polyline, 'Solid')

        #clean up
        rs.DeleteObject(polyline)

        return hatch
Example #6
0
def joinCurves(copies):

    # sortobjects per layer
    sorted_objects = {}
    for obj in copies:
        layer_name = rs.ObjectLayer(obj)

        if not (layer_name in sorted_objects):
            # add new list
            sorted_objects[layer_name] = []

        sorted_objects[layer_name].append(obj)

    # join curves per layer
    new_list = []
    for layer_name in sorted_objects:
        if len(sorted_objects[layer_name]) > 1:
            # list is at least 2 items
            list_result = rs.JoinCurves(sorted_objects[layer_name], True)
        else:
            list_result = sorted_objects[layer_name]

        for obj in list_result:
            rs.ObjectLayer(obj, layer_name)
            new_list.append(obj)

    return new_list
Example #7
0
    def createPipe(self, first, mid, last, text):
        first_fillet = rs.AddFilletCurve(first, mid, 0.25)
        fillet_points = rs.CurveFilletPoints(first, mid, 0.25)
        first_circle = rs.AddCircle(fillet_points[2], 0.125)
        first_cp = rs.CurveClosestPoint(first, fillet_points[0])
        first_domain = rs.CurveDomain(first)
        nfirst = rs.TrimCurve(first, (first_domain[0], first_cp), False)
        second_cp = rs.CurveClosestPoint(mid, fillet_points[1])
        second_domain = rs.CurveDomain(mid)
        nmid = rs.TrimCurve(mid, (second_cp, second_domain[1]), False)

        second_fillet = rs.AddFilletCurve(mid, last, 0.25)
        fillet_points = rs.CurveFilletPoints(mid, last, 0.25)
        second_circle = rs.AddCircle(fillet_points[2], 0.125)
        first_cp = rs.CurveClosestPoint(mid, fillet_points[0])
        first_domain = rs.CurveDomain(mid)
        nmid = rs.TrimCurve(nmid, (first_domain[0], first_cp), False)
        second_cp = rs.CurveClosestPoint(last, fillet_points[1])
        second_domain = rs.CurveDomain(last)
        nlast = rs.TrimCurve(last, (second_cp, second_domain[1]), False)

        curve = rs.JoinCurves(
            [nfirst, first_fillet, nmid, second_fillet, nlast])
        print curve
        pipe = rs.AddPipe(curve, 0, 0.09375, 0, 1)
        points = [
            rs.CurveStartPoint(first),
            rs.CurveEndPoint(first),
            rs.CurveStartPoint(last),
            rs.CurveEndPoint(last)
        ]
        self.copyAndMover(first, mid, last, points, text)
Example #8
0
 def get_curve_from_segments(self, lines):
     curves = rs.JoinCurves(lines)
     index = 0
     length = 0
     for i in range(0, len(curves)):
         new_length = rs.CurveLength(curves[i])
         if (new_length > length):
             index = i
             length = new_length
     return curves[index]
Example #9
0
def mapping(discretization_spacing, surface_guid, curve_features_guids = [], point_features_guids = []):
    """Creates planar polylines from the boundaries of a NURBS surface, NURBS curves and point on the NURBS surface
    by using the UV parameterisation with a user-input discretisation spacing.

    Parameters
    ----------
    discretization_spacing: real
        Spacing value for discretisation of NURBS surface borders and curves into polylines.
    surface: Rhino surface guid
        Untrimmed or trimmed Rhino NURBS surface.
    curve_features: Rhino curve guid
        Rhino NURBS curve on the surface.
    point_features: Rhino point guid
        Rhino point on the surface.

    Returns
    -------
    output: list
        Planar parameterised geometrical output: boundary, holes, polyline features and point features.

    Raises
    ------
    -

    """
    
    boundaries = surface_borders(surface_guid, border_type = 1)
    boundary_polylines = [curve_discretisation(boundary, discretization_spacing) for boundary in boundaries]
    uv_boundary_polylines = [[rs.SurfaceClosestPoint(surface_guid, vertex) for vertex in rs.PolylineVertices(boundary_polyline)] for boundary_polyline in boundary_polylines]
    planar_boundary_polylines = [[[u, v, 0] for u, v in uv_boundary_polyline] for uv_boundary_polyline in uv_boundary_polylines]
    planar_boundary_polyline = []
    for polyline in planar_boundary_polylines:
        planar_boundary_polyline += polyline[: -1]
    planar_boundary_polyline.append(planar_boundary_polyline[0])
    rs.DeleteObjects(boundaries)
    rs.DeleteObjects(boundary_polylines)

    holes = surface_borders(surface_guid, border_type = 2)
    if len(holes) > 1:
        holes = rs.JoinCurves(holes, delete_input = True)
    hole_polylines = [curve_discretisation(hole, discretization_spacing) for hole in holes]
    uv_hole_polylines = [[rs.SurfaceClosestPoint(surface_guid, vertex) for vertex in rs.PolylineVertices(hole_polyline)] for hole_polyline in hole_polylines]
    planar_hole_polylines = [[[u, v, 0] for u, v in hole] for hole in uv_hole_polylines]
    rs.DeleteObjects(holes)
    rs.DeleteObjects(hole_polylines)

    polyline_features = [curve_discretisation(curve_features_guid, discretization_spacing) for curve_features_guid in curve_features_guids]
    uv_polyline_features = [[rs.SurfaceClosestPoint(surface_guid, vertex) for vertex in rs.PolylineVertices(polyline_feature)] for polyline_feature in polyline_features]
    planar_polyline_features = [[[u, v, 0] for u, v in feature] for feature in uv_polyline_features]
    rs.DeleteObjects(polyline_features)

    uv_point_features = [rs.SurfaceClosestPoint(surface_guid, point) for point in point_features_guids]
    planar_point_features = [[u, v, 0] for u, v in uv_point_features]

    return planar_boundary_polyline, planar_hole_polylines, planar_polyline_features, planar_point_features
Example #10
0
def close_curve():
    curve_a = curves[0]
    curve_b = curves[1]
    points_a = [rs.CurveStartPoint(curve_a), rs.CurveEndPoint(curve_a)]
    points_b = [rs.CurveStartPoint(curve_b), rs.CurveEndPoint(curve_b)]
    for test_point in points_a:
        closest_point = rs.PointArrayClosestPoint(points_b, test_point)
        curves.append(rs.AddLine(test_point, points_b[closest_point]))
        points_b.pop(closest_point)
    rs.JoinCurves(curves, True)
    print "Curves closed"
 def CreateULine(self, x0, x1, y0, y1, z):
     r = 0.5
     sp4 = r - math.sin(math.pi / 4) * r
     return rs.JoinCurves([
         rs.AddLine((x0, y1, z), (x0, y0 + r, z)),
         rs.AddArc3Pt((x0, y0 + r, z), (x0 + r, y0, z),
                      (x0 + sp4, y0 + sp4, z)),
         rs.AddLine((x0 + r, y0, z), (x1 - r, y0, z)),
         rs.AddArc3Pt((x1 - r, y0, z), (x1, y0 + r, z),
                      (x1 - sp4, y0 + sp4, z)),
         rs.AddLine((x1, y0 + r, z), (x1, y1, z))
     ], True)
 def CreateEdgeSupport(self, edge, circle):
     edgeParameters = []
     circleParameters = []
     intersections = rs.CurveCurveIntersection(edge, circle)
     for intersection in intersections:
         edgeParameters.append(intersection[5])
         circleParameters.append(intersection[7])
     edgeCurves = rs.SplitCurve(edge, edgeParameters, True)
     edge = self.Keep(edgeCurves, 1, 0)
     circleCurves = rs.SplitCurve(circle, circleParameters, True)
     arc = self.Keep(circleCurves, 2)
     return rs.JoinCurves([edge, arc], True)
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
def joinLayCrvs():

    origLayer = rs.CurrentLayer()
    #shortName = rs.LayerName(origLayer, fullpath = False)
    fullname = rs.LayerName(origLayer)

    objs = rs.ObjectsByLayer(fullname)
    curves = []
    for obj in objs:
        if (rs.IsCurve(obj)):
            curves.append(obj)
    if (len(curves) > 1):
        rs.JoinCurves(curves, True)
Example #15
0
    def copyAndMover(self, first, mid, last, points, text):
        plane = rs.PlaneFromPoints(points[0], points[1], points[2])
        uv1 = rs.PlaneClosestPoint(plane, points[1], False)
        uv2 = rs.PlaneClosestPoint(plane, points[2], False)
        distHor = abs(uv1[0] - uv2[0])
        distVert = abs(uv1[1] - uv2[1])
        key = 'len{0}{1}'.format(distHor, distVert)
        key = re.sub(r'\.', '', key)
        if key in self.partsHash:
            self.partsHash[key].append(text)
        else:
            self.partsHash[key] = []
            self.partsHash[key].append(text)
            ypos = len(self.partsHash.keys()) + len(self.partsHash.keys())
            rs.AddText(key, [0, ypos, 0], 0.3)
            newPoints = [
                rs.AddPoint(0, ypos, 0),
                rs.AddPoint(self.FLAT_LENGTH, ypos, 0),
                rs.AddPoint(self.FLAT_LENGTH + distHor, ypos + distVert, 0),
                rs.AddPoint((self.FLAT_LENGTH * 2) + distHor, ypos + distVert,
                            0)
            ]
            first = rs.OrientObject(first, points, newPoints, 1)
            mid = rs.OrientObject(mid, points, newPoints, 1)
            last = rs.OrientObject(last, points, newPoints, 1)
            first_fillet = rs.AddFilletCurve(first, mid, 0.09375)
            fillet_points = rs.CurveFilletPoints(first, mid, 0.09375)
            first_circle = rs.AddCircle(fillet_points[2], 0.09375)
            first_cp = rs.CurveClosestPoint(first, fillet_points[0])
            first_domain = rs.CurveDomain(first)
            first = rs.TrimCurve(first, (first_domain[0], first_cp), True)
            second_cp = rs.CurveClosestPoint(mid, fillet_points[1])
            second_domain = rs.CurveDomain(mid)
            mid = rs.TrimCurve(mid, (second_cp, second_domain[1]), True)

            second_fillet = rs.AddFilletCurve(mid, last, 0.09375)
            fillet_points = rs.CurveFilletPoints(mid, last, 0.09375)
            second_circle = rs.AddCircle(fillet_points[2], 0.09375)
            first_cp = rs.CurveClosestPoint(mid, fillet_points[0])
            first_domain = rs.CurveDomain(mid)
            mid = rs.TrimCurve(mid, (first_domain[0], first_cp), True)
            second_cp = rs.CurveClosestPoint(last, fillet_points[1])
            second_domain = rs.CurveDomain(last)
            last = rs.TrimCurve(last, (second_cp, second_domain[1]), True)
            curve = rs.JoinCurves(
                [first, first_fillet, mid, second_fillet, last])

            rs.AddCircle([0, ypos - 0.125 - 0.09375, 0], 0.09375)
            rs.AddCircle([(self.FLAT_LENGTH * 2) + distHor,
                          ypos + distVert + 0.125 + 0.09375, 0], 0.09375)
 def CreateArc(self, a0, a1, r0, r1, z0):
     aa = (a0 + a1) / 2
     pa = (r0 * math.cos(aa), r0 * math.sin(aa), z0)
     pb = (r1 * math.cos(aa), r1 * math.sin(aa), z0)
     p0 = (r0 * math.cos(a0), r0 * math.sin(a0), z0)
     p1 = (r0 * math.cos(a1), r0 * math.sin(a1), z0)
     p2 = (r1 * math.cos(a1), r1 * math.sin(a1), z0)
     p3 = (r1 * math.cos(a0), r1 * math.sin(a0), z0)
     return rs.JoinCurves([
         rs.AddArc3Pt(p0, p1, pa),
         rs.AddLine(p1, p2),
         rs.AddArc3Pt(p2, p3, pb),
         rs.AddLine(p3, p0)
     ], True)
def WindowContour(WinCenter):
    P1 = [WinCenter[0], 0, WinCenter[1] + 0.468 / 2]
    P2 = [WinCenter[0] + 0.272 / 2, 0, WinCenter[1]]
    P3 = [WinCenter[0], 0, WinCenter[1] - 0.468 / 2]
    P4 = [WinCenter[0] - 0.272 / 2, 0, WinCenter[1]]

    WCurveU = rs.AddInterpCurve([P4, P1, P2],
                                start_tangent=[0, 0, 2.5],
                                end_tangent=[0, 0, -2.5])
    WCurveL = rs.AddInterpCurve([P2, P3, P4],
                                start_tangent=[0, 0, -2.5],
                                end_tangent=[0, 0, 2.5])

    WCurve = rs.JoinCurves([WCurveU, WCurveL], delete_input=True)
    return WCurve
Example #18
0
def draw_rhino(p_list):
    line_list = []
    for i in range(len(p_list)):
        j = i + 1
        if i == len(p_list) - 1:
            j = 0

        line = rs.AddLine([p_list[i][0], p_list[i][1], 0],
                          [p_list[j][0], p_list[j][1], 0])
        line_list.append(line)

    rs.JoinCurves(line_list)

    for i in line_list:
        rs.DeleteObject(i)
Example #19
0
 def outer_joinery(self, curve_id, left_side):
     self._clear_geom()
     comb_points = self.comb_creator.get_comb_points(curve_id, left_side)
     if not comb_points:
         return None
     start, end = edgeGeom.get_first_and_last_points(curve_id)
     prev_point = start
     for (base_point, offset_point) in comb_points:
         s, e = self.rivet_tab(base_point, offset_point, prev_point,
                               left_side)
         prev_point = e
     self.geom_temp.append(rs.AddLine(e, end))
     if len(self.geom_temp) >= 2:
         return rs.JoinCurves(self.geom_temp, delete_input=True)
     else:
         return self.geom_temp