def CreateSetOfExtendedBoundaries(self, boundaries, b_length): """ creates some extened boundaries to check for out of bounds fractures. Returns the extended boundaries An auxilliary method to trim extruding fractures. Parameters ---------- boundaries: list list of boundaries to be extended """ # A fairly basic way to check if a surface is outside of the boundary # is to make a set of additional boundaries which go beyond the # current boundaries. This is not perfect as it cannot guarantee # to get all the surfaces And requires many more intersection test extended_boundary_surfaces = [] # The boundaries are created by scaling up the other boundaries distances = [1.001, 1.01, 1.1] origin = [b_length / 2, b_length / 2, b_length / 2] for dist in distances: for boundary in boundaries: extended_boundary_surfaces.append( rs.ScaleObject(boundary, origin, [dist, dist, dist], True)) return extended_boundary_surfaces
def scale(shape, scale=1.0, center=u0()): p = Pt(center) s = [scale, scale, scale] ref = shape.realize() ref.do(lambda r: rh.ScaleObject(r, p, s, False)) shape.mark_deleted() return ref
def ellipse(self, xheight, yheight, direction): centerPoint = rs.AddPoint(self.point) if direction == 'right': centerPoint = rs.MoveObject( centerPoint, rs.VectorScale(rs.VectorCreate([1, 0, 0], [0, 0, 0]), xheight / 2)) if direction == 'left': centerPoint = rs.MoveObject( centerPoint, rs.VectorScale(rs.VectorCreate([-1, 0, 0], [0, 0, 0]), xheight / 2)) if direction == 'top': centerPoint = rs.MoveObject( centerPoint, rs.VectorScale(rs.VectorCreate([0, 1, 0], [0, 0, 0]), xheight / 2)) if direction == 'bottom': centerPoint = rs.MoveObject( centerPoint, rs.VectorScale(rs.VectorCreate([0, -1, 0], [0, 0, 0]), xheight / 2)) newEllipse = rs.AddCircle(centerPoint, xheight / 2) yScaleFactor = yheight / xheight rs.ScaleObject(newEllipse, self.point, [1, yScaleFactor, 0]) rs.DeleteObject(centerPoint) return (newEllipse)
def scale_block(self): origin = [0, 0, 0] detail = Rhino.RhinoDoc.ActiveDoc.Objects.Find(self.detail_id) scale = detail.Geometry.PageToModelRatio print scale sf = [self.scale, self.scale, self.scale] self.block = rs.ScaleObject(self.paper_dwg, origin, sf)
def transformMatrix(): obj_ids = rs.GetObjects("Select object(s) from which to create matrix", 0, True, True) if obj_ids is None: return box = rs.BoundingBox(obj_ids) if not isinstance(box, list): return origin = rs.PointDivide(rs.PointAdd(box[0], box[6]), 2) endpt = rs.GetPoint("To point") newpt = [1, 1, 1] translation1 = rs.VectorCreate(endpt, newpt) translation2 = rs.VectorCreate(translation1, origin) copied_obj_ids = rs.CopyObjects(obj_ids, translation2) for obj in copied_obj_ids: matrix = [] degrees = 90.0 # Some angle radians = math.radians(degrees) c = math.cos(radians) s = math.sin(radians) matrix.append([c, -s, 0, 0]) matrix.append([s, c, 0, 0]) matrix.append([0, 0, 1, 0]) matrix.append([0, 0, 0, 1]) pprint.pprint(matrix) rs.ScaleObject(obj, newpt, [3, 1, -9]) plane = rs.ViewCPlane() pprint.pprint(plane) rs.RotateObject(obj, newpt, uniform(0, 360), plane.XAxis) rs.RotateObject(obj, newpt, uniform(0, 360), plane.YAxis) rs.RotateObject(obj, newpt, uniform(0, 360), plane.ZAxis)
def RecursiveScale(objID,scalePt,scaleFact, scaleVect, num): if num == 0: return 0 else: sc = (1.0 / scaleFact) scaleVect = [x - sc for x in scaleVect] rs.ScaleObject(objID, scalePt, scaleVect, True) return RecursiveScale(objID, scalePt, scaleFact, scaleVect, num-1)
def draw_outline(z): db = draw_bottom() theta = z + 30 xy = abs((ma.sin(ma.radians(theta)))) scale = rs.ScaleObject(db, (0, 0, z / 2), (xy, xy, 0), True) curve = rs.RotateObject(scale, (0, 0, z), z * 1.5, False) rs.DeleteObject(db) return curve
def draw_outline(z): db = draw_bottom() theta = z xy = 1 / ma.log(z) scale = rs.ScaleObject(db, (0, 0, z / 3), (xy + 0.5, xy + 0.5, 0), True) curve = rs.RotateObject(scale, (0, 0, z), z, False) rs.DeleteObject(db) return curve
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 RecursiveScale(objID, scalePt, scaleFact, scaleVect, num): if num == 0: return 0 else: sc = (1.0 / scaleFact) scaleVect = [ x - sc for x in scaleVect ] #this is the meat of the script (subtract each element of a list by a number) rs.ScaleObject(objID, scalePt, scaleVect, True) return RecursiveScale(objID, scalePt, scaleFact, scaleVect, num - 1)
def draw_bottom_wakka(): bottom_outline = draw_outline(15) inner_bottom_outline = rs.ScaleObject(bottom_outline, (0, 0, 0), (0.7, 0.7, 1), True) rs.ScaleObject(bottom_outline, (0, 0, 7.5), (1.06, 1.06, 1), False) n = 360 bottom__rectangle = [] for i in rs.frange(0, n, d): si = draw_sikaku(i) do = draw_outline(15) p = rs.CurveSurfaceIntersection(do, si) rs.DeleteObject(si) rs.DeleteObject(do) dr = draw_rectangle_1(p[0][1], i) rs.MoveObject(dr, polar(0.6, i, 0)) bottom__rectangle.append(dr) bottom_curve = [bottom_outline, inner_bottom_outline, bottom__rectangle]
def scaleY(): objs = rs.GetObjects() if objs: for obj in objs: if obj: objCen = rs.SurfaceAreaCentroid(obj) if objCen: objCenPoint = rs.AddPoint(objCen[0]) rs.ScaleObject(obj, objCenPoint, (1, 2, 1)) rs.DeleteObject(objCenPoint)
def get_cut_curve(self): if self.compensation == 0: return rs.CopyObject(self.nurbs_curve) offset_distance = self.general_input["cut_diam"] * 0.5 scl_obj = rs.ScaleObject(self.nurbs_curve, self.point, (1.2, 1.2, 1), True) offset_points = rs.BoundingBox(scl_obj) rs.DeleteObject(scl_obj) offset_point_a = offset_points[0] offset_point_b = self.point if not rs.PointInPlanarClosedCurve(self.point, self.nurbs_curve): offset_point_b = self.find_point_in_curve(self.nurbs_curve) offset_a = rs.OffsetCurve(self.nurbs_curve, offset_point_a, offset_distance, None, 2) offset_b = rs.OffsetCurve(self.nurbs_curve, offset_point_b, offset_distance, None, 2) #Revisa si el offset no genero curvas separadas y si es el caso asigna la curva original como offset comparativo if not offset_a or len(offset_a) != 1: self.log.append( "offset error: el cortador no cabe en una de las curvas, se reemplazo con la curva original." ) if offset_a: rs.DeleteObjects(offset_a) offset_a = rs.CopyObject(self.nurbs_curve) if not offset_b or len(offset_b) != 1: self.log.append( "offset error: el cortador no cabe en una de las curvas, se reemplazo con la curva original." ) if offset_b: rs.DeleteObjects(offset_b) offset_b = rs.CopyObject(self.nurbs_curve) #Revisa el area para saber cual es el offset interno o externo if rs.CurveArea(offset_a) < rs.CurveArea(offset_b): in_offset = offset_a out_offset = offset_b else: in_offset = offset_b out_offset = offset_a #Responde dependiendo que compensacion se necesita if self.compensation == 1: rs.DeleteObject(in_offset) return out_offset elif self.compensation == -1: rs.DeleteObject(out_offset) return in_offset else: rs.DeleteObject(in_offset) rs.DeleteObject(out_offset) return None
def ellipse(self, xheight, yheight, placement='center', angle=0): centerPoint = rs.AddPoint(self.point) if placement == 'edge': centerPoint = rs.MoveObject( centerPoint, rs.VectorScale(rs.VectorCreate([1, 0, 0], [0, 0, 0]), xheight / 2)) newEllipse = rs.AddCircle(centerPoint, xheight / 2) ScaleFactor = yheight / xheight rs.ScaleObject(newEllipse, self.point, [1, ScaleFactor, 0]) newEllipse = rs.RotateObject(newEllipse, self.point, angle) rs.DeleteObject(centerPoint)
def scaleObject(id): x, y, z = [ float(n) for n in raw_input( 'At what point? Select the point carefully!: "x y z"').split() ] X, Y, Z = [ float(n) for n in raw_input( 'By what factor? "x y z": (Scale factor for each axis. Enter 1 to retain original scale. Never enter 0.)' ).split() ] rs.ScaleObject(id, (x, y, z), (X, Y, Z)) print('Done.') nextAction = ''
def draw_top_wakka(): top_outline = draw_outline(20) rs.ScaleObject(top_outline, (0, 0, 20), (1.09, 1.09, 1), False) n = 360 top_rectangle = [] for i in rs.frange(0, n, d): si = draw_sikaku(i) p = rs.CurveSurfaceIntersection(top_outline, si) rs.DeleteObject(si) dr = draw_rectangle_1(p[0][1], i) rs.MoveObject(dr, polar(0.1, i, 0)) top_rectangle.append(dr) top_curve = [top_outline, top_rectangle]
def projectPtOnSrf(attractorPt, targetSrf, pt): r = rs.AddLine(attractorPt, pt) r = rs.ScaleObject(r, attractorPt, (10, 10, 10)) dom = rs.CurveDomain(r) crv = rs.coercecurve(r) srf = rs.coercesurface(targetSrf).ToNurbsSurface() inv = Interval(dom[0], dom[1]) rs.DeleteObject(r) xobj = Intersection.CurveSurface(crv, inv, srf, 0.1, 1) return xobj[0].PointB
def ellipse(self, xheight, yheight, placement='center', angle=0): """xheight: the x dimension of the ellipse before rotation \n yheight: the y dimension of the ellipse before rotation \n placement: (optional) 'center' places ellipse centered around the turtle, 'edge' places ellipse to the side of the turtle \n angle: (optional) rotates ellipse around the turtle's""" centerPoint = rs.AddPoint(self.point) if placement == 'edge': centerPoint = rs.MoveObject( centerPoint, rs.VectorScale(rs.VectorCreate([1, 0, 0], [0, 0, 0]), xheight / 2)) newEllipse = rs.AddCircle(centerPoint, xheight / 2) ScaleFactor = yheight / xheight rs.ScaleObject(newEllipse, self.point, [1, ScaleFactor, 0]) newEllipse = rs.RotateObject(newEllipse, self.point, angle) rs.DeleteObject(centerPoint)
def ellipse(self, xheight, yheight, direction): if direction == center: centerPoint = self.point else if direction == right: centerPoint = rs.CopyObject(self.point, rs.VectorScale(rs.VectorCreate([1,0,0],[0,0,0]), xheight/2)) else if direction == left: centerPoint = rs.CopyObject(self.point, rs.VectorScale(rs.VectorCreate([-1,0,0],[0,0,0]), xheight/2)) else if direction == top: centerPoint = rs.CopyObject(self.point, rs.VectorScale(rs.VectorCreate([0,1,0],[0,0,0]), yheight/2)) else if direction == bottom: centerPoint = rs.CopyObject(self.point, rs.VectorScale(rs.VectorCreate([0,-1,0],[0,0,0]), yheight/2)) else: print('invalid direction') continue newEllipse = rs.AddCircle(centerPoint, xheight/2) yScaleFactor = yheight/xheight rs.ScaleObject(newEllipse, self.point, [1,yScaleFactor,0])
def fitcurvetolength(): curve_id = rs.GetObject("Select a curve to fit to Length", rs.filter.curve, True, True) if curve_id is None:return length = rs.CurveLength(curve_id) length_limit = rs.GetReal("Length limit", 0.5*length, 0.01*length, length) if length_limit is None:return while True: if rs.CurveLength(curve_id)<=length_limit:break curve_id = rs.ScaleObject(curve_id, (0,0,0), (0.95,0.95,0.95)) if curve_id is None: print "Something went wrong" return print "New curve length: ", rs.CurveLength(curve_id)
def scalecurve(): curve_id = rs.GetObject("pick curve", 4) # provide breakout bc idk if curve_id is None: return length = rs.CurveLength(curve_id) print "current length: %g " % length length_max = rs.GetReal("max length? ", .5 * length, .1 * length, 10 * length) # you can set ranges! if length_max is None: return while length < length_max: curve_id = rs.ScaleObject(curve_id, (0, 0, 0), (1.5, 1.5, 1.5), True) length = rs.CurveLength(curve_id) print "new curve length: %g" % rs.CurveLength(curve_id)
def ScaleEach(): factor = 2 objrefs = [] if sc.sticky.has_key("SCALEFACTOR"): factor = sc.sticky["SCALEFACTOR"] while True: go = Rhino.Input.Custom.GetObject() go.AcceptNumber(True, False) optFactor = Rhino.Input.Custom.OptionDouble(factor) go.AddOptionDouble("Scale", optFactor) get_rc = go.GetMultiple(1, 0) if go.CommandResult() != Rhino.Commands.Result.Success: return go.CommandResult() if get_rc == Rhino.Input.GetResult.Object: for n in range(go.ObjectCount): objrefs.append(go.Object(n)) break elif get_rc == Rhino.Input.GetResult.Number: factor = go.Number() sc.sticky["SCALEFACTOR"] = factor elif get_rc == Rhino.Input.GetResult.Option: factor = optFactor.CurrentValue sc.sticky["SCALEFACTOR"] = factor continue factor = sc.sticky["SCALEFACTOR"] if len(objrefs) == 0: return rs.EnableRedraw(False) for objref in objrefs: Id = objref.ObjectId obj = sc.doc.Objects.Find(Id) bbCen = obj.Geometry.GetBoundingBox(True).Center rs.ScaleObject(Id, bbCen, [factor, factor, factor], False) rs.EnableRedraw(True)
def outline(s): x1= 6*s y1= 0 x2= 3*s y2= 6*s*ma.sqrt(3)/2 xy1 = (x1, y1, 0) xy2 = (x2, y2, 0) line_origin = rs.AddLine(xy1, xy2) o = length_of_outline = 0.1 #0.05<0<0.10 line = rs.ScaleObject(line_origin, (0, 0, 0), (1+o, 1+o, 0), False) for angle in rs.frange(60, 360, 60): rs.RotateObject(line, (0, 0, 0), angle, None, True) all_lines = rs.ObjectsByType(0) rs.ObjectColor(all_lines,colors[0])
def addConstructionLine(point_a): # Color to use when drawing dynamic lines line_color_1 = System.Drawing.Color.FromArgb(200, 200, 200) line_color_2 = System.Drawing.Color.FromArgb(255, 0, 0) # This is a function that is called whenever the GetPoint's # DynamicDraw event occurs def GetPointDynamicDrawFunc(sender, args): point_b = args.CurrentPoint point_C = Rhino.Geometry.Point3d((point_a.X + point_b.X) / 2, (point_a.Y + point_b.Y) / 2, (point_a.Z + point_b.Z) / 2) #Rhino.Geometry.Transform.Translation( vec = rs.VectorCreate(point_b, point_a) rs.VectorUnitize(vec) vec2 = rs.VectorScale(vec, 500) vec3 = rs.coerce3dpoint(rs.VectorAdd(point_b, vec2)) rs.VectorReverse(vec2) vec4 = rs.coerce3dpoint(rs.VectorSubtract(point_b, vec2)) args.Display.DrawLine(point_a, vec3, line_color_1, 1) args.Display.DrawLine(point_a, vec4, line_color_1, 1) args.Display.DrawPoint(point_a, Rhino.Display.PointStyle.ControlPoint, 3, line_color_1) args.Display.DrawPoint(point_b, Rhino.Display.PointStyle.ControlPoint, 3, line_color_2) # Create an instance of a GetPoint class and add a delegate # for the DynamicDraw event gp = Rhino.Input.Custom.GetPoint() gp.DynamicDraw += GetPointDynamicDrawFunc gp.Get() if (gp.CommandResult() == Rhino.Commands.Result.Success): pt = gp.Point() line = rs.AddLine(point_a, pt) c = rs.CurveMidPoint(line) scaled = rs.ScaleObject(line, c, [500, 500, 500]) rs.ObjectColor(scaled, [199, 199, 199])
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 offsetRow(self, edge, vec, width): """ Offset a row depending on the type of width and direction. need to use self.edges :return: """ # print("edge", rs.CurveLength(edge)) # print("vec", vec) # print("width", width) newRow = rs.OffsetCurve(edge, vec, width) # Magic number # print("newRow", newRow) # print("newRowCurve", rs.CurveLength(newRow)) rs.ScaleObject(newRow, rs.CurveMidPoint(newRow), [20, 20, 0]) # print("ScaleNewRowCurve", rs.CurveLength(newRow)) # Problem Below!! param = [] for e in self.edges: intersect = rs.CurveCurveIntersection(newRow, e) # Follows the Rhino api if intersect is not None: param.append(intersect[0][5]) # print("param", param) if param[0] < param[1]: newRow = rs.TrimCurve(newRow, [param[0], param[1]]) elif param[0] > param[1]: newRow = rs.TrimCurve(newRow, [param[1], param[0]]) else: # only one intersection, it's time to stop newRow = None # newRow = rs.TrimCurve(newRow, [param[0], param[1]]) # print("TrimNewRowCurve", rs.CurveLength(newRow)) return newRow
def make(self): runVector = rs.VectorCreate(rs.CurveEndPoint(self.runLongEdge), rs.CurveStartPoint(self.runLongEdge)) unitRunVec = rs.VectorUnitize(runVector) treadVec = rs.VectorScale(unitRunVec, self.treadLength) riseVec = rs.VectorCreate([0, 0, self.riserHeight], [0, 0, 0]) newPt = [ rs.CurveStartPoint(self.firstRiserEdge).X, rs.CurveStartPoint(self.firstRiserEdge).Y, rs.CurveStartPoint(self.firstRiserEdge).Z - self.deltaHeight ] ptList = [] ptList.append(rs.AddPoint(newPt)) for i in range(self.numRisers): tempPt = rs.CopyObject(ptList[-1]) rs.MoveObject(tempPt, riseVec) ptList.append(tempPt) tempPt = rs.CopyObject(ptList[-1]) rs.MoveObject(tempPt, treadVec) ptList.append(tempPt) #stringer construct offset line undersideLine = rs.AddLine(ptList[0], ptList[-1]) closestPtParam = rs.CurveClosestPoint(undersideLine, ptList[1]) closestPt = rs.EvaluateCurve(undersideLine, closestPtParam) perpVec = rs.VectorUnitize(rs.VectorCreate(ptList[1], closestPt)) stringerBtm = rs.MoveObject(undersideLine, rs.VectorScale(perpVec, -self.thickness)) cnstrLine = rs.ScaleObject(stringerBtm, rs.CurveMidPoint(stringerBtm), [2, 2, 2]) #line going down btmPt = rs.MoveObject(ptList[0], [0, 0, -self.thickness]) moveDir = rs.VectorCreate(ptList[2], ptList[1]) btmPtMoved = rs.MoveObject(rs.CopyObject(btmPt), rs.VectorScale(moveDir, 3)) btmLineCnstr = rs.AddLine(btmPt, btmPtMoved) ptIntersectBtm = rs.AddPoint( rs.LineLineIntersection(btmLineCnstr, cnstrLine)[0]) #yes #top lines topVec = rs.VectorScale( rs.VectorUnitize(rs.VectorCreate(ptList[-1], ptList[-2])), self.extenionLength) topPt1 = rs.MoveObject(ptList[-1], topVec) topPtDown = rs.MoveObject(rs.CopyObject(topPt1), [0, 0, -self.thickness]) extLengthTemp = self.extenionLength if extLengthTemp < .1: extLengthTemp = .1 topVec = rs.VectorScale( rs.VectorUnitize(rs.VectorCreate(ptList[-1], ptList[-2])), extLengthTemp) topPtTemp = rs.MoveObject(rs.CopyObject(topPtDown), topVec) topLine = rs.AddLine(topPtDown, topPtTemp) ptIntersectTop = rs.AddPoint( rs.LineLineIntersection(topLine, cnstrLine)[0]) #yes ptList.append(topPtDown) ptList.append(ptIntersectTop) ptList.append(ptIntersectBtm) stringer = rs.AddPolyline(ptList) closeCrv = rs.AddLine(rs.CurveStartPoint(stringer), rs.CurveEndPoint(stringer)) newStringer = rs.JoinCurves([stringer, closeCrv], True) stair = rs.ExtrudeCurve(newStringer, self.firstRiserEdge) rs.CapPlanarHoles(stair) #make handrail guide curve topOfNosing = rs.AddLine(ptList[1], ptList[-5]) self.guideCrv = topOfNosing rs.DeleteObject(btmLineCnstr) rs.DeleteObject(btmPtMoved) rs.DeleteObject(btmLineCnstr) rs.DeleteObject(ptIntersectTop) rs.DeleteObject(undersideLine) rs.DeleteObject(topPtTemp) rs.DeleteObject(topLine) rs.DeleteObject(stringer) rs.DeleteObject(newStringer) rs.DeleteObjects(ptList) return stair
rs.MoveObject(listOfLists[i + 1], (0, findVOffset(listOfLists[i + 1]), 0)) #Now to create the square bounding box for it. initialBox = rs.BoundingBox(sortedCurves) iBoxX = rs.Distance(initialBox[0], initialBox[1]) iBoxY = rs.Distance(initialBox[0], initialBox[3]) if iBoxX >= iBoxY: boxDim = iBoxX else: boxDim = iBoxY initialBorder = rs.AddRectangle(rs.WorldXYPlane(), boxDim, boxDim) iBBox = rs.BoundingBox(initialBorder) rs.MoveObject(initialBorder, rs.VectorCreate(initialBox[3], iBBox[3])) centroid = rs.CurveAreaCentroid(initialBorder) initialBorder = rs.ScaleObject(initialBorder, centroid[0], [1.125, 1.125, 1.125], False) #Align all the rows horizontally tCenterLine = boxDim / 2 for group in listOfLists: gBox = rs.BoundingBox(group) gBoxDim = rs.Distance(gBox[0], gBox[1]) iCenterLine = gBoxDim / 2 htranslation = tCenterLine - iCenterLine rs.MoveObject(group, (htranslation, 0, 0)) #Align total group vertically tCenterLine = boxDim / 2 gBox = rs.BoundingBox(sortedCurves) gBoxDim = rs.Distance(gBox[0], gBox[3])
def testDuplicationsAndSpaceAndScaleAndRotate(): print("\n testDuplicationsAndSpaceAndScaleAndRotate commands \n") obj_ids = rs.GetObjects( "Select object(s) from which to create the rectangular matrix", 0, True, True) if obj_ids is None: return box = rs.BoundingBox(obj_ids) if not isinstance(box, list): return origin = rs.PointDivide(rs.PointAdd(box[0], box[6]), 2) nXdups = rs.GetInteger("Max Duplications X", 1, 1) nYdups = rs.GetInteger("Max Duplications Y", 1, 1) nZdups = rs.GetInteger("Max Duplications Z", 1, 1) nXspace = rs.GetReal("Spacing X", 1, 0) rXspace = rs.GetReal("Spacing X rand", 0, 0, 100) / 100 nYspace = rs.GetReal("Spacing Y", 1, 0) rYspace = rs.GetReal("Spacing Y rand", 0, 0, 100) / 100 nZspace = rs.GetReal("Spacing Z", 1, 0) rZspace = rs.GetReal("Spacing Z rand", 0, 0, 100) / 100 nXscale = rs.GetReal("Scale X", 1, 0) rXscale = rs.GetReal("Scale X rand", 0, 0, 100) / 100 nYscale = rs.GetReal("Scale Y", 1, 0) rYscale = rs.GetReal("Scale Y rand", 0, 0, 100) / 100 nZscale = rs.GetReal("Scale Z", 1, 0) rZscale = rs.GetReal("Scale Z rand", 0, 0, 100) / 100 nXrotate = rs.GetReal("Rotate X", 0, 0, 360) rXrotate = rs.GetReal("Rotate X rand", 0, 0, 100) / 100 nYrotate = rs.GetReal("Rotate Y", 0, 0, 360) rYrotate = rs.GetReal("Rotate Y rand", 0, 0, 100) / 100 nZrotate = rs.GetReal("Rotate Z", 0, 0, 360) rZrotate = rs.GetReal("Rotate Z rand", 0, 0, 100) / 100 rKeep = 1 - rs.GetReal("Percent to erase", 0, 0, 100) / 100 endpt = rs.GetPoint("To point") sample_near_val = lambda val, rand: random.uniform(-rand * val, rand * val) translations = [] # Copy Points with Spacing for k in range(nZdups): for j in range(nYdups): for i in range(nXdups): newpt = [ origin[0] + i * nXspace + sample_near_val(nXspace, rXspace), origin[1] + j * nYspace + sample_near_val(nYspace, rYspace), origin[2] + k * nZspace + sample_near_val(nZspace, rZspace) ] translations = translations + [rs.VectorCreate(endpt, newpt)] nObjs = len(translations) objs_to_keep = random.sample(range(nObjs), int(round(nObjs * rKeep))) translations = [translations[i] for i in objs_to_keep] copied_objs = [] for tr in translations: copied_objs = copied_objs + rs.CopyObjects(obj_ids, tr) for obj in copied_objs: bb = rs.BoundingBox(obj) if bb: center_point = rs.PointDivide(rs.PointAdd(bb[0], bb[6]), 2) # pt = rs.SurfaceVolumeCentroid(obj) rs.ScaleObject(obj, center_point, [ nXscale + sample_near_val(nXscale, rXscale), nYscale + sample_near_val(nYscale, rYscale), nZscale + sample_near_val(nZscale, rZscale) ]) plane = rs.ViewCPlane() rs.RotateObject(obj, center_point, nXrotate + sample_near_val(nXrotate, rXrotate), plane.XAxis) rs.RotateObject(obj, center_point, nYrotate + sample_near_val(nYrotate, rYrotate), plane.YAxis) rs.RotateObject(obj, center_point, nZrotate + sample_near_val(nZrotate, rZrotate), plane.ZAxis)
def RandomScaling(obj, plane, domainSt, domainEnd): scale = random.uniform(domainSt, domainEnd) rs.ScaleObject(obj, plane, (scale, scale, scale)) print "rotating" return obj