def get_lowest_curve_info(brep, h_tol): #right now hardcoded to not deal with multiple breps at the final step. to revise if needed. bdims = wge.get_bounding_dims(brep) brep_faces = wge.get_extreme_srf(brep, h_tol, False) crvs_by_brep = [] for f in brep_faces: crvs = [] inds = f.AdjacentEdges() for i in inds: k = brep.Edges crvs.append(brep.Edges[i]) crvs = Rhino.Geometry.Curve.JoinCurves(crvs, D_TOL) crvs_by_brep.append(crvs) crvs_by_brep = crvs_by_brep[ 0] #to fix this later. only deals w one brep for now list_curves = [] for pc in crvs_by_brep: if pc.GetType() != Rhino.Geometry.PolyCurve: pc = wru.polylinecurve_to_polycurve(pc) wge.make_pcurve_ccw(pc) list_curves.append(pc) return [list_curves, bdims]
def process_floor(in_objects, floor_outline, outline_cut_height=None): """function used to process an individual floor. input: in_objects: the internal curves and breps selected for this floor floor_outline: the outline brep for the envelope outline_cut_height: height to cut at. output: (crv,[crv]) crv: the offset boundary curve for the floor [crv]: the internal curves for the floor pt: lower-left reference point bdims = bounding dims of this floor """ #classify the inputs in_crvs, in_breps = brep_or_crv(in_objects) #get list of crvs to project brep_sections = [] for b in in_breps: cut_height = wge.get_brep_height(b) / 2 pcurves = wge.get_brep_plan_cut(rs.coercebrep(b), cut_height, D_TOL) brep_sections.extend(pcurves) b_section_guids = wru.add_curves_to_layer(brep_sections, LCUT_INDICES[0]) in_crvs.extend(b_section_guids) #get the outline brep curve if not outline_cut_height: outline_cut_height = wge.get_brep_height(floor_outline) floor_outline_crvs = wge.get_brep_plan_cut(rs.coercebrep(floor_outline), outline_cut_height, D_TOL) floor_outline_crvs = wru.add_curves_to_layer(floor_outline_crvs, LCUT_INDICES[1]) #get bounding info for the floor outline bb = rs.BoundingBox(floor_outline) corner = bb[0] bdims = wge.get_bounding_dims(floor_outline) proj_srf = rs.AddSrfPt([bb[0], bb[1], bb[2], bb[3]]) internal_crvs = rs.ProjectCurveToSurface(in_crvs, proj_srf, [0, 0, -1]) if in_crvs else [] offset_floor_crv = rs.ProjectCurveToSurface(floor_outline_crvs, proj_srf, [0, 0, -1]) #rs.DeleteObjects(in_crvs) rs.DeleteObjects(floor_outline_crvs) rs.DeleteObject(proj_srf) out_floor_crvs = rs.coercecurve(offset_floor_crv) out_internal_crvs = [rs.coercecurve(x) for x in internal_crvs] rs.DeleteObject(offset_floor_crv) rs.DeleteObjects(internal_crvs) rs.DeleteObjects(b_section_guids) #TODO: make sure objects are being deleted return out_floor_crvs, out_internal_crvs, corner, bdims
def get_section_curve_info_multi_no_ortho(brep, plane): """returns the curve outline, the bounding dims, and the plane where the curve was cut""" #set height bdims = wge.get_bounding_dims(brep) g_polycurves = wge.get_brep_plan_cut_use_plane(brep, plane, D_TOL) #g_polycurve = g_polycurves[0] list_curves = [] for pc in g_polycurves: if pc.GetType() != Rhino.Geometry.PolyCurve: pc = wru.polylinecurve_to_polycurve(pc) wge.make_pcurve_ccw(pc) list_curves.append(pc) #plane1 is where the section curve gets built. will be at the midheight. return [list_curves, bdims]
def get_section_curve_info(brep, plane): """returns the curve outline, the bounding dims, and the plane where the curve was cut""" #set height bdims = wge.get_bounding_dims(brep) g_polycurves = wge.get_brep_plan_cut_use_plane(brep, plane, D_TOL) g_polycurve = g_polycurves[0] if g_polycurve.GetType() != Rhino.Geometry.PolyCurve: g_polycurve = wru.polylinecurve_to_polycurve(g_polycurve) wru.make_pcurve_ccw(g_polycurve) if g_polycurve.GetType() == Rhino.Geometry.PolylineCurve: g_polyline = wru.polycurve_to_polyline(g_polycurve, doc.ModelAbsoluteTolerance, doc.ModelAngleToleranceDegrees) else: g_polyline = g_polycurve #plane1 is where the section curve gets built. will be at the midheight. return [g_polyline, bdims]
def rc_plot_volumes(use_epsilon): go = Rhino.Input.Custom.GetObject() go.GeometryFilter = Rhino.DocObjects.ObjectType.Brep default_inplaceBool = sticky["inplaceBool"] if sticky.has_key( "inplaceBool") else False default_heightsBool = sticky["heightsBool"] if sticky.has_key( "heightsBool") else False opt_inplace = Rhino.Input.Custom.OptionToggle(default_inplaceBool, "No", "Yes") opt_heights = Rhino.Input.Custom.OptionToggle(default_heightsBool, "No", "Yes") go.SetCommandPrompt("Select breps to extract plan cuts") go.AddOptionToggle("InPlace", opt_inplace) go.AddOptionToggle("PrintPieceHeights", opt_heights) go.GroupSelect = True go.SubObjectSelect = False go.AcceptEnterWhenDone(True) go.AcceptNothing(True) go.EnableClearObjectsOnEntry(False) go.EnableUnselectObjectsOnExit(False) go.GroupSelect = True go.SubObjectSelect = False go.DeselectAllBeforePostSelect = False res = None bHavePreselectedObjects = False while True: res = go.GetMultiple(1, 0) #If new option entered, redraw a possible result if res == Rhino.Input.GetResult.Option: # print res go.EnablePreSelect(False, True) continue #If not correct elif res != Rhino.Input.GetResult.Object: return Rhino.Commands.Result.Cancel if go.ObjectsWerePreselected: bHavePreselectedObjects = True go.EnablePreSelect(False, True) continue break rs.EnableRedraw(False) DIRPT1 = rs.coerce3dpoint([0, 0, 0]) DIRPT2 = rs.coerce3dpoint([1, 0.001, 0]) global BOOL_HEIGHTS global LCUT_INDICES global SORTDIR BOOL_HEIGHTS = opt_heights.CurrentValue LCUT_INDICES = wla.get_lcut_layers() SORTDIR = DIRPT2 - DIRPT1 #Get boolean for "inplace" INPLACE = opt_inplace.CurrentValue #Get brep representations of objects brep_geo_list = [] for i in xrange(go.ObjectCount): b_obj = go.Object(i).Object() brep_geo_list.append(b_obj.Geometry) #...brep conversion may be necessary new_brep_list = [] for i, geo in enumerate(brep_geo_list): if geo.GetType() != Rhino.Geometry.Brep: new_brep_list.append(wru.extrusion_to_brep(geo)) else: new_brep_list.append(geo) #set base for output. xbase = 0 ybase = 0 #set the amount to move up from the bottom of the brep for cutting the lower outline. #this should be replaced by a projection of the bottom face of the brep. epsilon = D_TOL * 2 select_items = [] centroids = [ c.GetBoundingBox(rs.WorldXYPlane()).Center for c in new_brep_list ] brep_collection = zip(centroids, new_brep_list) brep_collection = sorted(brep_collection, sortcompare) _, new_brep_list = zip(*brep_collection) for i, brep in enumerate(new_brep_list): #get lowest curve info #get label prefix and bounding dims for this brep bdims = wge.get_bounding_dims(brep) baseplane = rs.MovePlane(rs.WorldXYPlane(), [xbase, ybase, 0]) label_letter = wut.number_to_letter(i) #prepare heights and labels for each section cut num_sections = 1 remaining_thickness = 0 cuts_at = [epsilon] if use_epsilon else [0] brep_label = label_letter section_labels = [label_letter] if BOOL_HEIGHTS == True: section_labels = [ label + "\n" + str(round(bdims.Z, 1)) for label in section_labels ] #get section information for each cut section_planes = get_brep_section_planes(brep, cuts_at) section_curves, section_dims = [[], []] for i, plane in enumerate(section_planes): curve, dims = [0, 0] if (not use_epsilon) and (i == 0): curve, dims = get_lowest_curve_info(brep, D_TOL * 2) else: curve, dims = get_section_curve_info_multi_no_ortho( brep, plane) section_curves.append(curve) section_dims.append(dims) ##DO WORK HERE## drawing_planes = get_drawing_planes(section_dims, baseplane, GAP_SIZE) #place curves in drawing location for sp, dp, sc in zip(section_planes, drawing_planes, section_curves): if INPLACE == True: t = Rhino.Geometry.Transform.Translation(0, 0, 0) else: t = Rhino.Geometry.Transform.ChangeBasis(dp, sp) for c in sc: c.Transform(t) #THIS IS STILL A MESS: LABEL ADDING #draw curves and add text dots top_label_pt = get_brep_label_pt(brep) brep_textdot = rs.AddTextDot(brep_label, top_label_pt) rs.ObjectLayer(brep_textdot, "XXX_LCUT_00-GUIDES") label_pts = [] for sc, label in zip(section_curves, section_labels): for i, c in enumerate(sc): crv = wru.add_curve_to_layer(c, LCUT_INDICES[1]) select_items.append(crv) if i == 0: label_pts.append(rs.CurveAreaCentroid(crv)[0]) fab_tags = wfa.add_fab_tags(label_pts, section_labels, TEXTSIZE) for tag in fab_tags: rs.ObjectLayer(tag, "XXX_LCUT_02-SCORE") group_name = rs.AddGroup() rs.AddObjectsToGroup(tag, group_name) ybase += max([s.Y for s in section_dims]) + GAP_SIZE * 1 for tag in fab_tags: select_items.extend(tag) sticky["inplaceBool"] = INPLACE sticky["heightsBool"] = BOOL_HEIGHTS rs.UnselectAllObjects() rs.SelectObjects(select_items) rs.Redraw() rs.EnableRedraw(True)
def rc_plot_volumes(use_epsilon): #get sticky default_thickness = sticky["defaultThickness"] if sticky.has_key( "defaultThickness") else 5.5 go = Rhino.Input.Custom.GetObject() go.GeometryFilter = Rhino.DocObjects.ObjectType.Brep opt_thickness = Rhino.Input.Custom.OptionDouble(default_thickness, 0.2, 1000) opt_sections = Rhino.Input.Custom.OptionToggle(False, "No", "Yes") opt_inplace = Rhino.Input.Custom.OptionToggle(False, "No", "Yes") opt_heights = Rhino.Input.Custom.OptionToggle(False, "No", "Yes") go.SetCommandPrompt("Select breps to extract plan cuts") go.AddOptionDouble("Thickness", opt_thickness) go.GroupSelect = True go.SubObjectSelect = False go.AcceptEnterWhenDone(True) go.AcceptNothing(True) go.EnableClearObjectsOnEntry(False) go.EnableUnselectObjectsOnExit(False) go.GroupSelect = True go.SubObjectSelect = False go.DeselectAllBeforePostSelect = False res = None bHavePreselectedObjects = False while True: res = go.GetMultiple(1, 0) #If new option entered, redraw a possible result if res == Rhino.Input.GetResult.Option: # print res go.EnablePreSelect(False, True) continue #If not correct elif res != Rhino.Input.GetResult.Object: return Rhino.Commands.Result.Cancel if go.ObjectsWerePreselected: bHavePreselectedObjects = True go.EnablePreSelect(False, True) continue break rs.EnableRedraw(False) global THICKNESS THICKNESS = opt_thickness.CurrentValue global LCUT_INDICES LCUT_INDICES = wla.get_lcut_layers() #Get brep representations of objects brep_geo_list = [] for i in xrange(go.ObjectCount): b_obj = go.Object(i).Object() brep_geo_list.append(b_obj.Geometry) #...brep conversion may be necessary new_brep_list = [] for i, geo in enumerate(brep_geo_list): if geo.GetType() != Rhino.Geometry.Brep: new_brep_list.append(wru.extrusion_to_brep(geo)) else: new_brep_list.append(geo) #set base for output. xbase = 0 ybase = 0 #set the amount to move up from the bottom of the brep for cutting the lower outline. #this should be replaced by a projection of the bottom face of the brep. epsilon = D_TOL * 2 select_items = [] for i, brep in enumerate(new_brep_list): #get label prefix and bounding dims for this brep bdims = wge.get_bounding_dims(brep) baseplane = rs.MovePlane(rs.WorldXYPlane(), [xbase, ybase, 0]) label_letter = wut.number_to_letter(i) label_prefix = label_letter + "-" #prepare heights and labels for each section cut num_sections = 1 remaining_thickness = 0 cuts_at = [epsilon] if use_epsilon else [0] brep_label = label_letter section_labels = [label_letter] num_sections, remaining_thickness, cuts_at = get_section_division( bdims.Z, THICKNESS) if use_epsilon: cuts_at[0] = epsilon brep_label = label_letter + " r: " + str(round(remaining_thickness, 2)) section_labels = [label_prefix + str(i) for i in xrange(len(cuts_at))] #get section information for each cut section_planes = get_brep_section_planes(brep, cuts_at) #get lowest curve info section_curves, section_dims = [[], []] for i, plane in enumerate(section_planes): curve, dims = [0, 0] if (not use_epsilon) and (i == 0): curve, dims = get_lowest_curve_info(brep, D_TOL * 2) else: curve, dims = get_section_curve_info_multi_no_ortho( brep, plane) section_curves.append(curve) section_dims.append(dims) ##DO WORK HERE## drawing_planes = get_drawing_planes(section_dims, baseplane, GAP_SIZE) #place curves in drawing location for sp, dp, sc in zip(section_planes, drawing_planes, section_curves): t = Rhino.Geometry.Transform.ChangeBasis(dp, sp) for c in sc: c.Transform(t) #THIS IS STILL A MESS: LABEL ADDING #draw curves and add text dots top_label_pt = get_brep_label_pt(brep) brep_textdot = rs.AddTextDot(brep_label, top_label_pt) rs.ObjectLayer(brep_textdot, "XXX_LCUT_00-GUIDES") label_pts = [] for sc, label in zip(section_curves, section_labels): temp_area = 0 for i, c in enumerate(sc): crv = wru.add_curve_to_layer(c, LCUT_INDICES[1]) select_items.append(crv) if i == 0: label_pts.append(rs.CurveAreaCentroid(crv)[0]) temp_area = rs.CurveArea(crv) else: if rs.CurveArea(crv) > temp_area: label_pts[-1] = rs.CurveAreaCentroid(crv)[0] temp_area = rs.CurveArea(crv) fab_tags = wfa.add_fab_tags(label_pts, section_labels, TEXTSIZE) for tag in fab_tags: rs.ObjectLayer(tag, "XXX_LCUT_02-SCORE") group_name = rs.AddGroup() rs.AddObjectsToGroup(tag, group_name) ybase += max([s.Y for s in section_dims]) + GAP_SIZE * 1 for tag in fab_tags: select_items.extend(tag) #THIS IS STILL A MESS: LABEL ADDING sticky["defaultThickness"] = THICKNESS rs.UnselectAllObjects() rs.SelectObjects(select_items) rs.Redraw() rs.EnableRedraw(True)