private void DrawGear(Point3d BasePoint, double gearModule, int gearTeethCount) { Point3d oldBase = BasePoint; BasePoint = new Point3d(0, 0, 0); Vector3d mov = new Vector3d(oldBase.X, oldBase.Y, oldBase.Z); mov = mov.TransformBy(_editorHelper.CurrentUcs); double rp = (gearModule * gearTeethCount) / 2; // Primitive radius = (gearModule * gearTeethCount) / 2 //double gamma = Math.PI * gearModule / (2 * rp); double rrc = rp - 1.2 * gearModule; // Roor Radius double rr = rrc; // Roor Radius double rb = rp - gearModule; // Base Radius double re = rp + gearModule; // External Radius using (Transaction tr = _db.TransactionManager.StartTransaction()) { BlockTable bt = (BlockTable)tr.GetObject(_db.BlockTableId, OpenMode.ForWrite); BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); BlockTableRecord Gear = new BlockTableRecord(); string nameSalt = DateTime.Now.GetHashCode().ToString(); Gear.Name = "Gear" + nameSalt; Gear.Origin = BasePoint; bt.Add(Gear); tr.AddNewlyCreatedDBObject(Gear, true); ObjectId Layer20 = _drawingHelper.LayerManipulator.CreateLayer("2-0", System.Drawing.Color.Yellow); ObjectId Layer32 = _drawingHelper.LayerManipulator.CreateLayer("3-2", System.Drawing.Color.Lime); Circle RbCircle = new Circle(BasePoint, Vector3d.ZAxis, rb); Circle RrCircle = new Circle(BasePoint, Vector3d.ZAxis, rr); Circle RpCircle = new Circle(BasePoint, Vector3d.ZAxis, rp); Circle ReCircle = new Circle(BasePoint, Vector3d.ZAxis, re); RbCircle.SetLayerId(Layer20, false); RrCircle.SetLayerId(Layer20, false); RpCircle.SetLayerId(Layer32, false); ReCircle.SetLayerId(Layer20, false); Gear.AppendEntity(RbCircle); Gear.AppendEntity(RrCircle); Gear.AppendEntity(RpCircle); Gear.AppendEntity(ReCircle); Polyline3d GearPolyLine = GetGearPolyline(BasePoint, gearModule, gearTeethCount); GearPolyLine.SetLayerId(Layer20, false); Gear.AppendEntity(GearPolyLine); tr.AddNewlyCreatedDBObject(RbCircle, true); tr.AddNewlyCreatedDBObject(RrCircle, true); tr.AddNewlyCreatedDBObject(RpCircle, true); tr.AddNewlyCreatedDBObject(ReCircle, true); tr.AddNewlyCreatedDBObject(GearPolyLine, true); BlockReference GearRef = new BlockReference(BasePoint, Gear.ObjectId); GearRef.Position = BasePoint; GearRef.TransformBy(_editorHelper.CurrentUcs); GearRef.TransformBy(Matrix3d.Displacement(mov)); BlockTableRecord currSpace = (BlockTableRecord)tr.GetObject(_db.CurrentSpaceId, OpenMode.ForWrite); currSpace.AppendEntity(GearRef); tr.AddNewlyCreatedDBObject(GearRef, true); tr.Commit(); } }
private void DrawRack(Point3d BasePoint, double gearModule, int gearTeethCount) { Point3d oldBase = BasePoint; BasePoint = new Point3d(0, 0, 0); Vector3d mov = new Vector3d(oldBase.X, oldBase.Y, oldBase.Z); mov = mov.TransformBy(_editorHelper.CurrentUcs); double toothAngle = 70.0; double angle1 = Math.Sin(20.0 * (Math.PI / 180.0)); double angle2 = Math.Cos(20.0 * (Math.PI / 180.0)); double toothHead = gearModule * (Math.PI / 2) - ((angle1 * 2) * (1 / angle2)); double toothValley = gearModule * (Math.PI / 2) - ((angle1 * 2.4) * (1 / angle2)); double toothLenght = gearModule * 2.2 / angle2; double toothLenght2 = gearModule * gearTeethCount * Math.PI; Polyline rackBasePoly = new Polyline(); rackBasePoly.AddVertexAt(0, new Point2d(BasePoint.X, BasePoint.Y + 1.2 * gearModule), 0.0, 0.0, 0.0); rackBasePoly.AddVertexAt(1, new Point2d(BasePoint.X + toothLenght2, BasePoint.Y + 1.2 * gearModule), 0.0, 0.0, 0.0); Polyline3d rackGearPoly = new Polyline3d(); rackGearPoly = GetRackGearPoly(BasePoint, toothLenght, toothHead, toothValley, toothAngle, gearTeethCount); #region Transaction - set the layers and insert the created polylines in the DWG Transaction tr = _db.TransactionManager.StartTransaction(); using (tr) { BlockTable bt = (BlockTable)tr.GetObject(_db.BlockTableId, OpenMode.ForWrite); BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); BlockTableRecord GearRack = new BlockTableRecord(); string nameSalt = DateTime.Now.GetHashCode().ToString(); GearRack.Name = "GearRack" + nameSalt; GearRack.Origin = BasePoint; bt.Add(GearRack); tr.AddNewlyCreatedDBObject(GearRack, true); ObjectId Layer20 = _drawingHelper.LayerManipulator.CreateLayer("2-0", System.Drawing.Color.Yellow); ObjectId Layer32 = _drawingHelper.LayerManipulator.CreateLayer("3-2", System.Drawing.Color.Lime); rackGearPoly.SetLayerId(Layer20, false); rackBasePoly.SetLayerId(Layer32, false); GearRack.AppendEntity(rackGearPoly); GearRack.AppendEntity(rackBasePoly); tr.AddNewlyCreatedDBObject(rackGearPoly, true); tr.AddNewlyCreatedDBObject(rackBasePoly, true); BlockReference GearRackRef = new BlockReference(BasePoint, GearRack.ObjectId); GearRackRef.Position = BasePoint; GearRackRef.TransformBy(_editorHelper.CurrentUcs); GearRackRef.TransformBy(Matrix3d.Displacement(mov)); BlockTableRecord currSpace = (BlockTableRecord)tr.GetObject(_db.CurrentSpaceId, OpenMode.ForWrite); currSpace.AppendEntity(GearRackRef); tr.AddNewlyCreatedDBObject(GearRackRef, true); tr.Commit(); } #endregion }