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 splitVertical(St, ver_item):

    ver_param = rs.DivideCurveLength(ver_item, ipHeight, False, False)
    ver_Split = rs.SplitCurve(ver_item, ver_param, True)
    ver_line_split = []

    for ver_id in range(St, len(ver_Split), 2):
        ver_item = ver_Split[ver_id]

        ver_line_split.append(ver_item)
        #rs.DeleteObject(ver_item)

    return ver_line_split
def iterativePanel(lengthPanel):
    
    #aux elements
    crvBase = rs.GetObject("Iterative mode, Select curve to be use as rail", rs.filter.curve)
    #domain for split the curve into equal parts
    domain = rs.CurveDomain(crvBase)
    t = domain[1]/2.0
    crvSplit = rs.SplitCurve(crvBase, t)
    
    #building the core
    pEnd = rs.DivideCurveEquidistant(crvSplit[1], lengthPanel, True)
        
    for i in range (len(pEnd)-1):
        #rs.AddCircle(pEnd[i], 5) #Just fot testing
        panel = rs.AddLine(pEnd[i], pEnd[i+1])
def splitcircle(circle, parameter):
    points = []
    curves = rs.SplitCurve(circle, parameter, delete_input=True)
    for cur in curves:
        points.append(rs.CurveEndPoint(cur))
    return points
Esempio n. 5
0
            continue
        if rs.CurveBooleanUnion([polylines[i], polylines[j]]):
            MN = taxicab_midnormal(pts[i], pts[j], l)

            ccx = rs.CurveCurveIntersection(polylines[i], MN)
            if ccx is None:
                continue
            if ccx[0][0] == 2:
                continue
            para_a = [ccx[0][5], ccx[1][5]]
            para_b = [ccx[0][7], ccx[1][7]]

            if para_b[0] > para_b[1]:
                para_b = [para_b[1], para_b[0]]

            probable_dash = rs.SplitCurve(polylines[i], para_a)
            edge = rs.TrimCurve(MN, para_b, False)
            edgepts = rs.CurvePoints(edge)

            for crv in probable_dash:
                crvpts = rs.CurvePoints(crv)
                if rs.PointCompare(crvpts[0], edgepts[0]):
                    crvpts.reverse()
                newpl = rs.AddPolyline(edgepts + crvpts)
                if rs.PointInPlanarClosedCurve(pts[i], newpl):
                    polylines[i] = newpl
                    break

            ccx = rs.CurveCurveIntersection(polylines[j], MN)
            if ccx is None:
                continue
