def new_settings_button(self,sender,e,edit=False): while True: name = rs.StringBox (message=TXT["name"], default_value=None, title=TXT["nueva"]) if name != "" and name not in self.machining_settings: break if name: machining_settings = {name:{}} for compensation in [key for key in INPUT_VALUES]: machining_settings[name][compensation] = {} if self.user_data["selected_preset"]: list_settings = rs.PropertyListBox([i for i in INPUT_VALUES[compensation]],[str(self.machining_settings[self.user_data["selected_preset"]][compensation][i]) for i in VARIABLE_NAMES[compensation]],compensation, "Configuracion de corte") else: list_settings = rs.PropertyListBox([i for i in INPUT_VALUES[compensation]],[0 for i in INPUT_VALUES[compensation]],compensation, "Configuracion de corte") if list_settings: for i in range(0,len(list_settings)): machining_settings[name][compensation][VARIABLE_NAMES[compensation][i]] = self.validate_data(list_settings[i], VARIABLE_NAMES[compensation][i]) else: return persistant = rs.MessageBox(TXT["save_pers"], 4 | 256 | 64,TXT["database"]) if persistant == 6: machining_settings[name]["persistant"] = False else: machining_settings[name]["persistant"] = True self.user_data["selected_preset"] = name w = self.form.panel.Controls.Find("preset", True)[0] w.Text = name self.machining_settings.update(machining_settings)
def setFloorLevels(numFloors): """ sets the floor levels in document data input: int: the number of floors returns: None """ levelName = [] levels = [] for i in range(0, numFloors): levelName.append("L" + str(i + 1)) levelName.append("Roof") #if existing data, get for i in range(0, numFloors): if (rs.GetDocumentData("Levels", levelName[i]) is not None): levels.append(rs.GetDocumentData("Levels", levelName[i])) else: levels.append(None) if (rs.GetDocumentData("Levels", levelName[-1]) is not None): levels.append(rs.GetDocumentData("Levels", levelName[-1])) else: levels.append(None) #rs.DeleteDocumentData("Levels") newLevels = [] newLevels = rs.PropertyListBox(levelName, levels, "LEVELS", "Update the Levels below") if newLevels is None: return for i in range(0, numFloors + 1): rs.SetDocumentData("Levels", levelName[i], str(newLevels[i])) return None
def modify_add_settings(self): keys = self.settings['add'].keys() values = self.settings['add'].values() new_values = rs.PropertyListBox(keys, values, message='suggested addition rules', title='exploration settings') self.settings['add'].update( {key: float(value) for key, value in zip(keys, new_values)})
def settings_menu(pattern): settings = pattern.settings new_values = rs.PropertyListBox(settings.keys(), settings.values(), 'modify setting(s)?', 'Settings') pattern.settings = { setting: float(value) for setting, value in zip(settings.keys(), new_values) }
def UserDataInput(): obj = rs.GetObject("Select Object") Keylist = rs.GetUserText(obj, ) UserDataList = [] for n in Keylist: b = rs.GetUserText(obj, n) UserDataList.append(b) newlist = [] newlist = rs.PropertyListBox(Keylist, UserDataList, "User Data", "User Data Key List") if newlist: for c in range(len(Keylist)): rs.SetUserText(obj, Keylist[c], newlist[c])
def SurfaceTensorField(): #Prompt the user for all required data srf_id = rs.GetObject("Surface for tensor curvature field", 8, True, True) if not srf_id: return u = 100 v = 100 s = 10 pListBoxResult = rs.PropertyListBox( ("U-samples", "V-samples", "Smoothing iterations"), \ (u, v, S), "Algorithm settings", "Tensor field") if not pListBoxResult: return #Convert all strings in the PopertyListBox result into numbers again u = int(pListBoxResult[0]) v = int(pListBoxResult[1]) s = int(pListBoxResult[2]) #Make sure the values are within logical limits if u<1 or v<1 or s<0: return #At this point we have all input data collected. #We also know all values are correct #Initiate the Tensor Space T, K = SurfaceTensorField(srf_id, u, v) if not T or not K: print "Unable to construct basis Tensor field" return #Smooth the Tensor Space s times for i in range(s): rs.Prompt("Smoothing tensor field. Iteration: %d" % i) T, K = SmoothTensorField(T, K) #Add all Tensors as line segments Call Rhino.EnableRedraw(False) Dim A, B For i = 0 To u For j = 0 To v A = T(i,j)(0) B = Rhino.PointAdd(A, K(i,j)) Call Rhino.AddLine(A, B) Next
def main(): items = [ "Project Name", "Project Number", "Project Location", "Plot Ratio", "Min Green Coverage", "Max Site Coverage", "CAD coordinate (X,Y,Z)" ] values = [] if rs.GetDocumentData("Project Info", items[0]) is not None: for i in range(0, len(items)): values.append(rs.GetDocumentData("Project Info", items[i])) else: values = [None, None] values = rs.PropertyListBox(items, values, "Project Info", "Project Info") #if rs.ObjectsByLayer("SITE::BNDY") is not None: # siteArea = rs.Area(rs.ObjectsByLayer("SITE::BNDY")) #else: # siteArea = "No Site Boundary Layer" for i in range(0, len(items)): rs.SetDocumentData("Project Info", items[i], values[i]) rs.Command("_Show ")
def setup(): cfg = {} cfg['do_capture_fill'] = True delete_residual_display_modes() ## properties dialog # props = [("view_count", DEFAULT_VIEW_COUNT), ("image_size", 512), ("zoom_padding_percent", "-10,10,75"), ("iso (NE, NW, SE, or SW)", "SE"), ("do_scale_1d", "y"), ("do_scale_2d", "y"), ("do_shear", "n"), ("render_or_capture", "capture"), ("worms_eye?", "n")] prop_box_results = False if DEBUG: prop_box_results = [p[1] for p in props] if not prop_box_results: itms, vals = [p[0] for p in props], [p[1] for p in props] prop_box_results = rs.PropertyListBox( itms, vals, "Please set the following properties.", "Rhino Batch Render") if prop_box_results is None: exit() try: cfg['view_count'] = int(prop_box_results[0]) cfg['size'] = int(prop_box_results[1]) cfg['obj_bbox_pads'] = [ int(s) * 0.01 for s in prop_box_results[2].split(',') ] cfg['iso_select'] = str(prop_box_results[3]).lower() cfg["do_scale_1d"] = str(prop_box_results[4]).lower() in ("y", "yes", "true", "t", "1") cfg["do_scale_2d"] = str(prop_box_results[5]).lower() in ("y", "yes", "true", "t", "1") cfg["do_shear"] = str(prop_box_results[6]).lower() in ("y", "yes", "true", "t", "1") cfg["do_render_via_view_cap"] = str( prop_box_results[7]).lower().startswith("c") cfg["do_worms_eye"] = str(prop_box_results[8]).lower() in ("y", "yes", "true", "t", "1") except Exception as e: big_problem( "There was a problem parsing the values given in the properties dialog.\n{}" .format(e)) ## groups to draw # setup_groups(cfg) ## layers # setup_layers(cfg) ## xforms # fake_xf = xforms_to_apply(cfg['groups_info'][0]['bbox'], cfg, DEBUG) cfg['xform_count'] = len(fake_xf) ## root path # pth_root = False if DEBUG: pth_root = DEFAULT_SAVE_PATH if not pth_root: pth_root = rs.BrowseForFolder(message="where should we save this?", title="Where to Save?") dir_cfg = initialize_directory(pth_root, cfg['do_capture_fill']) cfg.update(dir_cfg) ## view # cam_height = 0.75 if cfg["do_worms_eye"]: cam_height *= -1 poss = { "ne": (1, 1, cam_height), "nw": (-1, 1, cam_height), "se": (1, -1, cam_height), "sw": (-1, -1, cam_height) } if cfg["iso_select"] not in poss: big_problem( "There was a problem with the selected isometric view.\n'{}' is not a valid selection." .format(cfg["iso_select"])) cfg["iso_cam_pos"] = poss[cfg["iso_select"]] ## tidy up and save settings JSON # cfg['total_image_count'] = cfg['view_count'] * len( cfg['obj_bbox_pads']) * cfg['xform_count'] * len(cfg['groups_info']) with open(os.path.join(cfg['pth_save'], 'settings.json'), 'w') as json_file: json.dump( { k: "{}".format(str(v)) for k, v in cfg.items() if k != "groups_info" }, json_file, sort_keys=True, indent=4) ## SETUP RHINO # rs.UnselectAllObjects() setup_display_modes(cfg) setup_floating_viewport(cfg) setup_render_settings(cfg) # padding objects wbbox = False for gp in cfg['groups_info']: if not wbbox: wbbox = gp['bbox'] else: wbbox.Union(gp['bbox']) wbbox = pad_bbox(wbbox, 10) cfg['pad_obj_ids'] = [] cfg['pad_obj_ids'].append(rs.AddPoint(wbbox.Min)) cfg['pad_obj_ids'].append(rs.AddPoint(wbbox.Max)) return cfg
from compas_pattern.cad.rhino.objects.surface import RhinoSurface from compas_pattern.algorithms.decomposition.algorithm import surface_decomposition from compas_pattern.algorithms.decomposition.algorithm import decomposition_mesh from compas_pattern.datastructures.mesh.constraints import automated_smoothing_constraints from compas_pattern.datastructures.mesh.constraints import automated_smoothing_surface_constraints from compas_pattern.datastructures.mesh.relaxation import constrained_smoothing from compas_rhino.artists import MeshArtist srf_guid = rs.GetObject('get surface', filter=8) #crv_guids = rs.GetObjects('get curves', filter=4) or [] crv_guids = [] pt_guids = rs.GetObjects('get points', filter=1) or [] poles = [rs.PointCoordinates(pt) for pt in pt_guids] settings = rs.PropertyListBox([ 'triangulation_precision', 'density_target', 'smoothing_iterations', 'damping_value' ], [1, 3.0, 30, 0.5], 'settings for mesh on surface') triangulation_precision, density_target, kmax, damping = settings # topology print 'decomposition...' decomposition, outer_boundary, inner_boundaries, polyline_features, point_features = surface_decomposition( srf_guid, float(triangulation_precision), crv_guids=crv_guids, pt_guids=pt_guids) coarse_quad_mesh = decomposition_mesh(srf_guid, decomposition, point_features) # density print 'densification...' coarse_quad_mesh.collect_strips()
import rhinoscriptsyntax as rs objs = rs.GetObjects("Select Objects") if objs: names = [] for obj in objs: name = rs.ObjectName(obj) if name is None: name = "" names.append(name) results = rs.PropertyListBox(objs, names, "Modify object name(s)") if results: rs.ObjectName(objs[i], results[i])
def editing_primal_dual(primal, default_settings, curve_constraints, point_constraints): dx = default_settings['dx'] dy = default_settings['dy'] density = default_settings['density'] pattern = default_settings['pattern'] smoothing_iterations = default_settings['smoothing iterations'] smoothing_damping = default_settings['smoothing damping'] # grammar rules + propagation scheme rules = [ 'settings', 'face_opening', 'flat_corner_2', 'flat_corner_3', 'flat_corner_33', 'split_35', 'split_35_diag', 'split_26', 'simple_split', 'double_split', 'singular_boundary_1', 'singular_boundary_2', 'clear_faces', 'move_vertices', 'stop' ] primal_guid = draw_mesh(primal) dense_primal = densification(primal, 1, custom=False) # smooth rs.EnableRedraw(False) constraints = {} for pt in point_constraints: vertex = None min_dist = -1 for vkey in dense_primal.vertices_on_boundary(): dist = distance_point_point(rs.PointCoordinates(pt), dense_primal.vertex_coordinates(vkey)) if min_dist < 0 or min_dist > dist: vertex = vkey min_dist = dist constraints[vertex] = ('point', rs.PointCoordinates(pt)) for vkey in dense_primal.vertices_on_boundary(): if vkey not in constraints: curve = None min_dist = -1 for crv in curve_constraints: vkey_guid = rs.AddPoint(dense_primal.vertex_coordinates(vkey)) t = rs.CurveClosestPoint(crv, vkey_guid) pt = rs.EvaluateCurve(crv, t) dist = distance_point_point( pt, dense_primal.vertex_coordinates(vkey)) rs.DeleteObject(vkey_guid) if min_dist < 0 or min_dist > dist: curve = crv min_dist = dist constraints[vkey] = ('curve', curve) rs.EnableRedraw(True) mesh_smooth_area(dense_primal, kmax=smoothing_iterations, damping=smoothing_damping, callback=apply_constraints, callback_args=[dense_primal, constraints]) dense_primal_guid = draw_mesh(dense_primal) rs.MoveObject(dense_primal_guid, [dx, 0, 0]) dense_dual = mesh_dual(dense_primal, Mesh) rotate_mesh(dense_dual, pi / 2) rs.EnableRedraw(False) dense_dual_guid = draw_mesh(dense_dual) rs.MoveObject(dense_dual_guid, [2 * dx, 0, 0]) rs.EnableRedraw(True) # start editing count = 1000 while count > 0: count -= 1 primal.update_default_edge_attributes() #ask for rule rule = rs.GetString('rule?', strings=rules) # exit if rule == 'stop': break elif rule == 'settings': density, pattern, dx, dy, smoothing_iterations, smoothing_damping = rs.PropertyListBox( [ 'density', 'pattern', 'dx', 'dy', 'smoothing iterations', 'smoothing damping' ], [ density, pattern, dx, dy, smoothing_iterations, smoothing_damping ], title='settings') density = float(density) dx = float(dx) dy = float(dy) smoothing_iterations = int(smoothing_iterations) smoothing_damping = float(smoothing_damping) # apply editing rule elif rule in rules: regular_vertices = list(primal.vertices()) apply_rule(primal, rule) #if rule != 'clear_faces': mesh_propagation(primal, regular_vertices) rs.DeleteObjects(primal_guid) rs.DeleteObjects(dense_primal_guid) rs.DeleteObjects(dense_dual_guid) primal_guid = draw_mesh(primal) for fkey in primal.faces(): if len(primal.face_vertices(fkey)) != 4: rs.AddPoint(primal.face_centroid(fkey)) dense_primal = densification(primal, density, custom=False) dense_primal = dense_primal.to_mesh() dense_primal = patterning(dense_primal, pattern) to_del = [ vkey for vkey in dense_primal.vertices() if len(dense_primal.vertex_neighbours(vkey)) == 0 ] for vkey in to_del: del dense_primal.vertex[vkey] # smooth rs.EnableRedraw(False) constraints = {} for pt in point_constraints: vertex = None min_dist = -1 for vkey in dense_primal.vertices_on_boundary(): dist = distance_point_point( rs.PointCoordinates(pt), dense_primal.vertex_coordinates(vkey)) if min_dist < 0 or min_dist > dist: vertex = vkey min_dist = dist constraints[vertex] = ('point', rs.PointCoordinates(pt)) for vkey in dense_primal.vertices_on_boundary(): if vkey not in constraints: curve = None min_dist = -1 for crv in curve_constraints: vkey_guid = rs.AddPoint( dense_primal.vertex_coordinates(vkey)) t = rs.CurveClosestPoint(crv, vkey_guid) pt = rs.EvaluateCurve(crv, t) dist = distance_point_point( pt, dense_primal.vertex_coordinates(vkey)) rs.DeleteObject(vkey_guid) if min_dist < 0 or min_dist > dist: curve = crv min_dist = dist constraints[vkey] = ('curve', curve) rs.EnableRedraw(True) mesh_smooth_area(dense_primal, kmax=smoothing_iterations, damping=smoothing_damping, callback=apply_constraints, callback_args=[dense_primal, constraints]) rs.EnableRedraw(False) dense_primal_guid = draw_mesh(dense_primal) rs.MoveObject(dense_primal_guid, [dx, 0, 0]) rs.EnableRedraw(True) dense_dual = mesh_dual(dense_primal, Mesh) rotate_mesh(dense_dual, pi / 2) rs.EnableRedraw(False) dense_dual_guid = draw_mesh(dense_dual) rs.MoveObject(dense_dual_guid, [2 * dx, 0, 0]) rs.EnableRedraw(True) return primal, dense_primal, dense_dual
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])