def GenStaggeredCourtyardBlock(site_crv, setback, stepbacks, bay_gap, fsr_li, flr_depth): bldg_srf_li = [] outer_setback_crv = rs.OffsetCurve(site_crv, rs.CurveAreaCentroid(site_crv)[0], setback) inner_floor_crv = rs.OffsetCurve(site_crv, rs.CurveAreaCentroid(site_crv)[0], setback + flr_depth) req_ht = (rs.CurveArea(site_crv)[0] * fsr_li[0]) / ( rs.CurveArea(outer_setback_crv)[0] - rs.CurveArea(inner_floor_crv)[0]) l = rs.AddLine([0, 0, 0], [0, 0, req_ht]) srf = rs.AddPlanarSrf([outer_setback_crv, inner_floor_crv]) srf2 = rs.ExtrudeSurface(srf, l) rs.DeleteObject(l) prev_ht = req_ht k = 1 for depth in stepbacks: req_ar = rs.CurveArea(site_crv)[0] * fsr_li[k] itr_stepback_crv = rs.OffsetCurve(site_crv, rs.CurveAreaCentroid(site_crv)[0], setback + depth) got_ar = rs.CurveArea(itr_stepback_crv)[0] - rs.CurveArea( inner_floor_crv)[0] ht = req_ar / got_ar l = rs.AddLine([0, 0, 0], [0, 0, ht]) srf = rs.AddPlanarSrf([itr_stepback_crv, inner_floor_crv]) srf2 = rs.ExtrudeSurface(srf, l) rs.MoveObject(srf2, [0, 0, prev_ht]) rs.DeleteObject(l) rs.DeleteObject(srf) bldg_srf_li.append(srf2) # prev_ht += ht k += 1
def GenStagerredBlock(site_crv, setback, stepbacks, bay_gap, fsr_li, flr_depths): bldg_srf_li = [] setback_crv = rs.OffsetCurve(site_crv, rs.CurveAreaCentroid(site_crv)[0], setback) ht = fsr_li[0] * rs.CurveArea(site_crv)[0] / rs.CurveArea(setback_crv)[0] pl_srf0 = rs.AddPlanarSrf(setback_crv) l = rs.AddLine([0, 0, 0], [0, 0, ht]) ext_srf = rs.ExtrudeSurface(pl_srf0, l) rs.DeleteObjects([l, pl_srf0]) k = 1 for depth in stepbacks: stepback_crv = rs.OffsetCurve(setback_crv, rs.CurveAreaCentroid(site_crv)[0], depth) ht2 = rs.CurveArea(site_crv)[0] * fsr_li[k] / rs.CurveArea( stepback_crv)[0] l = rs.AddLine([0, 0, 0], [0, 0, ht2]) pl_srf = rs.AddPlanarSrf(stepback_crv) ext_srf = rs.ExtrudeSurface(pl_srf, l) rs.MoveObject(ext_srf, [0, 0, ht]) bldg_srf_li.append(ext_srf) rs.DeleteObject(l) rs.DeleteObject(pl_srf) ht += ht2 k += 1
def search_placement_per_course(avail_geos, geos, vec=rs.AddPoint(1, 0, 0), dir_vecs=[1], rotation_degs=[0], vec_ampl=1, _search_size=2, rot_geo_degs=[0], placed_geos=[]): placed_bricks_per_course = [] all_tests_per_course = [] overl_areas = [] test_avail_geos = [] # verify len of avail geos if len(avail_geos) > 1: # for ig, g1 in enumerate(geos): for ig, avail_geo in enumerate(avail_geos): # translate avail geo to g1 loc g1 = geos[ig] avail_geo = geo_translate( avail_geo, rs.VectorCreate( rs.CurveAreaCentroid(g1)[0], rs.CurveAreaCentroid(avail_geo)[0])) test_avail_geos.append(avail_geo) for g2 in geos: # if g1 == g2: if rs.CurveAreaCentroid(avail_geo)[0] == rs.CurveAreaCentroid( g2)[0]: continue else: res = search_placement_between_two_units( avail_geo, g2, vec=get_geo_or(avail_geo), dir_vecs=dir_vecs, rotation_degs=rotation_degs, _search_size=_search_size, vec_ampl=vec_ampl, rot_geo_degs=rot_geo_degs, placed_geos=placed_bricks_per_course) if res[1]: placed_bricks_per_course.append(res[1]) all_tests_per_course.extend(res[0]) overl_areas.append(res[2]) return placed_bricks_per_course, len( placed_bricks_per_course ), all_tests_per_course, overl_areas, test_avail_geos
def GenCourtyardBlock(site_crv, setback, flr_depth, bay_gap, fsr): setback_crv = rs.OffsetCurve(site_crv, rs.CurveAreaCentroid(site_crv)[0], setback) inner_crv = rs.OffsetCurve(setback_crv, rs.CurveAreaCentroid(site_crv)[0], flr_depth) got_ar = rs.CurveArea(setback_crv)[0] - rs.CurveArea(inner_crv)[0] req_ar = rs.CurveArea(site_crv)[0] * fsr ht = req_ar / got_ar l = rs.AddLine([0, 0, 0], [0, 0, ht]) pl_srf = rs.AddPlanarSrf([setback_crv, inner_crv]) ext_srf = rs.ExtrudeSurface(pl_srf, l) # rs.DeleteObject(l) rs.DeleteObject(pl_srf)
def OffsetCurve(self, level_cut): check_presision = 10 offset_type = 1 branched_curves = [] main_curve = level_cut offset_distance = self.general_input["cut_diam"] * self.input_data[ "xy_dist"] curve_1 = rs.OffsetCurve(main_curve, rs.CurveAreaCentroid(main_curve)[0], -.1, None, offset_type) curve_2 = rs.OffsetCurve(main_curve, rs.CurveAreaCentroid(main_curve)[0], .1, None, offset_type) if curve_1 and curve_2: if len(curve_1) != 1 or len(curve_2) != 1: rs.DeleteObjects(curve_1) rs.DeleteObjects(curve_2) return branched_curves mini_test = self.getSmall(curve_1, curve_2) do_points = rs.DivideCurve(mini_test, check_presision, False) rs.DeleteObjects([curve_1, curve_2]) do_points.append(rs.CurveAreaCentroid(main_curve)[0]) for i in range(0, len(do_points)): new_offset_curve = rs.OffsetCurve(main_curve, do_points[i], offset_distance, None, offset_type) try: if self.isCurveNew(branched_curves, new_offset_curve) and rs.IsCurveClosed( new_offset_curve) and self.isSmall( new_offset_curve, main_curve): branched_curves.append(new_offset_curve) else: rs.DeleteObject(new_offset_curve) except: if new_offset_curve: rs.DeleteObjects(new_offset_curve) for curve in branched_curves: rs.ObjectColor(curve, color_palette["cut"]) if not branched_curves or len(branched_curves) > 1: branched_curves.append("sec_plane") return branched_curves
def areaTag(pline): #get area area = rs.CurveArea(pline)[0] area = str((int(area * 100)) / 100) + "m2" print area #move area tag below name tag location offset = [0, -2.5, 0] #add text tag objID = pline text = '%<area("' + str(objID) + '")>%m2' pt = rs.AddPoint(rs.CurveAreaCentroid(pline)[0]) rs.MoveObject(pt, offset) areaTag = rs.AddText(text, pt, 1, justification=131074) rs.DeleteObject(pt) parentLayer = rs.ParentLayer(rs.ObjectLayer(pline)) hostLayer = rs.AddLayer("ANNO_AREA", (128, 128, 128), parent=parentLayer) rs.ObjectLayer(areaTag, hostLayer) te = rs.coercerhinoobject(areaTag, True, True) te.Geometry.TextFormula = text te.CommitChanges() sc.doc.Views.Redraw() return None
def make_slots(W, L): g_W = 6 #20/L or 14/L g_L = min(W / 3, 35) #3dis grip = rs.AddRectangle([0, 0, 0], g_W, g_L) c, _ = rs.CurveAreaCentroid(grip) return [grip, c, g_W, g_L]
def wallProfile(polySrf): if polySrf: offsets = [] border = rs.DuplicateSurfaceBorder(polySrf) rs.SimplifyCurve(border) offsets.append(rs.OffsetCurve(border, [0, 0, 0], width / 2)) faces = rs.ExplodePolysurfaces(polySrf, False) faceborders = [rs.DuplicateSurfaceBorder(face) for face in faces] rs.DeleteObjects(faces) for faceborder in faceborders: rs.SimplifyCurve(faceborder) centroid = rs.CurveAreaCentroid(faceborder) offsets.append(rs.OffsetCurve(faceborder, centroid[0], width / 2)) rs.DeleteObjects(faceborders) srf = rs.AddPlanarSrf(offsets) rs.DeleteObjects(border) rs.DeleteObjects(offsets) return srf
def getSolarGeom(boundary,ht,lat,shourlst,ehourlst,day,north,long,timeZ,s_mth,e_mth): CH = ConvexHull2d() boundary_pts = rs.CurvePoints(boundary) # you'll need this later boundary_pts.pop(-1) bchullpts = CH.convex_hull(boundary_pts) centerPt = rs.CurveAreaCentroid(rs.AddCurve(bchullpts + [bchullpts[0]],1))[0] #centerPt = rs.CurveAreaCentroid(boundary)[0] boundary_plane = rs.PlaneFitFromPoints(boundary_pts) top_plane = get_plane(boundary,ht) # project curve to user_defined height sun_pts = get_sunpt(lat,centerPt,s_mth,day,shourlst,north_=north,lon=long,tZ=timeZ,scale_=100) sun_pts.extend(get_sunpt(lat,centerPt,e_mth,day,ehourlst,north_=north,lon=long,tZ=timeZ,scale_=100)) top_lst = project_curve(sun_pts,centerPt,top_plane,boundary) top_curves = map(lambda x: rs.coercecurve(x),top_lst) # temp for viz top_lst = map(lambda x: rs.CurvePoints(x),top_lst) top_pts = map(lambda x: rs.coerce3dpoint(x),\ reduce(lambda i,j:i+j,top_lst)) # convex hull methods chull_pts = CH.convex_hull(top_pts) chull_crv = rs.AddCurve(chull_pts + [chull_pts[0]],1) #chull_centerPt = rs.CurveAreaCentroid(chull_crv)[0] # adjust curve directions #if not rs.CurveDirectionsMatch(boundary,chull_crv): # rs.ReverseCurve(boundary) #b = rs.CurvePoints(boundary) + rs.CurvePoints(chull_crv) #c = rs.CurvePoints(chull_crv) return (boundary,chull_crv),top_curves
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 crackpolygon(pls, count): temppls = pls pls = [] if count == 0: return 1 else: for pl in temppls: if rs.CloseCurve(pl) == False: print "Not a closed curve" else: # print "Cool" centroid = rs.CurveAreaCentroid(pl) centpt = rs.AddPoint(centroid[0]) curves = rs.ExplodeCurves(pl) for crv in curves: # print crv pt1 = rs.CurveStartPoint(crv) pt2 = rs.CurveEndPoint(crv) pts = [] pts.append(pt1) pts.append(pt2) pts.append(centpt) pts.append(pt1) newpl = rs.AddPolyline(pts) pls.append(newpl) rs.DeleteObject(crv) cleanup = [] cleanup.append(centpt) # cleanup.append(curves) rs.DeleteObjects(cleanup) count = count - 1 return crackpolygon(pls, count)
def render_path_visualization(points, mesh_normals, layer_heights, up_vectors, extruder_toggles, cross_section, planar_printing): """ Visualize print paths with simple loft surfaces. """ # check input assert len(points) == len(mesh_normals) == len(layer_heights) == len(up_vectors) == len(extruder_toggles), \ 'Wrong length of input lists' loft_surfaces = [] travel_path_lines = [] if points[0] and mesh_normals[0] and layer_heights[0] and up_vectors[ 0]: # check if any of the values are None if planar_printing: # then make sure that all normals lie on the xy plane for n in mesh_normals: n[2] = 0 # transform and scale cross sections accordingly cen = rs.CurveAreaCentroid(cross_section)[0] origin_plane = rg.Plane(cen, rg.Vector3d(1, 0, 0), rg.Vector3d(0, 0, 1)) target_planes = [] for i, pt in enumerate(points): target_plane = rg.Plane(pt, mesh_normals[i], up_vectors[i]) target_planes.append(target_plane) cross_sections = [] for h, target_plane in zip(layer_heights, target_planes): section = rs.ScaleObject(rs.CopyObject(cross_section), origin=cen, scale=[0.9 * h, 1, 0.9 * h]) T = rg.Transform.PlaneToPlane(origin_plane, target_plane) rs.TransformObject(section, T) cross_sections.append(section) loft_surfaces = [] travel_path_lines = [] for i in range(len(points) - 1): if extruder_toggles[i]: loft = rs.AddLoftSrf( [cross_sections[i], cross_sections[i + 1]]) if loft: loft_surfaces.append(loft[0]) else: line = rg.Curve.CreateControlPointCurve( [points[i], points[i + 1]]) travel_path_lines.append(line) # add to travel path list else: print( 'At least one of the inputs that you have provided are invalid. ') return loft_surfaces, travel_path_lines
def get_brep_label_pt(brep, percent_height_distance=0.15): #get bounding box bb = rs.BoundingBox(brep) top_crv = rs.AddPolyline([bb[4], bb[5], bb[6], bb[7], bb[4]]) top_label_pt, _ = rs.CurveAreaCentroid(top_crv) top_label_pt = rs.VectorAdd( top_label_pt, [0, 0, rs.Distance(bb[0], bb[1]) * percent_height_distance]) rs.DeleteObject(top_crv) return top_label_pt
def make_zone(pts, bound): # make_zone: (listof pt), curve -> (listof solid) los = [] # get centroid from boundary curve center_pt = rs.CurveAreaCentroid(bound)[0] # extrude solids from sun path for sp in pts: extruded = extrude_solid(sp, center_pt, bound) los.append(extruded) # boolean interesect all return bool_solids(los)
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)
def postProcess(self): REDO=False ar=0.0 for i in self.FPOLY: rs.RotateObject(i, CP, -ANGLE) for i in self.FPOLY: try: ar+=rs.CurveArea(i)[0] except: pass mean_ar=ar/len(self.FPOLY) min_ar_per=0.2*mean_ar j=0 for i in self.FPOLY: pts=rs.CurvePoints(i) if(rs.CurveArea(i)[0]<min_ar_per): REDO=True break p=rs.BoundingBox(pts) max_poly=rs.AddPolyline([p[0],p[1],p[2],p[3],p[0]]) max_poly_ar=rs.CurveArea(max_poly)[0] actual_poly_ar=rs.CurveArea(i)[0] if((max_poly_ar/actual_poly_ar)>2): REDO=True rs.DeleteObject(max_poly) break else: rs.DeleteObject(max_poly) ab=int(rs.Distance(p[0],p[1])) ad=int(rs.Distance(p[0],p[3])) if((ab>ad) and (ab/ad)>5): REDO=True break elif((ab<ad) and (ab/ad)<0.2): REDO=True break j+=1 if(REDO==True and self.counter<MAX_REC): self.counter+=1 print("Redo %s" %(self.counter)) rs.DeleteObjects(self.FPOLY) self.start() self.recSplit(bsp.BBpts, 0) self.postProcess() else: j=0 for i in self.FPOLY: c=rs.CurveAreaCentroid(i)[0] rs.AddTextDot(str(j), c) j+=1
def make_zone(pts, bound): # make_zone: (listof pt), curve -> (listof solid) los = [] # get centroid from boundary curve center_pt = rs.CurveAreaCentroid(bound)[0] # extrude solids from sun path for p in pts: line = rs.AddCurve([center_pt, p], 1) extruded = extrude_solid(p, center_pt, bound) los.append(extruded) # boolean interesect all los_ = map(lambda g: rs.coercegeometry(g), los) return bool_solids(los)
def removePoly(bsp_tree, int_crv): del_crv = [] used_crv = [] for crv in bsp_tree: try: cen = rs.CurveAreaCentroid(crv)[0] if (rs.PointInPlanarClosedCurve(cen, int_crv) == 1): del_crv.append(crv) except: print("error") for crv in del_crv: bsp_tree.remove(crv) rs.DeleteObject(crv) return bsp_tree
def get_brep_labelpt(brep, multiplier): """get the label point for the top of a brep. params brep(brep): the brep multiplier (float): label will be (multiplier * brep height) above the brep returns GUID of point for the label.""" bb = rs.BoundingBox(brep) height = rs.Distance(bb[0], bb[4]) top_crv = rs.AddPolyline(bb[4:8] + [bb[4]]) top_label_pt, _ = rs.CurveAreaCentroid(top_crv) rs.MoveObject(top_label_pt, [0, 0, multiplier * height]) rs.DeleteObject(top_crv) return top_label_pt
def GroupMove(rectOutlineList, objects, objCenter, rotatedAngle, movingCenter): for objs, rect, center, rotAngle, centerStart in zip( objects, rectOutlineList, objCenter, rotatedAngle, movingCenter): # rotate everything by center with rotatedAngle rs.RotateObjects(objs, center, rotAngle) # find vector to move from obj location to rectangle(obj center to rect center) boxCenter = rs.CurveAreaCentroid(rect)[0] moveVector = rs.VectorCreate(boxCenter, center) # check if object is in box rectPt = rs.PolylineVertices(rect) rectPt = PointsReorder(rectPt, 1) if rs.Distance(rectPt[0], rectPt[1]) > rs.Distance( rectPt[1], rectPt[2]): rs.RotateObjects(objs, center, 90) rs.MoveObjects(objs, moveVector)
def get_vectors(face, points, brep_vec): face_cpt = rc.Geometry.Vector3d(rs.CurveAreaCentroid(face)[0]) vec_A = rc.Geometry.Vector3d(points[1] - points[0]) vec_B = rc.Geometry.Vector3d(points[2] - points[1]) normal = rc.Geometry.Vector3d.CrossProduct(vec_A, vec_B) normal = (face_cpt + normal) - face_cpt normal_reverse = (face_cpt + normal) - face_cpt normal_reverse.Reverse() normal_reverse.Unitize() normal.Unitize() return normal, normal_reverse, face_cpt
def genIntPoly(self, poly): cen=rs.CurveAreaCentroid(poly)[0] pts=rs.CurvePoints(poly) a=[(pts[0][0]+pts[1][0])/2,(pts[0][1]+pts[1][1])/2,0] b=[(pts[0][0]+pts[3][0])/2,(pts[0][1]+pts[3][1])/2,0] vec1=rs.VectorScale(rs.VectorUnitize(rs.VectorCreate(cen,a)),self.d0/2) vec2=rs.VectorScale(rs.VectorUnitize(rs.VectorCreate(cen,b)),self.d1/2) p=rs.PointAdd(cen,vec1) q=rs.PointAdd(cen,-vec1) r=rs.PointAdd(p,vec2) u=rs.PointAdd(p,-vec2) t=rs.PointAdd(q,vec2) s=rs.PointAdd(q,-vec2) poly=rs.AddPolyline([r,u,s,t,r]) self.req_poly.append(poly)
def draw_cells(LISTOFCELLS): rs.EnableRedraw(False) for i in range(len(LISTOFCELLS)): for j in range(len(LISTOFCELLS[i])): nowPts = LISTOFCELLS[i][j].cellCoord crv = rs.AddCurve(nowPts, 1) pt = rs.CurveAreaCentroid(crv)[0] rs.DeleteObject(crv) sandTxt = rs.AddTextDot(LISTOFCELLS[i][j].sandHeight, pt) if (LISTOFCELLS[i][j].sandHeight == 0): rs.ObjectLayer(sandTxt, layer="Zero") elif (LISTOFCELLS[i][j].inShadow == True): rs.ObjectLayer(sandTxt, layer="ShadowNum") else: rs.ObjectLayer(sandTxt, layer="Num") rs.EnableRedraw(True)
def setCurveDir(objs): count = 0 for obj in objs: if rs.IsCurve(obj) and rs.IsCurvePlanar(obj): sp = rs.AddPoint(rs.CurveEndPoint(obj)) tangent = rs.CurveTangent(obj, rs.CurveDomain(obj)[0]) print tangent p2 = rs.CopyObject(sp, tangent * -10) rs.AddPoint(p2) # rs.Command("Dir") # for i in range(0,rs.PolyCurveCount(obj)): # l = rs.CurveLength(obj,i) # if l < 4: # print l # layer=rs.ObjectLayer(obj) # segments = rs.ExplodeCurves(obj, True) # obj = rs.JoinCurves(segments, True) # rs.ObjectLayer(obj, layer) # rs.ObjectLayer(obj, layer) normal = rs.CurveNormal(obj) result = rs.CurveAreaCentroid(obj) if result: print normal start = result[0] end = (result[0].X + 100 * normal[0], result[0].Y + 100 * normal[1], result[0].Z + 100 * normal[2]) rs.AddLine(result[0], end) if normal and normal[2] < 0: count += 1 rs.ReverseCurve(obj) # print "Curve {} flipped {}{}".format(obj, normal, normal2) # try to find discontinuities print "reversed " + str(count) + " curves"
def curveVic(storyHt): profiles = [] firstCrv = rs.GetObject("pick a base curve", 4, True, True) count = rs.GetInteger("how many total curves") #dentil = rs.GetObject("pick dentil", 8) # vertically offset curves for i in range(count): if count == 0 or count == 1: return else: profiles.append(rs.CopyObject(firstCrv, [0, 0, storyHt * i])) # funk it up - needs to be more randomized? for crv in profiles: centerPt = rs.CurveAreaCentroid(crv) # deg = random.randint(0,360) # deg = random.randint(0,4) * 90 very swirly! deg = profiles.index(crv) * 10 rs.RotateObject(crv, centerPt[0], deg) # centerPt = rs.CurveAreaCentroid(profiles[3]) # rs.RotateObject(profiles[3], centerPt[0], 30) # centerPt = rs.CurveAreaCentroid(profiles[7]) # rs.RotateObject(profiles[7], centerPt[0], 30) # scale each crv randomly # for crv in profiles: # centerPt = rs.CurveAreaCentroid(crv) # x = random.uniform(.25,2) # y = random.uniform(.25,2) # z = 1 # rs.ScaleObject(crv, centerPt[0], (x,y,z) ) # add dentils and trim. map to surface? project? rs.SporphObject() better to use in GUI flow? # is there any flow along surface? no center box?!?! just acquire shape # for j in range(len(profiles)): # points = rs.DivideCurveEquidistant(profiles[j], 5) # for k in points: # rs.AddSphere(k, .25) # loft curves and clean up finalShape = rs.AddLoftSrf(profiles, closed=False) #profiles.append(firstCrv) rs.DeleteObjects(profiles) rs.CapPlanarHoles(finalShape)
def add_slots(rect, grip, gap): g_crv = grip[0] g_c = grip[1] g_W = grip[2] center, _ = rs.CurveAreaCentroid(rect) pr_L = rs.PointAdd(center, [gap / 2, 0, 0]) pr_R = rs.PointAdd(center, [-gap / 2, 0, 0]) pg_L = rs.PointAdd(g_c, [-g_W / 2, 0, 0]) pg_R = rs.PointAdd(g_c, [g_W / 2, 0, 0]) lgrip = rs.CopyObject(g_crv, rs.VectorCreate(pr_L, pg_L)) rgrip = rs.CopyObject(g_crv, rs.VectorCreate(pr_R, pg_R)) rs.DeleteObject(g_crv) return [lgrip, rgrip]
def DetailCenter(detail): box = rs.BoundingBox(detail) pt_set = box[0:4] lines = [] for i, pt in enumerate(pt_set): if i != 3: line = rs.AddLine(pt, pt_set[i + 1]) else: line = rs.AddLine(pt, pt_set[0]) lines.append(line) rect = rs.JoinCurves(lines, True) center = rs.CurveAreaCentroid(rect)[0] return center
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
def add_tickmarks(rect, len, offset): c, _ = rs.CurveAreaCentroid(rect) mirror_v = [c, rs.PointAdd(c, [0, 10, 0])] mirror_h = [c, rs.PointAdd(c, [10, 0, 0])] pts = rs.CurvePoints(rect) if not pts: return "ERROR" pts = rs.SortPoints(pts) # print pts t_0 = rs.CopyObject(pts[0], [offset, offset, 0]) t_1 = rs.CopyObject(t_0, [len, 0, 0]) t_2 = rs.CopyObject(t_0, [0, len, 0]) tick = rs.AddPolyline([t_1, t_0, t_2]) rs.DeleteObjects([t_0, t_1, t_2]) tick_2 = rs.MirrorObject(tick, mirror_v[0], mirror_v[1], True) ticks_3 = rs.MirrorObjects([tick, tick_2], mirror_h[0], mirror_h[1], True) rs.ObjectLayer([tick, tick_2] + ticks_3, LCUT_NAMES[3]) tick_list = [tick, tick_2] + ticks_3 return tick_list
def __init__(self, curve, input_data, general_input, compensation, pocketing): self.log = [] self.input_data = input_data self.general_input = general_input self.compensation = compensation self.pocketing = pocketing self.asignedcluster = -1 self.iscluster = False self.nurbs_curve = curve self.curve = curve #Curva original2 self.type = "point" if rs.IsPoint( self.nurbs_curve) else "curve" if rs.IsCurveClosed( self.nurbs_curve) else "open_curve" self.point = self.curve if rs.IsPoint( self.nurbs_curve) else rs.CurveAreaCentroid( self.nurbs_curve)[0] if rs.IsCurveClosed( self.nurbs_curve) else rs.CurveStartPoint( self.nurbs_curve) # Centroide curva original self.start_point = rs.PointCoordinates( self.nurbs_curve, False) if rs.IsPoint( self.nurbs_curve) else rs.CurveStartPoint(self.nurbs_curve) self.cut_curve = self.get_cut_curve() self.time = 10