Esempio n. 6
0
    def get_cut_path_closed(self, crv):

        #crea la curva de corte y la curva de plunge en el nivel original
        plunge_distance = self.input_data[
            "plunge"] if self.compensation != 0 else 10.0
        no_entries = self.input_data["entries"]
        level_depth = self.input_data["depth"] / no_entries
        crv_domain = rs.CurveDomain(crv)
        crv_length = rs.CurveLength(crv)
        if plunge_distance >= crv_length: plunge_distance = crv_length * .8
        crv_domain_param = crv_domain[1] - crv_domain[0]
        trim_domain = (plunge_distance * crv_domain_param) / crv_length
        planar_plunge_crv, cut_crv = rs.SplitCurve(
            rs.CopyObject(crv),
            rs.CurveDomain(crv)[0] + trim_domain)
        no_points = int(rs.CurveLength(planar_plunge_crv) / POINT_TOL)
        plunge_pts = rs.DivideCurve(planar_plunge_crv,
                                    no_points,
                                    create_points=False,
                                    return_points=True)
        plunge_moved_pts = []
        z_count = abs(level_depth)
        z_pass = abs(level_depth / no_points)
        for pt in plunge_pts:
            new_point = pt[0], pt[1], pt[2] + z_count
            plunge_moved_pts.append(new_point)
            z_count -= z_pass

        plunge_crv = rs.AddPolyline(plunge_moved_pts)
        rs.SimplifyCurve(plunge_crv)

        #Crea la curva de corte para pocketing si se requiere
        pocketing_crv = None if not self.pocketing else self.finish_pocket_curves(
            self.make_pocket_curves(crv))
        #Lista final de operacion de cortador por curva
        curves_cut_path = []
        #agrega la entrada del cortador

        entry_end_point = rs.CurveStartPoint(planar_plunge_crv)
        sec_plane = self.general_input["sec_plane"]
        in_curve = rs.AddLine(
            (entry_end_point[0], entry_end_point[1], sec_plane),
            entry_end_point)
        rs.ObjectColor(in_curve, color_palette["plunge"])
        curves_cut_path.append(in_curve)
        #general la lista de curvas y las ordena por nivel diferenciando entre plunge y corte por color
        for entrie in range(1, int(no_entries) + 1):
            z_level = level_depth * entrie
            translation = rs.VectorAdd((0, 0, 0), (0, 0, z_level))
            level_plunge = rs.CopyObject(plunge_crv, translation)
            level_cut = rs.CopyObject(cut_crv, translation)
            rs.ObjectColor(level_plunge, color_palette["plunge"])
            rs.ObjectColor(level_cut, color_palette["cut"])
            curves_cut_path.append(level_plunge)
            curves_cut_path.append(level_cut)
            if self.pocketing:
                pocketing_curves = self.get_pocket_entry(
                    z_level, translation, pocketing_crv)
                curves_cut_path += pocketing_curves
        #agrega la ultima linea de corte como plunge para no generar bote de pieza tan brusco
        final_cut = rs.CopyObject(planar_plunge_crv, translation)
        rs.ObjectColor(final_cut, color_palette["plunge"])
        curves_cut_path.append(final_cut)
        #agrega la salida del cortador
        final_point = rs.CurveEndPoint(final_cut)
        out_curve = rs.AddLine(final_point,
                               (final_point[0], final_point[1], sec_plane))
        rs.ObjectColor(out_curve, color_palette["cut"])
        curves_cut_path.append(out_curve)

        rs.DeleteObjects([planar_plunge_crv, plunge_crv, cut_crv, crv])

        if self.pocketing:
            for po_crv in pocketing_crv:
                if po_crv != "sec_plane":
                    rs.DeleteObject(po_crv)

        return curves_cut_path
Esempio n. 7
0
def hatchedCurve():
    """
    this script divides a curve by length and makes a hatch-dashed version of it'
    works only in world top
    version 1.1
    www.studiogijs.nl
    """

    projection = Rhino.Geometry.Vector3d(0, 0, 1)
    viewprojection = sc.doc.Views.ActiveView.ActiveViewport.CameraZ
    if not viewprojection == projection:
        print " this script only works in top view"
        return
    getcurves = rs.GetObjects(
        "select curves to change into hatch-dashed-style", 4, preselect=True)
    rs.UnselectAllObjects()
    if not getcurves:
        return

    s = sc.sticky['scale'] if sc.sticky.has_key('scale') else 1
    scale = rs.GetReal("line-width of the hatch-dashed curve", s, .5, 5)

    if not scale:
        return
    sc.sticky['scale'] = scale

    f = sc.sticky['factor'] if sc.sticky.has_key('factor') else 5
    factor = rs.GetReal("line-length factor of the hatch-dashed curve", f, 1,
                        10)

    if not factor:
        return
    sc.sticky['factor'] = factor

    #turn of the lights, magic should be done in darkness
    rs.EnableRedraw(False)

    style = Rhino.Geometry.CurveOffsetCornerStyle.Sharp
    tol = sc.doc.ModelAbsoluteTolerance
    plane = Rhino.Geometry.Plane.WorldXY

    subcurvelist = []
    offset_curves = []
    for curve in getcurves:
        # ------------------------------------------------------
        # offset curves inward and outward to create the borders
        # ------------------------------------------------------
        c = rs.coercecurve(curve)
        if not rs.IsCurvePlanar(curve):
            continue
        #else:
        #rs.HideObject(curve)

        offsets = c.Offset(plane, scale / 2, tol, style)
        if offsets:
            offset = sc.doc.Objects.Add(offsets[0])
            offset_curves.append(offset)
        offsets = c.Offset(plane, -scale / 2, tol, style)
        if offsets:
            offset = sc.doc.Objects.Add(offsets[0])
            offset_curves.append(offset)
        # -----------------------------------
        # explode c into segments if possible
        # -----------------------------------
        exploded = rs.ExplodeCurves(c)
        if exploded:
            for segment in exploded:
                subcurvelist.append(segment)
        else:
            #it appears this is for single lines only
            subcurvelist.append(rs.CopyObject(curve))

    segments = []
    # -------------------------------------------------------
    # divide subcurves into shorter segments (dashed pattern)
    # -------------------------------------------------------
    for curve in subcurvelist:
        closed = False
        if rs.coercecurve(curve).IsClosed:
            closed = True
        if rs.CurveLength(curve) > (scale * factor):
            segment_count = int(rs.CurveLength(curve) / (scale * factor / 2))
            while True:
                #we need to start with 1/2 segment, then full space, then half segment
                #so #of segments needs to be a multiple of 4
                if segment_count % 4 == 0: break
                else: segment_count += 1

            pts = rs.DivideCurve(curve, segment_count)

            if closed:
                pts = pts[
                    1:]  #remove only first point, since last point == first
            pts = pts[1:-1]  #remove first and last point

            pts = pts[::2]  #remove every other point
            # --------------
            # dash the curve
            # --------------
            for i, pt in enumerate(pts):
                t = rs.CurveClosestPoint(curve, pt)
                curves = rs.SplitCurve(curve, t)
                curve = curves[1]
                segment = curves[0]
                if closed:
                    #delete every odd segment
                    if i % 2 == 0:
                        rs.DeleteObject(segment)
                    else:
                        segments.append(segment)
                else:
                    #delete every even segment
                    if i % 2 == 1:
                        rs.DeleteObject(segment)
                    else:
                        segments.append(segment)

            #append the remaining part
            segments.append(curve)

    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

    if segments:
        segments = rs.JoinCurves(segments, True)
        layer = "hatched_curves"
        if not rs.IsLayer(layer):
            rs.AddLayer(layer)

        hatches = []
        #create the hatches
        for s in segments:
            rs.ObjectLayer(hatchthis(s), layer)
        for offset in offset_curves:
            rs.ObjectLayer(offset, layer)

    #clean up
    rs.DeleteObjects(segments)
    rs.HideObjects(getcurves)
    rs.DeleteObjects(curves)
    #put on the lights, it's the result that counts
    rs.EnableRedraw(True)
