def FixedFractureGen(n, aspect_ratio=None, sides=None): """ A function to add a fixed number of circles in a cube. It also writes data to fracture data text file for regenerating fracture networks. """ if fracture_shape == 'circle': # initialize a to store fractures fracture_list = [] # a loop to insert the fixed number of fractures for i in range(n): #layer name for the frcature layer_name = "FRACTURE_" + str(i + 1) #create an istance of Fracture class frac = Fracture() #store fracture name frac.fracture_name = layer_name #generate origin for fracture origin = GeneratePoint(boxlength) #store farcture center frac.fracture_center = origin #convert the origin to a plane plane = InclinePlane(origin) #add layer and color rs.AddLayer(layer_name, rs.CreateColor(0, 255, 0)) #make current layer rs.CurrentLayer(layer_name) #insert the fracture in the domain my_circle = rs.AddCircle(plane, radius) #circle_list.append(my_circle) surf = rs.AddPlanarSrf(my_circle) #delete initial fracture drawn which is a curve rs.DeleteObject(my_circle) #save fracture's GUID frac.fracture_GUID = surf[0] #append fracture into fracture list fracture_list.append(frac) elif fracture_shape == 'ellipse': #list to store fracture surface GUIDs fracture_list = [] for i in range(n): #layer name for the frcature layer_name = "FRACTURE_" + str(i + 1) #create an istance of Fracture class frac = Fracture() frac.fracture_name = layer_name #generate fracture origin origin = GeneratePoint(boxlength) frac.fracture_center = origin #plane for fracture plane = InclinePlane(origin) #calculate r_y ry = radius / aspect_ratio #create layer for fracture rs.AddLayer(layer_name, rs.CreateColor(0, 255, 0)) rs.CurrentLayer(layer_name) #draw ellipse fracture = rs.AddEllipse(plane, radius, ry) # write the plane, r_x and r_y to file for re-plotting ##file.write("\n" + str(plane[0]) + "," + str(plane[1]) + "," + str(plane[2]) + "," + str(radius) + ","+ str(ry)) #make fracture a surface frac_surf = rs.AddPlanarSrf(fracture) #delete initial fracture drawn which is a curve rs.DeleteObject(fracture) #append surface GUID to list of fracture surfaces frac.fracture_GUID = frac_surf[0] fracture_list.append(frac) elif fracture_shape == 'polygon': #list to store fracture surface GUIDs fracture_list = [] #write the shape type ##file.write('\npolygon\n') for i in range(n): layer_name = "FRACTURE_" + str(i + 1) frac = Fracture() frac.fracture_name = layer_name #theta in radian theta_rad = (2 * math.pi) / sides #theta in degree (interior angles) theta_deg = theta_rad * (180 / math.pi) #generate origin origin = GeneratePoint(boxlength) frac.fracture_center = origin #create a 3D point object which isn't visible to the rhino document pt_01 = rs.coerce3dvector( [radius + origin[0], origin[1], origin[2]]) #empty list to store all points points = [] #a rotation axis ax = rs.coerce3dvector([0, 0, 1]) #loop to generate points for polygon vertices #file.write("\n") for j in range(sides): #rotation transform with rotation from the origin trans = rs.XformRotation2(theta_deg * j, ax, origin) #transform the original 3D point and append to list points.append(rs.PointTransform(pt_01, trans)) # append the initial point to close the polygon points.append(pt_01) # create layer for fracture # layer_name = "FRACTURE_" + str(i+1) rs.AddLayer(layer_name, rs.CreateColor(0, 255, 0)) rs.CurrentLayer(layer_name) # get GUID of created polygon polygon = rs.AddPolyline(points) # polygon = rs.AddPolyline(points) plane = InclinePlane(origin, boxlength) cob = rs.XformChangeBasis(rs.WorldXYPlane(), plane) shear2d = rs.XformIdentity() shear2d[0, 2] = math.tan(math.radians(45.0)) cob_inverse = rs.XformChangeBasis(plane, rs.WorldXYPlane()) temp = rs.XformMultiply(shear2d, cob) xform = rs.XformMultiply(cob_inverse, temp) fracture = rs.TransformObjects(polygon, xform, False) # make fracture a surface frac_surf = rs.AddPlanarSrf(fracture) # delete initial fracture drawn which is a curve rs.DeleteObject(fracture) frac.fracture_GUID = frac_surf[0] fracture_list.append(frac) return fracture_list
d = max(d, abs(dz) - h / 2) return d # check inputs if not radius: radius = [5.0 for _ in origin] if not height: height = [15.0 for _ in origin] if len(radius) < len(origin): radius = [radius[0] for _ in origin] if len(height) < len(origin): height = [height[0] for _ in origin] # calculate transformation matrix between worldxy and box plane voxplane = rs.WorldXYPlane() a = [9999.9 for p in pts] for i, o in enumerate(origin): tpts = [rg.Point3d(p) for p in pts] voxplane.Origin = o.Origin tf = rg.Transform.PlaneToPlane(o, voxplane) # rebase the points according to the transformation matrix for p in tpts: p.Transform(tf) a = [ min(a[j], get_dist(p, o, radius[i], height[i])) for j, p in enumerate(tpts) ]
def RandomFractureGen(frac_min, frac_max, radius_min, radius_max, aspect_min=None, aspect_max=None, polysize_min=None, polysize_max=None): """ Funtions to generate fractures of random number and sizes Parameters ---------- frac_min: int minimum number of fractures to generate frac_max: int maximum number of fractures to generate radius_min: float minimum size of fractures radius_max: float maximum number of fractures to generate aspect_min: float minimum aspect ratio fpr ellipses (Default:None) aspect_max: float maximum aspect ratio fpr ellipses (Default:None) polysize_min: int minimum size of polygon (Default:None) polysize_max: int maximum size of polygon (Default:None) """ # randomly determine the number of fractures to generate num_frac = random.randint(frac_min, frac_max) # open file and append to it file = open(path, 'a') if fracture_shape == 'circle': # write the shape type file.write('\ncircle') # initialize list to store fractures fracture_list = [] # loop to generate fractures for i in range(num_frac): # name the layer layer_name = "FRACTURE_" + str(i + 1) # an instance of fracture object frac = Fracture() # get fracture name frac.fracture_name = layer_name # generate fracture center origin = GeneratePoint(boxlength) # store fracture center frac.fracture_center = origin # convert the origin to a plane plane = InclinePlane(origin, boxlength) # add layer and create color for it rs.AddLayer(layer_name, rs.CreateColor(0, 255, 0)) # make layer current layer rs.CurrentLayer(layer_name) # generate fracture size radius = FractureSize(size_dist, radius_min, radius_max) # insert the circle in the domain my_circle = rs.AddCircle(plane, radius) # write the plane and radius to file for re-plotting file.write("\n" + str(plane[0]) + "," + str(plane[1]) + "," + str(plane[2]) + "," + str(radius)) surf = rs.AddPlanarSrf(my_circle) # delete initial fracture drawn which is a curve rs.DeleteObject(my_circle) # set fracture guid into its object frac.fracture_GUID = surf[0] fracture_list.append(frac) elif fracture_shape == 'ellipse': # initialize list to store fractures fracture_list = [] # write the shape type file.write('\nellipse') for i in range(num_frac): # name the layer layer_name = "FRACTURE_" + str(i + 1) # an instance of fracture object frac = Fracture() # get fracture name frac.fracture_name = layer_name # generate fracture center origin = GeneratePoint(boxlength) # store fracture center frac.fracture_center = origin # plane for fracture plane = InclinePlane(origin, boxlength) # randomly generate radius(rx) radius = FractureSize(size_dist, radius_min, radius_max) # randomly generate aspect ratio aspect_ratio = random.randint(aspect_min, aspect_max) # calculate r_y ry = radius / aspect_ratio # add layer with color rs.AddLayer(layer_name, rs.CreateColor(0, 255, 0)) # make current layer rs.CurrentLayer(layer_name) # draw fracture fracture = rs.AddEllipse(plane, radius, ry) # write the plane, r_x and r_y to file for re-plotting file.write("\n" + str(plane[0]) + "," + str(plane[1]) + "," + str(plane[2]) + "," + str(radius) + "," + str(ry)) # make fracture a surface frac_surf = rs.AddPlanarSrf(fracture) # delete initial fracture drawn which is a curve rs.DeleteObject(fracture) # set fracture guid into its object frac.fracture_GUID = frac_surf[0] # append fracture guid to list fracture_list.append(frac) elif fracture_shape == 'polygon': # initialize list to store fractures fracture_list = [] # write the shape type file.write('\npolygon\n') for i in range(num_frac): # name the layer layer_name = "FRACTURE" + str(i + 1) # an instance of fracture class frac = Fracture() # get farcture name frac.fracture_name = layer_name # randomly determine the sides of the polygon sides = random.randint(polysize_min, polysize_max) # theta in radian theta_rad = (2 * math.pi) / sides # theta in degree (interior angles) theta_deg = theta_rad * (180 / math.pi) # generate origin origin = GeneratePoint(boxlength) # save fracture center frac.fracture_center = origin # randomly generate radius(rx) radius = FractureSize(size_dist, radius_min, radius_max) # create a 3D point object which isn't visible to the rhino document pt_01 = rs.coerce3dvector( [radius + origin[0], origin[1], origin[2]]) # empty list to store all points points = [] # a rotation axis ax = rs.coerce3dvector([0, 0, 1]) # loop to generate points for polygon vertices for j in range(sides): # rotation transform with rotation from the origin trans = rs.XformRotation2(theta_deg * j, ax, origin) # transform the original 3D point and append to list points.append(rs.PointTransform(pt_01, trans)) if j == 0: file.write( str(rs.PointTransform(pt_01, trans)[0]) + "," + str(rs.PointTransform(pt_01, trans)[1]) + "," + str(rs.PointTransform(pt_01, trans)[2]) + ",") if j != 0: file.write( str(rs.PointTransform(pt_01, trans)[0]) + "," + str(rs.PointTransform(pt_01, trans)[1]) + "," + str(rs.PointTransform(pt_01, trans)[2]) + ",") # append the initial point to close the polygon points.append(pt_01) file.write( str(pt_01[0]) + "," + str(pt_01[1]) + "," + str(pt_01[2]) + ",") # create layer for fracture layer_name = "FRACTURE_" + str(i + 1) rs.AddLayer(layer_name, rs.CreateColor(0, 255, 0)) rs.CurrentLayer(layer_name) # get GUID of created polygon polygon = rs.AddPolyline(points) # get the plane plane = InclinePlane(origin, boxlength) # transform the polygon to the plane cob = rs.XformChangeBasis(rs.WorldXYPlane(), plane) shear2d = rs.XformIdentity() shear2d[0, 2] = math.tan(math.radians(45.0)) cob_inverse = rs.XformChangeBasis(plane, rs.WorldXYPlane()) temp = rs.XformMultiply(shear2d, cob) xform = rs.XformMultiply(cob_inverse, temp) fracture = rs.TransformObjects(polygon, xform, False) # write to file #file.write(str(origin[0]) + "," + str(origin[1]) + "," + str(origin[2])+ "," ) file.write( str(plane[0]) + "," + str(plane[1]) + "," + str(plane[2]) + "," + str(sides) + "\n") # make fracture a surface frac_surf = rs.AddPlanarSrf(fracture) # delete initial fracture drawn which is a curve rs.DeleteObject(fracture) # set fracture guid into its objects frac.fracture_GUID = frac_surf[0] # append fracture guid to list fracture_list.append(frac) # close file file.close() return fracture_list
def RedrawNetwork(path): """ A function to reload/regenerate fracture networks. Parameter -------- path: str path where the text file containing fracture data is stored. """ # open text file m = open(path, 'r') # read first line of text file; length of the domain l = m.readline() # convert length to float length = float(l) # read the second line of the domain; shape of the fracture shape = m.readline().split() #corners = ([(0,0,0),(length,0,0),(length,length,0),(0,length,0),(0,0,length),(length,0,length),(length,length,length),(0,length,length)]) #rs.AddBox(corners) # create the domain dom = Domain.Domain(length) # display the domain dom.Show() if shape[0] != 'polygon': # a list to store GUIDs of regenerated fractures frac_list = [] # list to store the x_axis of the fracture plane x_axis = [] # list to store the y_axis of the fracture plane y_axis = [] # list to store the origin of the fracture location origin = [] # list to store the size of fracture size = [] # read file line by line for line in m: # split line by comma words = line.split(",") #if words[0] != 'circle': # append the origin, x_axis and y_axis values in each line origin.append(float(words[0])) origin.append(float(words[1])) origin.append(float(words[2])) x_axis.append(float(words[3])) x_axis.append(float(words[4])) x_axis.append(float(words[5])) y_axis.append(float(words[6])) y_axis.append(float(words[7])) y_axis.append(float(words[8])) size.append(float((words[9]))) # if the shape is ellipse, we have two radii, so append the second radius if shape[0] == 'ellipse': size.append(float((words[10]))) # close file m.close() # display fractures if they are circles/disks if shape[0] == 'circle': n = 0 # go through the lists of origin, x_axis and y_axis # we divide by 3, because the list contains 3 consecutive values # representing a single origin, x_axis or y_axis for i in range(int(len(origin) / 3)): # lists to store the origin, x_axis and y_axis of each fracture o = [] x = [] y = [] # append the origin, x_axis and y_axis of each fracture for j in range(3): o.append(origin[n + j]) x.append(x_axis[n + j]) y.append(y_axis[n + j]) # convert the origin, x_axis and y_axis to a plane plane = rs.PlaneFromFrame(o, x, y) # name the current layer # we are creating layers so that we can trim out of bounds fractures # the function that does this makes use of the layer names layer_name = "FRACTURE_" + str(i + 1) # give the layer a color rs.AddLayer(layer_name, rs.CreateColor(0, 255, 0)) # make layer the current layer rs.CurrentLayer(layer_name) # draw fracture my_disk = rs.AddCircle(plane, size[i]) # convert to a surface surf = rs.AddPlanarSrf(my_disk) #delete initial fracture drawn which is a curve rs.DeleteObject(my_disk) # append fracture frac_list.append(surf) # increment n used for parsing n += 3 # trim out of bounds fractures # the function all creates new fractures at the locations of all # exixting fractures dom.RemoveSurfacesOutsideOfBox(length) # delete all old fractures for frac in frac_list: rs.DeleteObject(frac) dom_frac = dom.my_fractures #get the fractures in the domain #print(dom_frac) #swap old guids with new ones and put new guids in old frac layers #new_frac_guids = Frac.NewFracturesGuids(dom_frac,frac_list) # display fractures if they are ellipse if shape[0] == 'ellipse': # lists to store the origin, x_axis and y_axis of each fracture n = 0 p = 0 q = 1 # go through the lists of origin, x_axis and y_axis # we divide by 3, because the list contains 3 consecutive values # representing a single origin, x_axis or y_axis for i in range(int(len(origin) / 3)): o = [] x = [] y = [] # append the origin, x_axis and y_axis of each fracture for j in range(3): o.append(origin[n + j]) x.append(x_axis[n + j]) y.append(y_axis[n + j]) # convert the origin, x_axis and y_axis to a plane plane = rs.PlaneFromFrame(o, x, y) # name the current layer # we are creating layers so that we can trim out of bounds fractures # the function that does this makes use of the layer names layer_name = "FRACTURE_" + str(i + 1) # give the layer a color rs.AddLayer(layer_name, rs.CreateColor(0, 255, 0)) # make layer current layer rs.CurrentLayer(layer_name) # draw fracture my_frac = rs.AddEllipse(plane, size[i + p], size[i + q]) # convert to a surface from curve surf = rs.AddPlanarSrf(my_frac) # delete initial fracture drawn which is a curve rs.DeleteObject(my_frac) # append fracture frac_list.append(surf) # increment varaiables used for parsing n += 3 p += 1 q += 1 # trim out of bounds fractures dom.RemoveSurfacesOutsideOfBox(length) # delete old fractures for frac in frac_list: rs.DeleteObject(frac) dom_frac = dom.my_fractures if shape[0] == 'polygon': # list to store origin origin = [] # list to store number of sides of each polygon size = [] # list to store the x_axis of the fracture plane x_axis = [] # list to store the y_axis of the fracture plane y_axis = [] # list to store fractures frac_list = [] # list to store points points = [] for line in m: # split each line by comma words = line.split(",") # store the number of sides of the polygon size.append(float(words[-1])) # store the x axis x_axis.extend( (float(words[-7]), float(words[-6]), float(words[-5]))) y_axis.extend( (float(words[-4]), float(words[-3]), float(words[-2]))) # store the origin origin.extend( (float(words[-10]), float(words[-9]), float(words[-8]))) # length of all points on the line # this will ensure we capture lines with disparate points when # generating polygon of different sides ex = int(3 * (size[-1] + 1)) # store all points on the line points.extend((words[:ex])) # close file m.close() # variables to use for parsing n = 0 m = 0 # iterate for the number of fractures generated for i in range(len(size)): # list to store points and origin o = [] x = [] y = [] p = [] # get the origin and axes of the fracture for j in range(3): o.append(origin[n + j]) x.append(x_axis[n + j]) y.append(y_axis[n + j]) # variable for parsing r = 0 # get the points of fracture edges for k in range(int(size[i]) + 1): p.append([]) for l in range(3): p[k].append(float(points[m + l + r])) # increment r r += 3 # increment parsing variables m += ((int(size[i]) + 1) * 3) n += 3 # name the current layer # we are creating layers so that we can trim out of bounds fractures # the function that does this makes use of the layer names layer_name = "FRACTURE_" + str(i + 1) # give the layer a color rs.AddLayer(layer_name, rs.CreateColor(0, 255, 0)) # make layer the current layer rs.CurrentLayer(layer_name) # joing the points poly = rs.AddPolyline(p) # get the plane plane = rs.PlaneFromFrame(o, x, y) # transform fracture to the plane cob = rs.XformChangeBasis(rs.WorldXYPlane(), plane) shear2d = rs.XformIdentity() shear2d[0, 2] = math.tan(math.radians(45.0)) cob_inverse = rs.XformChangeBasis(plane, rs.WorldXYPlane()) temp = rs.XformMultiply(shear2d, cob) xform = rs.XformMultiply(cob_inverse, temp) frac = rs.TransformObjects(poly, xform, False) # convert to a surface surf = rs.AddPlanarSrf(frac) #delete initial fracture drawn which is a curve rs.DeleteObject(frac) frac_list.append(surf) # trim out of bounds fractures # the function all creates new fractures at the locations of all # exixting fractures dom.RemoveSurfacesOutsideOfBox(length) # delete all old fractures for fr in frac_list: rs.DeleteObject(fr) dom_frac = dom.my_fractures return dom_frac
import rhinoscriptsyntax as rs import math import Rhino from Rhino.Geometry import * points = [] epoints = [] spoints = [] split = [] csplit = [] hcurve = [] dom = [] cir = [] cplane = [] YAxis = rs.WorldXYPlane() vector = (0, 0, 1) point = rs.AddPoint(5, 1, -10) r = 1 #create the points for the first hyperbolic curve for d in rs.frange(-2, 4, 0.1): x = d z = -(math.cosh(x)) y = 1 pt = (x, y, z) rs.AddPoint(x, y, z) points.append(pt) #create the circles and planes from them for c in range(0, 7):
def SampleGardenPath(): # Acquire information for the garden path start_point = rs.GetPoint('Start point of path') if start_point is None: return end_point = rs.GetPoint('End point of path', start_point) if end_point is None: return half_width = rs.GetDistance(start_point, None, 'First width point', 'Half width of path') if half_width is None: return tile_radius = rs.GetReal('Radius of tiles', 1.0) if tile_radius is None: return if tile_radius <= 0.0: return tile_spacing = rs.GetReal('Distance between tiles', 1.0) if tile_spacing is None: return if tile_spacing < 0.0: return # To increase speed, disable redrawing rs.EnableRedraw(False) # Calculate angles angle_rc = rs.Angle(start_point, end_point) angle = angle_rc[0] length = rs.Distance(start_point, end_point) width = half_width * 2 angle_p90 = angle + 90.0 angle_m90 = angle - 90.0 # Draw the outline of the path polyline = [] polyline.append(rs.Polar(start_point, angle_m90, half_width)) polyline.append(rs.Polar(polyline[0], angle, length)) polyline.append(rs.Polar(polyline[1], angle_p90, width)) polyline.append(rs.Polar(polyline[2], angle + 180.0, length)) polyline.append(polyline[0]) rs.AddPolyline(polyline) # Draw the rows of tiles plane = rs.WorldXYPlane() distance = tile_radius + tile_spacing offset = 0.0 while (distance <= length - tile_radius): # Place one row of tiles given polyline along path and possibly offset it first = rs.Polar(start_point, angle, distance) current = rs.Polar(first, angle_p90, offset) next = current while (rs.Distance(first, next) < half_width - tile_radius): plane = rs.MovePlane(plane, next) rs.AddCircle(plane, tile_radius) next = rs.Polar(next, angle_p90, tile_spacing + tile_radius + tile_radius) next = rs.Polar(current, angle_m90, tile_spacing + tile_radius + tile_radius) while (rs.Distance(first, next) < half_width - tile_radius): plane = rs.MovePlane(plane, next) rs.AddCircle(plane, tile_radius) next = rs.Polar(next, angle_m90, tile_spacing + tile_radius + tile_radius) distance = distance + ((tile_spacing + tile_radius + tile_radius) * math.sin(60.0 * 180.0 / math.pi)) if (offset == 0.0): offset = (tile_spacing + tile_radius + tile_radius) * math.cos( 60.0 * 180.0 / math.pi) else: offset = 0.0 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)
def RunCommand(is_interactive): global params center = rs.GetPoint(message="Select center point") n = rs.GetInteger(message="Number of teeth", number=params["n"], minimum=4) m = rs.GetReal(message="Gear module", number=params["m"]) pa = rs.GetReal(message="Pressure angle", number=params["pa"], minimum=0, maximum=45) ha = rs.GetReal(message="Helix angle", number=params["ha"], minimum=-45, maximum=45) t = rs.GetReal(message="Thickness", number=params["t"], minimum=0) bool_opts = rs.GetBoolean(message="Output options", items=(("PitchCylinder", "No", "Yes"),), defaults=(params["pc"],)) if None in [center, n, m, pa, ha, t, bool_opts]: return 1 # Cancel pc = bool_opts[0] params["n"] = n params["m"] = m params["pa"] = pa params["ha"] = ha params["t"] = t params["pc"] = pc cplane = rs.ViewCPlane() # Get current CPlane cplane = rs.MovePlane(cplane, center) xform = rs.XformChangeBasis(cplane, rs.WorldXYPlane()) rs.EnableRedraw(False) old_plane = rs.ViewCPlane(plane=rs.WorldXYPlane()) gear = generate_gear_crv(teeth=params["n"], module=params["m"], pressure_angle=params["pa"]) pitch = abs((n * m * pi) / tan(radians(ha))) turns = t / pitch if ha < 0: # Left handed helix turns = -turns centerline = rs.AddLine([0, 0, 0], [0, 0, t]) helix = rs.AddSpiral([0, 0, 0], [0, 0, t], pitch=pitch, turns=turns, radius0=(m * n) / 2) helical_gear_srf = rs.AddSweep2(rails=[centerline, helix], shapes=[gear]) rs.DeleteObjects([centerline, helix, gear]) rs.ViewCPlane(plane=old_plane) rs.TransformObjects(helical_gear_srf, xform) if pc: circle = generate_pitch_circle_crv(teeth=params["n"], module=params["m"]) pitch_cyl_srf = rs.ExtrudeCurveStraight(circle, start_point=[0, 0, 0], end_point=[0, 0, t]) rs.TransformObjects(pitch_cyl_srf, xform) rs.DeleteObject(circle) rs.SelectObjects([helical_gear_srf, pitch_cyl_srf]) else: rs.SelectObjects(helical_gear_srf) rs.EnableRedraw(True) return 0 # Success
def DrawPlane(self, dist, axis_of_rotation, angle_of_rotation): """ function to draw the plane on Rhino interface. Returns the plane's Guid Parameters ---------- dist: float dist to move away from y-axis (origin) if 'ZX' plane dist to move away from x-axis (origin) if 'YZ' plane dist to move away from z-axis (origin) if 'XY' plane axis_of_rotation: list list specifying axis of rotation on Rhino e.g. [1,0,0] is to rotate on x-axis angle_of_rotation: float angle to rotate the plane Raises ------ ValueError if the argument 'dist' is less than than 0. """ try: if dist < 0: raise ValueError except ValueError: print("draw_plane(): argument 'dist' should not be negative") else: if self.plane == 'XY': # axis for plane to be drawn myplane = rs.WorldXYPlane() # add a rectangle in the XY plane rec = rs.AddRectangle(myplane, self.width, self.height) # save the GUID of the plane self.GUID = rec # move the plane "dist" away from the z-axis # dist to move away from z-axis (origin) rs.MoveObject(rec, [0, 0, dist]) # rotate plane rs.RotateObject(rec, [self.height / 2, self.width / 2, dist], angle_of_rotation, axis_of_rotation) # return the GUID of the plane return rec if self.plane == 'YZ': # axis for plane to be drawn myplane = rs.WorldYZPlane() # add a rectangle in the YZ plane rec = rs.AddRectangle(myplane, self.width, self.height) # save the GUID of the plane self.GUID = rec # dist to move away from x-axis (origin) rs.MoveObject(rec, [dist, 0, 0]) # rotate plane rs.RotateObject(rec, [dist, dist, self.height / 2], angle_of_rotation, axis_of_rotation) # return the GUID of the plane return rec if self.plane == 'ZX': # axis for plane to be drawn myplane = rs.WorldZXPlane() # add a rectangle in the XZ plane rec = rs.AddRectangle(myplane, self.width, self.height) # save the GUID of the plane self.GUID = rec # dist to move away from y-axis (origin) rs.MoveObject(rec, [0, dist, 0]) # rotate plane rs.RotateObject(rec, [dist, dist, self.height / 2], angle_of_rotation, axis_of_rotation) # return the GUID of the plane return rec
#coding=utf-8 import rhinoscriptsyntax as rs plane = rs.WorldXYPlane() #建立XY工作平面 mplane = rs.MovePlane(plane, [6, 6.5, 0]) #移动平面 rectangle = rs.AddCircle(mplane, 5) #建立圆形 dpointsc = rs.DivideCurve(rectangle, 20) #等分矩形 dpoints = rs.AddPoints(dpointsc) #增加等分点 for i in range(len(dpoints)): rs.AddText(str(i), dpoints[i], 1) #添加字 print(dpoints) #sphere = rs.AddSphere(dpoints[3],1) #cube = rs.AddBox(rs.BoundingBox(sphere)) sdpoints = dpoints[:] #切片提取点 for i in range(len(sdpoints)): sphere = rs.AddSphere(sdpoints[i], 0.5) cube = rs.AddBox(rs.BoundingBox(sphere)) rs.DeleteObject(sphere) #删除不再使用的球体 xform = rs.XformTranslation([i, i * 1.3, i * 1.3]) #分步骤执行比gh同步更灵活 trancube = rs.TransformObject(cube, xform)
__author__ = "billpower" __version__ = "2019.12.25" import rhinoscriptsyntax as rs plane = rs.WorldXYPlane() #获取xy以原点为中心的参考平面 rectangle = rs.AddRectangle(plane, 40, 40) dpointsCoordinate = rs.DivideCurve(rectangle, 10) #等分10矩形 dpoints = rs.AddPoints(dpointsCoordinate) #增加等分点 print(dpoints) format = "point_%s" #格式化字符串的模式 dpointe = [] i = 0 for i in range(len(dpoints)): dpointe.append(format % str(i)) #格式化字符串并逐一追加到列表 print(dpointe) dpointx = list(range(len(dpoints))) #建立等分点索引 print(dpointx) #切片索引,建球 selepoints = dpoints[x:y] spheres = [] print(selepoints) for i in range(len(selepoints)): #循环来处理多组数据 sphere = rs.AddSphere(selepoints[i], 3) #提取[y](圆心,半径) cube = rs.AddBox(rs.BoundingBox(sphere)) #(物体,plane) spheres.append(cube) # id = rs.GetObject(sphere)
def __reset_view(self): rs.ViewCPlane(None, rs.WorldXYPlane()) rs.Command("_Zoom _A _E _Enter") rs.Command("_SelAll") rs.Command("_Shade _d=r _Enter") rs.Command("_SelNone")
def outbox(self, gap): #DEFINE BASE SLICE------------> rec_lr = rs.AddRectangle(rs.WorldYZPlane(), self.data[0], self.data[1]) srf_lr = rs.AddPlanarSrf(rec_lr) rec_lr = rs.MoveObject( rec_lr, rs.VectorCreate(ZERO, rs.SurfaceAreaCentroid(srf_lr)[0])) rs.DeleteObject(srf_lr) rec_lr = cutrec(2, rec_lr, gap) srf_lr = rs.AddPlanarSrf(rec_lr) rs.DeleteObjects(rec_lr) ### CANNOT USE WORLDZX()----------> xz = rs.PlaneFromFrame([0, 0, 0], [1, 0, 0], [0, 0, 1]) rec_fk = rs.AddRectangle(xz, self.data[2], self.data[3]) ###<------------- srf_fk = rs.AddPlanarSrf(rec_fk) rec_fk = rs.MoveObject( rec_fk, rs.VectorCreate(ZERO, rs.SurfaceAreaCentroid(srf_fk)[0])) rs.DeleteObject(srf_fk) rec_fk = cutrec(2, rec_fk, gap) srf_fk = rs.AddPlanarSrf(rec_fk) rs.DeleteObjects(rec_fk) rec_tb = rs.AddRectangle(rs.WorldXYPlane(), self.data[5], self.data[4]) srf_tb = rs.AddPlanarSrf(rec_tb) rec_tb = rs.MoveObject( rec_tb, rs.VectorCreate(ZERO, rs.SurfaceAreaCentroid(srf_tb)[0])) rs.DeleteObject(srf_tb) rec_tb = cutrec(1, rec_tb, 0) srf_tb = rs.AddPlanarSrf(rec_tb) rs.DeleteObject(rec_tb) #CONSTRUCT THE BOX--------------------> srfs = [] srfs.append(rs.CopyObject(srf_tb, [0, 0, self.data[3] / 2.0])) srfs.append(rs.CopyObject(srf_tb, [0, 0, self.data[3] / (-2.0)])) srfs.append(rs.CopyObject(srf_fk, [0, self.data[0] / 2.0, 0])) srfs.append( rs.MirrorObject( rs.CopyObject(srf_fk, [0, self.data[0] / (-2.0), 0]), [0, 1, 0], [0, 0, 1])) srfs.append(rs.CopyObject(srf_lr, [self.data[5] / (-2.0), 0, 0])) srfs.append( rs.MirrorObject( rs.CopyObject(srf_lr, [self.data[5] / (2.0), 0, 0]), [1, 0, 0], [0, 0, 1])) bele = [] for srf in srfs: extvec = rs.VectorCreate(ZERO, rs.SurfaceAreaCentroid(srf)[0]) max, sign, loc = 0, -1, 0 for i in range(len(extvec)): if abs(extvec[i]) > max: max = abs(extvec[i]) sign = extvec[i] loc = i if loc == 0: line = rs.AddLine( ZERO, rs.VectorScale(rs.VectorUnitize([sign, 0, 0]), cut2)) bele.append(rs.ExtrudeSurface(srf, line)) elif loc == 1: line = rs.AddLine( ZERO, rs.VectorScale(rs.VectorUnitize([0, sign, 0]), cut2)) bele.append(rs.ExtrudeSurface(srf, line)) elif loc == 2: line = rs.AddLine( ZERO, rs.VectorScale(rs.VectorUnitize([0, 0, sign]), cut2)) bele.append(rs.ExtrudeSurface(srf, line)) rs.DeleteObject(line) rs.DeleteObjects(srfs) rs.DeleteObjects([srf_lr, srf_fk, srf_tb]) return bele
def twig_gen(self, base_radius, top_radius, height): return rs.AddCylinder(rs.WorldXYPlane(), height, base_radius)
def rc_cut_plan(boundary_brep, cut_heights, floor_guids, use_epsilon): bb = rs.BoundingBox(boundary_brep) max_z = bb[4].Z min_z = bb[0].Z crv_list, layer_list, refpt_list, bdims_list = [[], [], [], []] for i, guids in enumerate(floor_guids): if not (min_z < cut_heights[i] < max_z): continue outline_crv, internals, refpt, bdims = process_floor( guids, boundary_brep, cut_heights[i]) mp = Rhino.Geometry.AreaMassProperties.Compute(outline_crv) outline_crv_centroid = mp.Centroid corner_style = Rhino.Geometry.CurveOffsetCornerStyle.Sharp offset_crv = outline_crv.Offset(outline_crv_centroid, rs.coerce3dvector([0, 0, 1]), THICKNESS, D_TOL, corner_style) offset_crv_geometry = offset_crv[0] crv_list.append([[offset_crv_geometry], internals]) layer_list.append([LCUT_INDICES[1], LCUT_INDICES[2]]) refpt_list.append(refpt) bdims_list.append(bdims) #...brep conversion may be necessary if len(crv_list) == 0: print "Error: Cut planes do not intersect the envelope brep" return None #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 = [] increment = max(d.X for d in bdims_list) + GAP_SIZE * 1 dplane_list = get_drawing_planes(bdims_list, rs.WorldXYPlane(), GAP_SIZE) refplane_list = [rs.MovePlane(rs.WorldXYPlane(), pt) for pt in refpt_list] for i, floor in enumerate(crv_list): t = Rhino.Geometry.Transform.ChangeBasis(dplane_list[i], refplane_list[i]) for j, layer_crvs in enumerate(floor): for c in layer_crvs: c.Transform(t) select_items.extend( wru.add_curves_to_layer(layer_crvs, layer_list[i][j])) labelpt = (bdims_list[i].X / 2 + dplane_list[i].Origin.X, bdims_list[i].Y / 2 + dplane_list[i].OriginY, 0) td = rs.AddTextDot(str(i + 1), labelpt) rs.ObjectLayer(td, "XXX_LCUT_00-GUIDES") select_items.append(td) rs.UnselectAllObjects() rs.SelectObjects(select_items) rs.Redraw() rs.EnableRedraw(True)