def rotate(mesh): rotation_x, rotation_y, rotation_z = random.sample(range(0, 360), 3) center_point = rs.MeshAreaCentroid(mesh) mesh = rs.RotateObject(mesh, center_point, rotation_x, [0,40,0], copy=False) mesh = rs.RotateObject(mesh, center_point, rotation_y, [1,0,0], copy=False) mesh = rs.RotateObject(mesh, center_point, rotation_z, copy=False) return mesh
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 Run(xNum, yNum): if xNum is None: rs.MessageBox("No number provided for x") return if yNum is None: rs.MessageBox("No number provided for y") return rs.EnableRedraw(False) boxes = [] for i in range(xNum): for n in range(yNum): points = [] for s in range(2): for t in range(4): x = math.cos(math.radians(45 + 90 * t)) * math.sqrt(2) y = math.sin(math.radians(45 + 90 * t)) * math.sqrt(2) z = -1 + 2 * s point = geo.Point3d(x, y, z) points.append(point) box = rs.AddBox(points) box = rs.RotateObject(box, geo.Point3d(0, 0, 0), 90 / (xNum - 1) * i, geo.Vector3d.ZAxis) box = rs.RotateObject(box, geo.Point3d(0, 0, 0), 90 / (yNum - 1) * n, geo.Vector3d.XAxis) box = rs.MoveObject(box, geo.Vector3d(4 * i, 4 * n, 0)) boxes.append(box) rs.EnableRedraw(True) return boxes #Run()
def draw_x(self, point, size=CELL_SIZE): """Drawing X""" x = point[0] - size * .025 y = point[1] - (size * .75) / 2 r = rs.AddRectangle((x, y, 0), size * .05, size * .75) rectangles = [ rs.RotateObject(r, point, 45, copy=True), rs.RotateObject(r, point, -45, copy=True) ] rs.DeleteObject(r) rs.CurveBooleanUnion(rectangles) rs.DeleteObjects(rectangles)
def PlaceInstance(file, x, y, mirror, rotate): rs.Command("_-Insert _File=_Yes " + root + "packages/" + file + ".3dm B 0,0,0 1 0 _Enter") objects = rs.SelectedObjects() if not len(objects): return None object = objects[0] rs.UnselectAllObjects() rs.RotateObject(object, (0, 0, 0), rotate) if mirror: rs.RotateObject(object, (0, 0, 0), 180, (0, 1, 0)) rs.MoveObject(object, (0, 0, -boardThickness)) rs.MoveObject(object, (x, y, 0)) return object
def PlaceInstance(file, x, y, mirror, rotate): rs.Command( "_-Insert _File=_Yes /Users/denis/sandbox/denisbohm/firefly-ice-mechanical/scripts/packages/" + file + ".3dm B 0,0,0 1 0 _Enter") objects = rs.SelectedObjects() if not len(objects): return None object = objects[0] rs.UnselectAllObjects() rs.RotateObject(object, (0, 0, 0), rotate) if mirror: rs.RotateObject(object, (0, 0, 0), 180, (0, 1, 0)) rs.MoveObject(object, (0, 0, -boardThickness)) rs.MoveObject(object, (x, y, 0)) return object
def rotateObjects(): objs = rs.GetObjects("Select objects") if objs is None: return center = rs.GetPoint("About which point?") if center is None: return for obj in objs: box = rs.BoundingBox(obj) if not isinstance(box, list): return xyp = rs.WorldXYPlane() rs.RotateObject(obj, center, random() * 360, xyp[0]) rs.RotateObject(obj, center, random() * 360, xyp[1]) rs.RotateObject(obj, center, random() * 360, xyp[2])
def drawDivisionLine(emblem, color=True): objs = [] # line r = 24 for i in range(int(emblem.division)): p = [r, 0, 0] if (emblem.division % 4 == 0): angle = i * 360.0 / emblem.division + 360.0 / emblem.division / 2.0 else: angle = i * 360.0 / emblem.division p = rs.VectorRotate(p, angle, [0, 0, 1]) obj = rs.AddLine([0, 0, 0], p) if (color): layer = "line%s" % (i % int(emblem.division / 2.0)) else: layer = "lineGray" rs.ObjectLayer(obj, layer) objs.append(obj) # circle obj = rs.AddCircle([0, 0, 0], r) if (color): layer = "lineBlack" else: layer = "lineGray" rs.ObjectLayer(obj, layer) objs.append(obj) # text planeOri = rs.ViewCPlane() for i in range(int(emblem.division / 2.0)): if (emblem.division % 4 == 0): angle = i * 360.0 / emblem.division + 360.0 / emblem.division / 2.0 else: angle = i * 360.0 / emblem.division p = [r, 0, 0] txt = "%d" % (angle) height = 1.2 pt = [0, height / 2.0, 0] font_style = 0 justification = 2 + 65536 obj = rs.AddText(txt, pt, height, font, font_style, justification) rs.RotateObject(obj, [0, 0, 0], -90.0, [0, 0, 1], False) rs.MoveObject(obj, [r, 0, 0]) rs.RotateObject(obj, [0, 0, 0], angle, [0, 0, 1], False) rs.ObjectLayer(obj, "textLine") objs.append(obj) rs.ViewCPlane(None, planeOri) #return return objs
def profile2(plane, vec): rs.ViewCPlane(None, plane) sec = rs.AddLine((0, 0, 0), (louverW, 0, 0)) sec = rs.RotateObject(sec, plane.Origin, 45.0, plane.ZAxis, copy=True) # if sec: rs.DeleteObjects(sec) return sec
def rotateObject(id): angle = float(raw_input('By what angle (in degrees)?')) 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('About what axis? "x y z": (Enter 1 to rotate or 0 to not rotate along a particular axis)').split()] rs.RotateObject(id, (x,y,z), angle, axis=(X,Y,Z)) print('Done.') nextAction = ''
def MoveWithVector (treeIn, profPointTreeIn, vectorTreeIn, thicknessIn, angleIn, treeOut): profMax = GridCornerBig (profPointTreeIn) profMin = GridCornerSmall (profPointTreeIn) max = GridCornerBig (treeIn) for i in range(treeIn.BranchCount): treeBranch = treeIn.Branch(i) treePath = treeIn.Path(i) profBranch = profPointTreeIn.Branch(i) vectorBranch = vectorTreeIn.Branch(i) thicknessBranch = thicknessIn.Branch(i) angleBranch = angleIn.Branch(i) for j in range(treeBranch.Count): elem = treeBranch[j] profPoint = profBranch [j] vector = vectorBranch [j] v = thicknessBranch [j] angle = angleBranch [j] if type != 0: elemLapos = rs.AddPoint (elem.X,elem.Y,0) elemLapos = rs.coerce3dvector (elemLapos) #angle = rs.VectorAngle ([1,0,0], elemLapos) betaRad = math.radians (beta) gammaRad = math.radians (angle) if gammaRad > betaRad/2: gammaRad = gammaRad - betaRad/2 else: gammaRad = betaRad/2 - gammaRad v = (math.cos (betaRad/2)) / (math.cos (gammaRad)) *v vec = rs.coerce3dpoint (vector) rotVecX = vec.X rotVecZ = vec.Y rotVecY = vec.Z rotVec = rs.AddPoint (rotVecX, rotVecY, rotVecZ) rotVec = rs.coerce3dpoint (rotVec) ORIGO = rs.AddPoint (0,0,0) ORIGO = rs.coerce3dpoint (ORIGO) VECTOR = rs.RotateObject(rotVec, ORIGO, angle, [0,0,1]) vector = rs.coerce3dvector (VECTOR) vector = vector * v elem = rs.coerce3dpoint (elem) MovePoint = rs.MoveObject (elem, vector) MovePoint = rs.coerce3dpoint (MovePoint) treeOut.Add (elem, treePath)
def makeTriangleSrf(self, i): srfList = [] c0 = self.hexShape.cornersPt[i] c1 = self.hexShape.cornersPt[i + 1] p0 = self.hexProjection.cornersPt[i] p1 = self.hexProjection.cornersPt[i + 1] m = self.hexShape.centerPt mp = self.hexProjection.centerPt tm, tmp = self.move2PtInside(m, mp) t = rs.PointAdd(m, (0, 0.6, 0)) tp = util.projectPtOnSrf(self.hexProjection.attractorPt, self.hexProjection.targetSrf, t) t, tp = self.move2PtInside(t, tp, 0.5) srfList.append(rs.AddSrfPt([t, tm, tmp, tp])) srfList.append(rs.AddSrfPt([c0, m, mp, p0])) srfList.append(rs.AddSrfPt([c0, c1, p1, p0])) srfList.append(rs.AddSrfPt([c1, m, mp, p1])) vt = rs.VectorCreate(c1, p1) rs.RotateObject(srfList[3], c1, 2, vt) return rs.JoinSurfaces(srfList, True)
def align(crv1,crv2,origin,axis): count=0 vert=rs.PolylineVertices(crv1) while testAlign(crv1,crv2)==False or count>len(vert): count=count+1 crv1=rs.RotateObject(crv1,origin,360/len(vert),axis) return crv1
def circles(center, circle, radius, generation): cir = [] index = maxgeneration - generation if generation == 0: draw(center, radius, index * 10, index) if generation < maxgeneration: domain = rs.CurveDomain(circle) parameter = domain[1] / 2 points = splitcircle(circle, parameter) for p in points: temprand = random.uniform(0, 0) cent = rs.RotateObject(rs.MoveObject(p, (0, 0, generation * 10)), center, temprand) temp = rs.RotateObject((rs.AddCircle(cent, radius)), center, temprand) circles(cent, temp, radius * 0.75, generation + 1) draw(cent, radius, index * 10, index)
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 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 create_shape(target_object, ref_object, target_srf_num, angle=None): if angle == None: angle = random.choice([0, 90, 180, 270]) ref_points = ref_object.get_reference_points(target_srf_num) target_points = target_object.get_target_points(target_srf_num) shape = target_object.get_reference_shape(ref_object, target_srf_num) rotation_axis = target_object.get_rotation(target_srf_num) center = target_object.get_face_center(target_srf_num) rs.RotateObject(shape, center, angle, rotation_axis) return shape
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 postProcess(self): REDO=False ar=0.0 for i in self.FPOLY: rs.RotateObject(i, CP, -ANGLE) for i in self.FPOLY: try: ar+=rs.CurveArea(i)[0] except: pass mean_ar=ar/len(self.FPOLY) min_ar_per=0.2*mean_ar j=0 for i in self.FPOLY: pts=rs.CurvePoints(i) if(rs.CurveArea(i)[0]<min_ar_per): REDO=True break p=rs.BoundingBox(pts) max_poly=rs.AddPolyline([p[0],p[1],p[2],p[3],p[0]]) max_poly_ar=rs.CurveArea(max_poly)[0] actual_poly_ar=rs.CurveArea(i)[0] if((max_poly_ar/actual_poly_ar)>2): REDO=True rs.DeleteObject(max_poly) break else: rs.DeleteObject(max_poly) ab=int(rs.Distance(p[0],p[1])) ad=int(rs.Distance(p[0],p[3])) if((ab>ad) and (ab/ad)>5): REDO=True break elif((ab<ad) and (ab/ad)<0.2): REDO=True break j+=1 if(REDO==True and self.counter<MAX_REC): self.counter+=1 print("Redo %s" %(self.counter)) rs.DeleteObjects(self.FPOLY) self.start() self.recSplit(bsp.BBpts, 0) self.postProcess() else: j=0 for i in self.FPOLY: c=rs.CurveAreaCentroid(i)[0] rs.AddTextDot(str(j), c) j+=1
def fenceCurve(): """ ---x---x---x---x---x---x--- this script divides a curve by length and adds 'crosses' to it, grouped per curve / polyline www.studiogijs.nl """ curves = rs.GetObjects("select curves to change into fence-style", 4, preselect=True) if not curves: return s = sc.sticky['scale'] if sc.sticky.has_key('scale') else 20 scale = rs.GetReal("scale of the arrow curve", s, 5, 100) if not scale: return sc.sticky['scale'] = scale rs.EnableRedraw(False) for curve in curves: lines = [] if rs.CurveLength(curve) > scale: pts = rs.DivideCurveLength(curve, scale) for pt in pts: t = rs.CurveClosestPoint(curve, pt) vec = rs.CurveTangent(curve, t) line = rs.AddLine(pt - vec * scale / 10, pt + vec * scale / 10) rs.RotateObject(line, pt, 45) lines.append(line) line_copy = rs.RotateObject(line, pt, 90, copy=True) lines.append(line_copy) group = rs.AddGroup() rs.AddObjectsToGroup(lines, group) rs.AddObjectsToGroup(curve, group) rs.SelectObjects(lines) rs.SelectObjects(curves) rs.EnableRedraw(True)
def arrowCurve(): """ ---->---->---->---->---->---->---->---- this script divides a curve by length and adds dashes to either side of the curve, grouped per curve / polyline limitation: does not accomodate at corners (to avoid ccx issues) www.studiogijs.nl """ curves = rs.GetObjects("select curves to change into arrow-style",4, preselect=True) if not curves: return s=sc.sticky['scale'] if sc.sticky.has_key('scale') else 20 scale = rs.GetReal("scale of the arrow curve", s, 5, 100) if not scale: return sc.sticky['scale']=scale rs.EnableRedraw(False) for curve in curves: lines=[] if rs.CurveLength(curve)>scale: pts = rs.DivideCurveLength(curve, scale) for pt in pts: t=rs.CurveClosestPoint(curve, pt) vec = rs.CurveTangent(curve, t)*scale/10 line = rs.AddLine(pt, pt+vec) line_copy = rs.CopyObject(line, [0,0,0]) rs.RotateObject(line, pt, 45) rs.RotateObject(line_copy, pt, -45) lines.append(line) lines.append(line_copy) group = rs.AddGroup() rs.AddObjectsToGroup(lines, group) rs.AddObjectsToGroup(curve, group) rs.SelectObjects(lines) rs.SelectObjects(curves) rs.EnableRedraw(True)
def main(): cyls = [] radius = 0 gname = "Enclosure" extantGroups = rs.GroupNames() print "groups: ", extantGroups enclosures = [s for s in extantGroups if "Enclosure" in s] print "enclosures: ", enclosures if rs.IsGroup("Enclosure"): num = len(enclosures) gname += "_" + ` num ` encGroup = rs.AddGroup(gname) print "group: ", encGroup focus = rs.GetPoint("center of fence") if (focus is None): return rpt = rs.GetPoint("enclosure radius", focus) if (rpt is None): return else: radius = (rpt - focus).Length rs.AddObjectsToGroup(rs.AddCircle(focus, radius), encGroup) count = rs.GetInteger("number of cylinders") if (count is None): return cyldiam = rs.GetReal("cylinder diameter") if (cyldiam is None): return minheight = rs.GetReal("minimum height") if (minheight is None): return maxheight = rs.GetReal("maximum height") if (maxheight is None): return # arcjitter = rs.GetReal("amount of arc jitter") # if (arcjitter is None): return # radialjitter = rs.GetReal("amount of radial jitter") # if (radialjitter is None): return for i in range(count): cyl = rs.AddCylinder(rpt, random.uniform(minheight, maxheight), cyldiam / 2, True) rs.RotateObject(cyl, focus, (360 / count) * (i + 1)) cyls.append(cyl) if cyls: rs.AddObjectsToGroup(cyls, encGroup) print "Enclosure built:" print "focus: (", focus, ")" print "radius:", radius print "cylinders:", count, "ranging from", minheight, "to", maxheight, "units in length."
def CreateRadialBar(self, a, r0, r1, w, z0, z1, cap=False): x0 = r0 y0 = -w / 2 x1 = r1 y1 = w / 2 r = w / 2 d = self.GetDraftDistance(z0, z1) curve0 = self.CreateRadial(x0 + d, x1 - d, r - d, z0) curve1 = self.CreateRadial(x0, x1, r, z1) slot = rs.AddLoftSrf([curve0, curve1]) if cap: slot = rs.JoinSurfaces([slot, rs.AddPlanarSrf([curve0])], True) rs.DeleteObjects([curve0, curve1]) slot = rs.RotateObject(slot, (0, 0, 0), a, (0, 0, 1)) return slot
def equilateralPolygon(sides, size): cornerpoints = [] cornerpoint = rs.AddPoint(0, size, 0) cornerpoints.append(cornerpoint) for points in range(1, sides, 1): anothercorner = rs.RotateObject(cornerpoint, (0, 0, 0), points * 360 / sides, None, copy=True) cornerpoints.append(anothercorner) print(cornerpoints) rs.AddLine(cornerpoints[0], cornerpoints[1]) rs.AddLine(cornerpoints[1], cornerpoints[2])
def createSegments(): for i in range(levels): points = [] origin = [0+random.random()*depth,0+random.random()*depth,i*levelres] point1 = rs.AddPoint(radius,0,i*levelres) points.append(point1) for i in range(1, segements): tempPoint = points[-1] tempOrgin = [origin[0] + random.random()*depth, origin[1] + random.random()*depth, origin[2]+1] newPt = rs.RotateObject(tempPoint,tempOrgin,degrees,None,True) points.append(newPt) points.append(point1) lastCircle.append(tempOrgin) polygon = rs.AddPolyline(points) lofts.append(polygon) return lofts
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 curveVic(storyHt): profiles = [] firstCrv = rs.GetObject("pick a base curve", 4, True, True) count = rs.GetInteger("how many total curves") #dentil = rs.GetObject("pick dentil", 8) # vertically offset curves for i in range(count): if count == 0 or count == 1: return else: profiles.append(rs.CopyObject(firstCrv, [0, 0, storyHt * i])) # funk it up - needs to be more randomized? for crv in profiles: centerPt = rs.CurveAreaCentroid(crv) # deg = random.randint(0,360) # deg = random.randint(0,4) * 90 very swirly! deg = profiles.index(crv) * 10 rs.RotateObject(crv, centerPt[0], deg) # centerPt = rs.CurveAreaCentroid(profiles[3]) # rs.RotateObject(profiles[3], centerPt[0], 30) # centerPt = rs.CurveAreaCentroid(profiles[7]) # rs.RotateObject(profiles[7], centerPt[0], 30) # scale each crv randomly # for crv in profiles: # centerPt = rs.CurveAreaCentroid(crv) # x = random.uniform(.25,2) # y = random.uniform(.25,2) # z = 1 # rs.ScaleObject(crv, centerPt[0], (x,y,z) ) # add dentils and trim. map to surface? project? rs.SporphObject() better to use in GUI flow? # is there any flow along surface? no center box?!?! just acquire shape # for j in range(len(profiles)): # points = rs.DivideCurveEquidistant(profiles[j], 5) # for k in points: # rs.AddSphere(k, .25) # loft curves and clean up finalShape = rs.AddLoftSrf(profiles, closed=False) #profiles.append(firstCrv) rs.DeleteObjects(profiles) rs.CapPlanarHoles(finalShape)
def __init__(self,radius,sides): self.radius = radius self.sides = sides theta = (2*math.pi)/self.sides print theta pt01 = rs.AddPoint(self.radius,0,0); pts = [] pts.append(pt01) self.origin = [0,0,0] degrees = theta*(180/math.pi) print degrees for i in range(1,self.sides): tempPt = pts[-1] newPt = rs.RotateObject(tempPt,self.origin,degrees,None,True) pts.append(newPt) pts.append(pt01) self.polygon = rs.AddPolyline(pts);
def equilateralPolygon(sides, size): cornerpoints = [] cornerpoint = rs.AddPoint(0, size, 0) cornerpoints.append(cornerpoint) for point in range(1, sides, 1): anothercorner = rs.RotateObject(cornerpoint, (0, 0, 0), point * 360 / sides, None, copy=True) cornerpoints.append(anothercorner) #print(cornerpoints) for item in range(0, len(cornerpoints) - 1, 1): rs.AddLine(cornerpoints[item], cornerpoints[item + 1]) rs.AddLine(cornerpoints[len(cornerpoints) - 1], cornerpoints[0])
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)