Esempio n. 8
0
def trim_boundary(e_crvs, cb_crvs, tol, inside=True):
    """input:
	e_crvs: etch curves to be trimmed
	cb_crvs: closed boundary curves
	tol: tolerance. document tolerance recommended
	inside=True: trim the inside if true, trim outside if false
	returns the trimmed curves.
	NOTE: assumes redraw is turned off. assumes curves are planar.
	future versions to use projection method to avoid these assumptions."""

    #remove non-crv inputs
    e_crvs = [x for x in e_crvs if rs.ObjectType(x) == 4]
    cb_crvs = [x for x in cb_crvs if rs.ObjectType(x) == 4]

    #split curves
    split_crvs = []
    for e in e_crvs:
        intersection_list = []
        for c in cb_crvs:
            ccx_out = rs.CurveCurveIntersection(e, c, tol)
            if ccx_out is None: continue
            params = [x[5] for x in ccx_out if x[0] == 1
                      ]  #if pt intersection type; get param on etch crv
            intersection_list.extend(params)
        if intersection_list:
            split_crvs.extend(rs.SplitCurve(e, intersection_list))

    #append non-split curves
    no_split = []
    for e in e_crvs:
        id = sc.doc.Objects.Find(e)
        if id != None: no_split.append(e)
    split_crvs.extend(no_split)
    #rs.ObjectLayer(split_crvs,"XXX_LCUT_02-SCORE")

    #build regions for boundary test
    srfs = rs.AddPlanarSrf(cb_crvs)
    line = rs.AddLine([0, 0, -5], [0, 0, 5])
    rs.MoveObjects(srfs, [0, 0, -5])
    vols = []
    for srf in srfs:
        ext = rs.ExtrudeSurface(srf, line, True)
        if ext != None: vols.append(ext)
    rs.DeleteObjects(srfs)
    rs.DeleteObject(line)

    #categorize inside/outside curves
    keep_crvs = []
    delete_crvs = []
    for c in split_crvs:
        if inside == True:
            keep_crvs.append(c) if not multi_test_in_or_out(
                c, vols) else delete_crvs.append(c)
        else:
            keep_crvs.append(c) if multi_test_in_or_out(
                c, vols) else delete_crvs.append(c)

    #rs.ObjectLayer(keep_crvs,"XXX_LCUT_04-ENGRAVE")
    rs.DeleteObjects(vols)
    rs.DeleteObjects(delete_crvs)

    return keep_crvs