def unionAllCurves(Curves): res = [] for curveCount in range(0, len(Curves), 2): try: sc.doc = rc.RhinoDoc.ActiveDoc #change target document rs.EnableRedraw(False) guid1 = sc.doc.Objects.AddCurve(Curves[curveCount]) guid2 = sc.doc.Objects.AddCurve(Curves[curveCount + 1]) all = rs.CurveBooleanUnion([guid1, guid2]) rs.DeleteObjects(guid1) rs.DeleteObjects(guid2) if all: a = [rs.coercegeometry(a) for a in all] for g in a: g.EnsurePrivateCopy() #must ensure copy if we delete from doc rs.DeleteObjects(all) sc.doc = ghdoc #put back document rs.EnableRedraw() if a == None: a = [Curves[curveCount], Curves[curveCount + 1]] except: rs.DeleteObjects(guid1) sc.doc = ghdoc #put back document rs.EnableRedraw() a = [Curves[curveCount]] if a: res.extend(a) return res
def create_board(self, size=CELL_SIZE): """Drawing a game board""" board_location_point = rs.GetPoint("Set board starter point") if board_location_point: self.board_location_point = board_location_point point = self.board_location_point self.grid = [] for i in range(3): row = [] for j in range(3): x1 = point[0] + i * size y1 = point[1] + j * size x2 = point[0] + (i + 1) * size y2 = point[1] + (j + 1) * size row.append([(x1, y1), (x2, y2)]) self.grid.append(row) rectangles = [ rs.AddRectangle((point[0], point[1] + size - size * .025, 0), size * 3, size * .05), rs.AddRectangle((point[0], point[1] + 2 * size - size * .025, 0), size * 3, size * .05), rs.AddRectangle((point[0] + size - size * .025, point[1], 0), size * .05, size * 3), rs.AddRectangle((point[0] + 2 * size - size * .025, point[1], 0), size * .05, size * 3) ] rs.CurveBooleanUnion(rectangles) rs.DeleteObjects(rectangles)
def draw_x(self, point, size=CELL_SIZE): """Drawing X""" x = point[0] - size * .025 y = point[1] - (size * .75) / 2 r = rs.AddRectangle((x, y, 0), size * .05, size * .75) rectangles = [ rs.RotateObject(r, point, 45, copy=True), rs.RotateObject(r, point, -45, copy=True) ] rs.DeleteObject(r) rs.CurveBooleanUnion(rectangles) rs.DeleteObjects(rectangles)
def main(): diameter = rs.GetReal("enter cutter diameter", number=0.25) diameter = diameter * 1.1 # first, select objects in three orthogonal planes obj = rs.GetObject("select object", filter=4) # curve curve_points = rs.CurvePoints(obj)[:-1] circles = [] while True: point = rs.GetPoint("select point") if point is None: break try: idx = curve_points.index(point) print "clicked index", idx except ValueError: print "invalid point" continue points = [ curve_points[(idx + 1) % len(curve_points)], curve_points[idx], curve_points[(idx - 1) % len(curve_points)], ] print points angle = rs.Angle2( (points[1], points[0]), (points[1], points[2]), ) angle = angle[0] point = rs.VectorAdd( points[1], rs.VectorRotate( 0.5 * diameter * rs.VectorUnitize(rs.VectorSubtract(points[2], points[1])), angle / 2, (0, 0, 1))) #p0 = (point.X, point.Y, point.Z + 1000) #p1 = (point.X, point.Y, point.Z - 1000) circle = rs.AddCircle(point, diameter / 2.0) circles.append(circle) #extrusion = rs.ExtrudeCurveStraight(circle, p0, p1) rs.CurveBooleanUnion(circles + [obj]) rs.DeleteObjects(circles) rs.DeleteObject(obj)
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)
import rhinoscriptsyntax as rs curve_ids = rs.GetObjects("Select curves to union", 4) if len(curve_ids) > 1: result = rs.CurveBooleanUnion(curve_ids) if result: rs.DeleteObjects(curve_ids)
l = 2 * r """ PL = taxicab_midnormal ( A, B, r ) """ pts = P polylines = [] for pt in P: polylines.append(taxicab_circle(pt, r)) for i in range(len(polylines)): for j in range(i): if i == j: 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)
def create_bone(point, curve, length, width, radius, extend): if not extend: extend = 0.001 curve_surface = rs.AddPlanarSrf(curve) if not curve_surface: exp_curves = rs.ExplodeCurves(curve) curve_surface = rs.AddEdgeSrf(exp_curves) rs.DeleteObjects(exp_curves) print("Surface problem") # circle = rs.AddCircle(rs.CurveAreaCentroid(curve)[0],10000) # planar_surface = rs.AddPlanarSrf(circle) # projected_curve = rs.ProjectCurveToSurface(curve,planar_surface,(0,0,-1)) # if not projected_curve: rs.ProjectCurveToSurface(curve,planar_surface,(0,0,1)) # if not projected_curve: print "noooooo" # curve_surface = rs.AddPlanarSrf(projected_curve) # rs.DeleteObjects([circle,planar_surface,curve]) # curve = rs.JoinCurves(rs.DuplicateEdgeCurves(curve_surface, select=False)) # if not curve_surface: print "WARNING" main_point_param = rs.CurveClosestPoint(curve, point) curve_normal = rs.CurveNormal(curve) curve_plane = rs.CurvePlane(curve) tangent = rs.CurveTangent(curve, main_point_param) center_curve = rs.AddLine((0, 0, 0), rs.VectorScale(tangent, length)) rs.RotateObject(center_curve, (0, 0, 0), 90, curve_normal) rs.MoveObject(center_curve, rs.VectorCreate(point, (0, 0, 0))) if not rs.IsPointOnSurface(curve_surface, rs.CurveEndPoint(center_curve)): rs.RotateObject(center_curve, point, 180, curve_normal) normal = rs.VectorScale(tangent, 10000) normal_inverted = rs.VectorReverse(normal) side_curve = rs.OffsetCurveOnSurface(center_curve, curve_surface, width / 2) if not side_curve: side_curve = rs.OffsetCurveOnSurface(center_curve, curve_surface, -width / 2) side_curves = [ side_curve, rs.RotateObject( side_curve, rs.CurveMidPoint(center_curve), 180, rs.VectorCreate(rs.CurveStartPoint(center_curve), rs.CurveEndPoint(center_curve)), True) ] #side_curves = [side_curve,rs.MirrorObject(side_curve,rs.CurveStartPoint(center_curve),rs.CurveEndPoint(center_curve), True)] #side_curves = [rs.OffsetCurveOnSurface(center_curve,curve_surface, width/2),rs.OffsetCurveOnSurface(center_curve,curve_surface, -width/2)] for side_curve in side_curves: rs.ExtendCurveLength(side_curve, 0, 0, 2) rs.ObjectColor(side_curve, (255, 0, 0)) perimeter_curve = rs.AddCurve([ rs.CurveStartPoint(side_curves[0]), rs.CurveEndPoint(side_curves[0]), rs.CurveEndPoint(side_curves[1]), rs.CurveStartPoint(side_curves[1]), rs.CurveStartPoint(side_curves[0]) ], 1) inside_curve = rs.OffsetCurve(perimeter_curve, rs.CurveAreaCentroid(perimeter_curve)[0], radius * .7) external_curve = rs.OffsetCurve(perimeter_curve, rs.CurveAreaCentroid(perimeter_curve)[0], -extend) e_points = [ rs.CurvePoints(external_curve)[0], rs.CurvePoints(external_curve)[3] ] e_perimeter_curve = rs.AddCurve([ rs.CurveEndPoint(side_curves[1]), rs.CurveEndPoint(side_curves[0]), e_points[0], e_points[1], rs.CurveEndPoint(side_curves[1]) ], 1) center_plane_a = rs.PlaneFromPoints( rs.CurvePoints(inside_curve)[2], rs.CurvePoints(inside_curve)[1], rs.CurvePoints(inside_curve)[3]) center_plane_b = rs.PlaneFromPoints( rs.CurvePoints(inside_curve)[1], rs.CurvePoints(inside_curve)[0], rs.CurvePoints(inside_curve)[2]) circles = [ rs.AddCircle(center_plane_a, radius + RADIUS_TOLERANCE), rs.AddCircle(center_plane_b, radius + RADIUS_TOLERANCE) ] bone_curve = rs.CurveBooleanUnion( [e_perimeter_curve] + circles) if extend else rs.CurveBooleanUnion([perimeter_curve] + circles) rs.DeleteObjects([ inside_curve, center_curve, perimeter_curve, curve_surface, e_perimeter_curve, external_curve ] + side_curves + circles) return bone_curve
def Main(): input_curves = rs.GetObjects("Curves", rs.filter.curve, True, True) input_points = rs.GetObjects("Points for dogboone placement", rs.filter.point) if not input_curves or not input_points: return #Reads, asks and writes settings to document data_name = "dogbone2" values = rs.GetDocumentData(data_name, "settings") values = json.loads(values)["data"] if values else [ "35.0", "15.0", "9.525", "1" ] settings = ["Length:", "With:", "Diameter:", "Tolerance Offset:"] length, width, diam, aperture = [ float(i.replace(" ", "")) for i in rs.PropertyListBox( settings, values, "DogBone by dfmd", "Settings:") ] rs.SetDocumentData(data_name, "settings", json.dumps({"data": [length, width, diam, aperture]})) sorted_points = [] clean_curves = [] rs.EnableRedraw(False) for curve in input_curves: point_list = [] for point in input_points: if rs.PointInPlanarClosedCurve(point, curve, rs.CurvePlane(curve)) == 2: point_list.append(point) if point_list: sorted_points.append(rs.SortPointList(point_list)) #Clean curve # circle = rs.AddCircle(rs.CurveAreaCentroid(curve)[0],10000) # planar_surface = rs.AddPlanarSrf(circle) # projected_curve = rs.ProjectCurveToSurface(curve,planar_surface,(0,0,-1)) # clean_curves.append(projected_curve) # rs.DeleteObjects([circle,planar_surface,curve]) clean_curves.append(curve) #main_curve = rs.GetCurveObject("Selecciona curva",True)[0] #main_points = rs.SortPointList(rs.GetObjects("Selecciona puntos de referencia",rs.filter.point)) #input_curves = rebuild_curves(input_curves) for main_curve in clean_curves: main_points = sorted_points[clean_curves.index(main_curve)] bone_curves = [ create_bone(point, main_curve, length, width, diam / 2, aperture) for point in main_points ] #new_main_curve = rs.CopyObject(rs.ConvertCurveToPolyline(main_curve,False,False,True)) new_main_curve = rs.CopyObject(main_curve) completed = True for bone_curve in bone_curves: buffer_curve = rs.CurveBooleanDifference(new_main_curve, bone_curve) if len(buffer_curve) > 1: rs.DeleteObjects(buffer_curve) rs.DeleteObject(new_main_curve) completed = False break rs.DeleteObject(new_main_curve) new_main_curve = buffer_curve if not completed: super_curve = rs.CurveBooleanUnion(bone_curves) rare_curves = rs.CurveBooleanDifference(main_curve, super_curve) if len(rare_curves) > 1: areas = [rs.CurveArea(i) for i in rare_curves] sorted_curves = [ x for (y, x) in sorted(zip(areas, rare_curves)) ] rs.DeleteObjects(sorted_curves[:-1]) rs.DeleteObject(super_curve) rs.DeleteObjects(bone_curves + [main_curve])