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 left(): #very very computationally heavy. Be patient spt = rs.CurveStartPoint(ref) r = rs.OffsetCurve(ref, [1, 0, 0], plinth_lst[2]) r_p = rs.AddEdgeSrf([ref, r]) guide_curve2 = rs.AddLine(spt, rs.PointAdd(spt, [0, 0, plinth_lst[1]])) rs.ExtrudeSurface(r_p, guide_curve2) rs.DeleteObjects([guide_curve2, r])
def subtrackCubeFrom(self, curid, pts, height): btmSuf = rs.AddSrfPt(pts) extrudeLine = rs.AddLine(pts[0],map(sum, zip(pts[0],[0,0,height]))) suf = rs.ExtrudeSurface(btmSuf, extrudeLine, True) newid = rs.BooleanDifference(curid,suf,True) rs.DeleteObjects([btmSuf,extrudeLine,suf]) return newid
def right(): spt = rs.CurveStartPoint(curve) l = rs.OffsetCurve(curve, [-1, 0, 0], plinth_lst[2]) l_p = rs.AddEdgeSrf([curve, l]) guide_curve1 = rs.AddLine(spt, rs.PointAdd(spt, [0, 0, plinth_lst[1]])) rs.ExtrudeSurface(l_p, guide_curve1) rs.DeleteObjects([guide_curve1, l])
def makeBrep(srf): point1 = rs.EvaluateSurface(srf, 0, 0) vec = rs.CreateVector(0, 0, height) point2 = rs.CopyObject(point1, vec) line = rs.AddLine(point1, point2) brep = rs.ExtrudeSurface(srf, line) if point2: rs.DeleteObjects(point2) if line: rs.DeleteObjects(line) return brep
def addWallRhino(corners, thickness, height): outWallCrv = rs.AddPolyline(corners) inWallCrv = rs.OffsetCurve(outWallCrv, [0,1,0], thickness, [0,0,1], CurveOffsetCornerStyle.Sharp) objs = [outWallCrv, inWallCrv] btmWall = rs.AddPlanarSrf(objs)[0] extrudeLine = rs.AddLine(corners[0],map(sum, zip(corners[0],[0,0,height]))) allWalls = rs.ExtrudeSurface(btmWall, extrudeLine, True) rs.DeleteObjects([outWallCrv,inWallCrv,btmWall,extrudeLine]) return allWalls
def GenExtrBlock(site_crv, setback, flr_depth, bay_gap, fsr): setback_crv = rs.OffsetCurve(site_crv, rs.CurveAreaCentroid(site_crv)[0], setback) got_ar = rs.CurveArea(setback_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) ext_srf = rs.ExtrudeSurface(pl_srf, l) # rs.DeleteObject(l) rs.DeleteObject(pl_srf)
def massFromSrf(obj): lvl = levels[rs.GetUserText(obj, 'level')] height = float(lvl['height']) startpt = trp.objBBPts(obj)[0] endpt = (startpt.X, startpt.Y, startpt.Z + height) curve = rs.AddLine(startpt, endpt) mass = rs.ExtrudeSurface(obj, curve) trp.copySourceLayer(mass, obj) trp.copySourceData(mass, obj) rs.DeleteObject(curve) return mass
def add_box(origin, x_vector, y_vector, z_vector): _srf = rss.AddSrfPt(( origin, rss.PointAdd(origin, x_vector), rss.PointAdd(origin, rss.VectorAdd(x_vector, y_vector)), rss.PointAdd(origin, y_vector) )) _crv = rss.AddLine(origin, rss.PointAdd(origin, z_vector)) box = rss.ExtrudeSurface(_srf, _crv) rss.DeleteObjects((_srf, _crv)) return box
def makeWall(obj): rs.EnableRedraw(False) shape = wallProfile(obj) railCurve = addRail(shape) wall = rs.ExtrudeSurface(shape, railCurve) rs.DeleteObjects(shape) rs.DeleteObjects(railCurve) rs.EnableRedraw(False) return wall
def addHallWall(self, roomids, corners, corners2, thickness, height): outWallCrv = rs.AddPolyline(corners) inWallCrv = rs.AddPolyline(corners2) #inWallCrv = rs.OffsetCurve(outWallCrv, [20,14,0], thickness, [0,0,1], CurveOffsetCornerStyle.Sharp) outExtrudeLine = rs.AddLine(corners[0],map(sum, zip(corners[0],[0,0,height]))) outBtmSuf = rs.AddPlanarSrf(outWallCrv)[0] outWall = rs.ExtrudeSurface(outBtmSuf, outExtrudeLine, True) inExtrudeLine = rs.AddLine(corners[0],map(sum, zip(corners[0],[0,0,height-thickness]))) inBtmSuf = rs.AddPlanarSrf(inWallCrv)[0] inWall = rs.ExtrudeSurface(inBtmSuf, inExtrudeLine, True) hallway = rs.BooleanDifference(outWall,inWall,True) rs.DeleteObjects([outWallCrv,inWallCrv,outExtrudeLine,outBtmSuf,outWall,inExtrudeLine,inBtmSuf,inWall]) newroomids = list(roomids) for roomid in roomids: newhallway = rs.BooleanDifference(hallway, roomid,False) newroomid = rs.BooleanDifference(roomid, hallway,False) newroomids.append(newroomid) rs.DeleteObject(hallway) rs.DeleteObject(roomid) hallway = newhallway return hallway
def extrude_down_srf(srf, height=None): """if no height input, extrude down by the bounding box height*2.""" if height == None: bb = rs.BoundingBox(srf) height = rs.Distance(bb[0], bb[4]) * 2 if height < D_TOL: return None path_line = rs.AddLine([0, 0, 0], [0, 0, -height]) xy_plane = rs.WorldXYPlane() extruded_srf = rs.ExtrudeSurface(srf, path_line, True) rs.DeleteObject(path_line) return extruded_srf
def main(): to_delete = [] rs.ProjectOsnaps(False) positive_object = rs.GetObject("select positive object", 16) negative_object = rs.GetObject("select negative object", 16) rs.HideObject(negative_object) polysurface, face = GetSubSurface("select tenon surface") to_delete.append(face) normal = rs.VectorUnitize(rs.SurfaceNormal(face, (0.5, 0.5))) plane = rs.PlaneFromNormal(rs.EvaluateSurface(face, 0.5, 0.5), normal) rs.ViewCPlane(plane=plane) rs.ProjectOsnaps(True) tenon_rects = rs.GetObjects(message="select tenon curves", filter=4) tenon_faces = [] for rect in tenon_rects: tenon_faces.append(rs.AddPlanarSrf(rect)[0]) rs.ShowObject(negative_object) rs.ProjectOsnaps(False) height_pt = rs.GetPoint("enter height point") # compule a vector normal to plane of the desired height extrude_vec_a = rs.EvaluateSurface(face, 0.5, 0.5) dist = rs.DistanceToPlane(plane, height_pt) extrude_vec_b = [dist * el for el in normal] extrude_vec_b = rs.VectorAdd(extrude_vec_a, extrude_vec_b) extrude_curve = rs.AddCurve((extrude_vec_a, extrude_vec_b)) to_delete.append(extrude_curve) tenons = [] for tenon_face in tenon_faces: tenon = rs.ExtrudeSurface(tenon_face, extrude_curve) tenons.append(tenon) rs.BooleanUnion([positive_object] + tenons, delete_input=False) rs.BooleanDifference([negative_object], tenons, delete_input=False) to_delete.append(positive_object) to_delete.append(negative_object) rs.DeleteObjects(to_delete) rs.DeleteObjects(tenon_faces) rs.DeleteObjects(tenons)
def CrossPlatformExtrudeSurface(SurfaceId, CurveId, Capped=True): # rs.ExtrudeSurface not implemented in Rhino for OS X if airconics_setup.RhinoVersion == 1: SolidId = rs.ExtrudeSurface(SurfaceId, CurveId, Capped) else: rs.SelectObject(CurveId) rs.Command("_SelNone") rs.SelectObject(SurfaceId) rs.Command("_ExtrudeSrfAlongCrv _SelPrev") SolidId = rs.LastCreatedObjects() rs.Command("_SelNone") return SolidId
def _build_volume_brep_from_zone(self): # Floor Surface floor_surface = rs.coercebrep(self.tfa_surface.surface) floor_surface = ghc.Move(floor_surface, ghc.UnitZ(self._offset_z) )[0] # 0 is the new translated geometry # Extrusion curve surface_centroid = Rhino.Geometry.AreaMassProperties.Compute(floor_surface).Centroid end_point = ghc.ConstructPoint(surface_centroid.X, surface_centroid.Y, surface_centroid.Z + self._space_height) extrusion_curve = rs.AddLine(surface_centroid, end_point) volume_brep = rs.ExtrudeSurface(surface=floor_surface, curve=extrusion_curve, cap=True) volume_brep = rs.coercebrep(volume_brep) return [volume_brep]
def addWall2(self, corners, thickness, height): print ("Building Wall...") pts = [ Point3d(x[0],x[1],x[2]) for x in corners] outWallCrv = PolylineCurve(pts) inWallCrv = outWallCrv.Offset(Plane.WorldXY, -thickness, doc.ModelAbsoluteTolerance, CurveOffsetCornerStyle.Sharp)[0] doc.Objects.AddCurve(outWallCrv) doc.Objects.AddCurve(inWallCrv) objs = rs.GetObjects("Select planar curves to build surface", rs.filter.curve) #objs = [outWallCrv.Id, inWallCrv.Id] if objs: btmWall = rs.AddPlanarSrf(objs)[0] extrudeLine = rs.AddLine(corners[0],map(sum, zip(corners[0],[0,0,height]))) allWalls = rs.ExtrudeSurface(btmWall, extrudeLine, True) PolylineCurve.GetObjectData()
def faces(): surfaces = rs.GetObjects("select surfaces", filter=rs.filter.surface) points = [ rs.EvaluateSurface(surface, *rs.SurfaceParameter(surface, (0.5, 0.5))) for surface in surfaces ] x = reduce(lambda s, point: s + point.X, points, 0) / len(points) y = reduce(lambda s, point: s + point.Y, points, 0) / len(points) z = reduce(lambda s, point: s + point.Z, points, 0) / len(points) # find the center of the object mass_center = rs.AddPoint(x, y, z) extrude_curves = {} # find the appropriate extrusion curve with the lowest dot product for surface in surfaces: surface_center = rs.EvaluateSurface( surface, *rs.SurfaceParameter(surface, (0.5, 0.5))) center_vector = rs.VectorCreate(surface_center, mass_center) normals = [] normals.append( rs.SurfaceNormal(surface, rs.SurfaceParameter(surface, (0.5, 0.5)))) normals.append(-rs.SurfaceNormal( surface, rs.SurfaceParameter(surface, (0.5, 0.5)))) if (rs.VectorDotProduct(normals[0], center_vector) < rs.VectorDotProduct(normals[1], center_vector)): extrude_curve = normals[0] else: extrude_curve = normals[1] extrude_curve = rs.VectorUnitize(extrude_curve) extrude_curve = rs.VectorScale(extrude_curve, 0.25) extrude_curve = [ surface_center, rs.VectorAdd(surface_center, extrude_curve) ] extrude_curve = rs.AddCurve(extrude_curve) rs.ExtrudeSurface(surface, extrude_curve) rs.DeleteObject(extrude_curve) rs.DeleteObject(surface) rs.DeleteObject(mass_center)
def e(theta, num): """ receives: theta = degree of line ( 0 < theta < 45 ) num = number of pattern ( 0 < num < 15 ) works: draw tile pattern returns: None """ def base(x, y): d = ma.radians(theta) r = 1 / ma.cos(d) - (ma.sin(d)**2) / ma.cos(d) n = r * ma.sin(d) k = r * ma.cos(d) a1 = (x, y, 0) b1 = (x, y + 1, 0) c1 = (x + 1, y + 1, 0) d1 = (x + 1, y, 0) a2 = (x + k, y + n, 0) b2 = (x + n, y + 1 - k, 0) c2 = (x + 1 - k, y + 1 - n, 0) d2 = (x + 1 - n, y + k, 0) l1 = rs.AddLine(a1, a2) l2 = rs.AddLine(b1, b2) l3 = rs.AddLine(c1, c2) l4 = rs.AddLine(d1, d2) for i in range(0, num): for k in range(0, num): base(i, k) line = rs.ObjectsByType(0) n = len(line) for i in range(0, n): a = line[i] b = rs.AddLine((0, 0, 0), (0, 0, 0.05)) c = rs.RotateObject(b, (0, 0, 0), 90, None, False) s = rs.ExtrudeCurve(a, b) rs.ExtrudeSurface(s, c)
def Volumetria(eixos, dist_e, dist_l, pto): plAux = rs.CopyObject(eixos, -eZ * (dist_l)) plAux2 = rs.CopyObject(eixos, eZ * (dist_l)) pl1 = rs.OffsetCurve(plAux, pto, dist_e, eZ) pl1 = rs.coercegeometry(pl1) pl2 = rs.OffsetCurve(plAux, pto, -dist_e, eZ) pl2 = rs.coercegeometry(pl2) pl3 = rs.AddLine(rs.CurveStartPoint(pl1), rs.CurveStartPoint(pl2)) pl4 = rs.AddLine(rs.CurveEndPoint(pl1), rs.CurveEndPoint(pl2)) eixos3D = rs.AddPlanarSrf((pl1, pl3, pl2, pl4)) lin = rs.AddLine(rs.CurveStartPoint(plAux), rs.CurveStartPoint(plAux2)) eixos3D = rs.ExtrudeSurface(eixos3D, lin, True) eixos3D = rs.coercegeometry(eixos3D) return eixos3D
def add_cube_w_material(count): for i in xrange(count): for j in xrange(count): ### define pt, plane tmp_pt = rs.AddPoint(i * 2, j * 2, 0) tmp_pln = rs.PlaneFromPoints(tmp_pt, rs.PointAdd(tmp_pt, (1,0,0)), rs.PointAdd(tmp_pt, (0,1,0))) ### define extrude line line_ex = rs.AddLine((0,0,0), (0,0,1)) ### draw rect tmp_crv = rs.AddRectangle(tmp_pln, 1,1) tmp_surf = rs.AddPlanarSrf(tmp_crv) tmp_box = rs.ExtrudeSurface(tmp_surf, line_ex, True) ### set color rs.AddMaterialToObject(tmp_box) index = rs.ObjectMaterialIndex(tmp_box) rs.MaterialName(index, str(i) + "_" +str(j)) rs.MaterialColor(index, ((255 / count) * i, 255 - ((255 / count) * j), 255 - ((255 / count) * j))) # name = rs.MaterialName(index) # print name ### delete rs.DeleteObject(tmp_pt) rs.DeleteObject(tmp_crv) rs.DeleteObject(tmp_surf) rs.DeleteObject(line_ex)
def get_building_booleans(building_breps, planes): """make slices of the building that will be booleaneddifferenced out of the terrain slices.""" if not building_breps: return None bldg_intersection_boolean_breps = [] bldg_intersection_breps = [] sections = [] #get the sections organized by level for i, plane in enumerate(planes): sections_level = [] for b in building_breps: plane_sections = get_section(rs.coercebrep(b), plane) if not plane_sections: continue else: sections_level.append(plane_sections) sections.append(sections_level) #extrude the sections organized by level boolean_breps = [] for i, level in enumerate(sections): boolean_breps_level = [] for section in level: pb = Rhino.Geometry.Brep.CreatePlanarBreps(section) pb = pb[0] srf_added = wrh.add_brep_to_layer(pb, LCUT_IND[4]) b = rs.ExtrudeSurface(srf_added, SHORT_GUIDE) centroid, _ = rs.SurfaceAreaCentroid(b) b = rs.ScaleObject(b, centroid, [1.0, 1.0, 1.5]) #rs.ObjectLayer(b,"s7") boolean_breps_level.append(b) rs.DeleteObject(srf_added) boolean_breps.append(boolean_breps_level) return boolean_breps
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
def makeWall(crvs, width): rs.EnableRedraw(False) breps = [] shapes = [] for crv in crvs: rs.SimplifyCurve(crv) shape = offsetBothCrvs(crv, width) if rs.IsPolysurface(shape): surfs = rs.ExplodePolysurfaces(shape) for surf in surfs: shapes.append(surf) if shape: rs.DeleteObjects(shape) else: shapes.append(shape) for shape in shapes: railCurve = addRail(shape) breps.append(rs.ExtrudeSurface(shape, railCurve)) if railCurve: rs.DeleteObjects(railCurve) if shapes: rs.DeleteObjects(shapes) rs.EnableRedraw(False) return breps
def cube(x, y, z): line1 = rs.AddLine((x, y, z), (x, y + 5, z)) line2 = rs.AddLine((x, y, z), (x + 5, y, z)) surface = rs.ExtrudeCurve(line1, line2) line3 = rs.AddLine((x, y, 0), (x, y, 5)) rs.ExtrudeSurface(surface, line3)
if new_object: if y_split[0] == 'v': vertex.append([float(y_split[1]), float(y_split[2]), 0]) else: counter += 1 if counter == 1: new_object = False vertex.append(vertex[0]) pts_ids = rs.AddPoints(vertex) rs.ObjectColor(pts_ids, [255, 0, 0]) curve_ids = rs.AddPolyline(vertex) surf_ids = rs.AddPlanarSrf(curve_ids) # This height value can be further edited to reduce complexity # A simple way to edit this would be to floor the value to reduce the step sizes possible. height = float(y_split[1]) if height > 0: extrusion_pt = [vertex[0][0], vertex[0][1], height] extrusion_curve = rs.AddLine(vertex[0], extrusion_pt) vol_ids = rs.ExtrudeSurface(surf_ids, extrusion_curve) if 'object' in L1stripped: new_object = True vertex = [] counter = 0 vertices_file.close()
def main(): global inner_curves, outer_curves, curve_coords # save for later orig_hidden_objects = rs.HiddenObjects() # we put reference points in the dogbone-ref layer, so create it if it doesn't exist rs.AddLayer("dogbone-ref") panel, face = getsubsurface.GetSubSurface("select dogbone face") diameter = rs.GetReal("enter cutter diameter", number=0.25) diameter = diameter * 1.1 rs.EnableRedraw(False) # compute the plane normal = rs.VectorUnitize(rs.SurfaceNormal(face, (0.5, 0.5))) plane = rs.PlaneFromNormal(rs.EvaluateSurface(face, 0.5, 0.5), normal) rs.ViewCPlane(plane=plane) rs.ProjectOsnaps(True) outer_curves = rs.DuplicateSurfaceBorder(face, 1) inner_curves = rs.DuplicateSurfaceBorder(face, 2) # make a dict mapping each curve to the coords in that curve curve_coords = dict() for curve in outer_curves + inner_curves: coords = rs.CurvePoints(curve)[:-1] curve_coords[curve] = coords # make a dict mapping each curve to the z component of its cross product at each index curve_cross_zs = dict() for curve, coords in curve_coords.items(): proj_coords = [rs.SurfaceClosestPoint(face, coord) for coord in coords] cross_zs = [] for idx in range(len(proj_coords)): triplet = [ proj_coords[(idx + 1) % len(proj_coords)], proj_coords[idx], proj_coords[(idx - 1) % len(proj_coords)] ] v0 = (triplet[1][0] - triplet[0][0], triplet[1][1] - triplet[0][1], 0) v1 = (triplet[2][0] - triplet[1][0], triplet[2][1] - triplet[1][1], 0) cross_z = rs.VectorCrossProduct(v0, v1)[2] cross_zs.append(cross_z) curve_cross_zs[curve] = cross_zs points = [] bones = [] temp_points = [] rs.EnableRedraw(True) while True: coord = rs.GetPoint("select corner") if coord is None: break try: curve, idx = get_curve_and_idx_for_coord(coord) point = rs.AddPoint(coord) rs.ObjectColor(point, (255, 0, 0)) temp_points.append(point) bones.append((curve, idx)) except ValueError: print "invalid curve point" continue rs.EnableRedraw(False) rs.DeleteObjects(temp_points) # try to automatically identify dogbone points if user selected none if len(bones) == 0: for curve, coords in curve_coords.items(): proj_coords = [ rs.SurfaceClosestPoint(face, coord) for coord in coords ] for idx in range(len(proj_coords)): triplet = [ proj_coords[(idx + 1) % len(proj_coords)], proj_coords[idx], proj_coords[(idx - 1) % len(proj_coords)] ] if curve_cross_zs[curve][idx] > 0: bones.append((curve, idx)) # make the bones extrusions = [] for bone in bones: curve, idx = bone coords = curve_coords[curve] point = rs.AddPoint(coords[idx]) rs.ObjectLayer(point, "dogbone-ref") triplet = [ coords[(idx + 1) % len(coords)], coords[idx], coords[(idx - 1) % len(coords)], ] angle = rs.Angle2( (triplet[1], triplet[0]), (triplet[1], triplet[2]), ) angle = angle[0] # This is a hacky method to determine the handedness of the curve # the cross product SHOULD have worked here, but for some reason # it did not. v0 = triplet[2][0] - triplet[1][0], triplet[2][1] - triplet[1][1], 0 v1 = triplet[1][0] - triplet[0][0], triplet[1][1] - triplet[0][1], 0 _angle = math.degrees( math.atan2(v0[1], v0[0]) - math.atan2(v1[1], v1[0])) while _angle > 180: _angle -= 360 while _angle < -180: _angle += 360 if math.copysign(1, angle) != math.copysign(1, _angle): angle -= 180 point = rs.VectorAdd( triplet[1], rs.VectorRotate( 0.5 * diameter * rs.VectorUnitize(rs.VectorSubtract(triplet[2], triplet[1])), angle / 2, (0, 0, 1))) circle = rs.AddCircle((point.X, point.Y, -10), diameter / 2.0) circle_srf = rs.AddPlanarSrf(circle) p0 = (point.X, point.Y, -10) p1 = (point.X, point.Y, 10) line = rs.AddLine(p0, p1) extrusion = rs.ExtrudeSurface(circle_srf, line) extrusions.append(extrusion) rs.DeleteObjects([circle, circle_srf, line]) rs.BooleanDifference([panel], extrusions, delete_input=True) rs.DeleteObject(panel) rs.DeleteObjects(extrusions) rs.DeleteObjects(points) rs.DeleteObjects(inner_curves) rs.DeleteObjects(outer_curves) rs.DeleteObject(face) rs.ShowObject(rs.AllObjects()) rs.HideObjects(orig_hidden_objects) rs.EnableRedraw(True)
def make_fingers(positive, negative, subdivisions): """ intersect two collections of planes subdivide the intersections assign each subdivision to a guid from which it will be subtracted """ # this vector is used to indicate axis of the intersection. # it needs to be parallel to the intersection # (there are other ways of doing this!) p0 = rs.GetPoint("select start of intersection") p1 = rs.GetPoint("select end of intersection") edge = rs.AddLine(p0, p1) vector = rs.VectorCreate(p0, p1) rs.EnableRedraw(False) # this dict maps a pair of planes (ps, ns) to their booleanintersection intersections = {} for ps in positive: for ns in negative: intersection = rs.BooleanIntersection(ps, ns, False) if intersection is not None: intersections[(ps, ns)] = intersection # here we construct some very large cylinders aligned with the axis you drew origins = [] cylinders = [] for i in range(subdivisions+1): origin = rs.EvaluateCurve(edge, rs.CurveParameter(edge, i * 1.0/(subdivisions))) origins.append(origin) rs.DeleteObject(edge) for i in range(subdivisions): plane = rs.PlaneFromNormal(origins[i], vector) circle = rs.AddCircle(plane, 100) planar_circle = rs.AddPlanarSrf(circle) extrusion_curve = rs.AddLine(origins[i], origins[i+1]) cylinders.append(rs.ExtrudeSurface(planar_circle, extrusion_curve)) rs.DeleteObject(circle) rs.DeleteObject(planar_circle) rs.DeleteObject(extrusion_curve) # we perform a boolean intersection between each intersection and # the cylinders to construct the fingers for key, intersection in intersections.items(): ps, ns = key for i, cylinder in enumerate(cylinders): print "intersection", intersection print "cylinder", cylinder objs = [brep for brep in rs.BooleanIntersection(intersection, cylinder, False) if rs.IsBrep(brep)] # assign the resulting fingers to either the positive or negative if i % 2 == 0: guid_to_difference[ps].extend(objs) else: guid_to_difference[ns].extend(objs) DeleteItemOrList(cylinders) DeleteItemOrList(intersections.values()) rs.EnableRedraw(True)
import rhinoscriptsyntax as rs sourceObjects = rs.GetObjects(message="Select Surfaces to Extrude", filter=8, preselect=True, select=False) height = rs.GetReal(message="Input Extrusion Height", number=10) guide = rs.AddLine((0, 0, 0), (0, 0, height)) for obj in sourceObjects: objlayer = rs.ObjectLayer(obj) extruded = rs.ExtrudeSurface(obj, guide) rs.ObjectLayer(extruded, layer=objlayer) rs.DeleteObject(guide)
def MultiNestedBoundaryTrimCurves(): msg="Select closed boundary curves for trimming" TCrvs = rs.GetObjects(msg, 4, preselect=False) if not TCrvs: return cCrvs=[crv for crv in TCrvs if rs.IsCurveClosed(crv)] if len(cCrvs)==0: print "No closed trim curves found" return rs.LockObjects(cCrvs) origCrvs = rs.GetObjects("Select curves to trim", 4) rs.UnlockObjects(cCrvs) if not origCrvs : return #plane which is active when trim curve is chosen refPlane = rs.ViewCPlane() if sc.sticky.has_key("TrimSideChoice"): oldTSChoice = sc.sticky["TrimSideChoice"] else: oldTSChoice=True choice = [["Trim", "Outside", "Inside"]] res = rs.GetBoolean("Side to trim away?", choice, [oldTSChoice]) if not res: return trimIns = res[0] #False=Outside tol=sc.doc.ModelAbsoluteTolerance bb=rs.BoundingBox(origCrvs,refPlane) #CPlane box, world coords if not bb: return zVec=refPlane.ZAxis rs.EnableRedraw(False) botPlane=Rhino.Geometry.Plane(bb[0]-zVec,zVec) #check xform=rs.XformPlanarProjection(botPlane) cutCrvs=rs.TransformObjects(cCrvs,xform,True) ccc=CheckPlanarCurvesForCollision(cutCrvs) if ccc: msg="Boundary curves overlap, results may be unpredictable, continue?" res=rs.MessageBox(msg,1+32) if res!= 1: return bSrfs=rs.AddPlanarSrf(cutCrvs) rs.DeleteObjects(cutCrvs) if bSrfs == None: return line=rs.AddLine(bb[0]-zVec,bb[4]+zVec) vols=[] for srf in bSrfs: ext=rs.ExtrudeSurface(srf,line,True) if ext != None: vols.append(ext) rs.DeleteObjects(bSrfs) rs.DeleteObject(line) if len(vols)==0: return exGroup=rs.AddGroup() rs.AddObjectsToGroup(vols,exGroup) rs.Prompt("Splitting curves...") rs.SelectObjects(origCrvs) rs.Command("_Split _-SelGroup " + exGroup + " _Enter", False) splitRes=rs.LastCreatedObjects() rs.DeleteGroup(exGroup) rs.Prompt("Classifying trims...") noSplit=[] for crv in origCrvs: #add curve to list if it has not been split (still exists in doc) id=sc.doc.Objects.Find(crv) if id != None: noSplit.append(crv) errors=0 if splitRes: if len(noSplit)>0: splitRes.extend(noSplit) for crv in splitRes: inside=MultiTestInOrOut(crv,vols) if inside != None: if (inside and trimIns) or (not inside and not trimIns): rs.DeleteObject(crv) else: errors+=1 rs.DeleteObjects(vols) if errors>0: print "Problems with {} curves".format(errors) sc.sticky["TrimSideChoice"] = trimIns