I am developing a Steel Section plugin for my company, and it functions well. One thing I would like to do is use a jig so that the user can see it on the screen where the crosshairs are, relative to the insertion point (TL,TC, TR, ML, MC, MR, BL, BC, BR).
This is the code I have to draw an I-beam
public override void DrawSection(SectionPlacement Placement, Point3d InsertionPoint) { //convert the InsertionPoint to Point2d Point2d Inspt = new Point2d(InsertionPoint.X, InsertionPoint.Y); Point2d PtVertex = new Point2d(); Polyline oPolyline = new Polyline(16); Point3dCollection Pts = new Point3dCollection(); //Get top left based on Insertion Point being Middle centre switch (Placement) { case SectionPlacement.TopLeft: PtVertex = Inspt; break; case SectionPlacement.TopCentre: PtVertex = new Point2d(Inspt.X - (this.Bf / 2), Inspt.Y); break; case SectionPlacement.TopRight: PtVertex = new Point2d(Inspt.X - (this.Bf), Inspt.Y); break; case SectionPlacement.MiddleLeft: PtVertex = new Point2d(Inspt.X, Inspt.Y + (this.D / 2)); break; case SectionPlacement.MiddleCentre: PtVertex = new Point2d(Inspt.X - (this.Bf / 2), Inspt.Y + (this.D / 2)); break; case SectionPlacement.MiddleRight: PtVertex = new Point2d(Inspt.X - this.Bf, Inspt.Y + (this.D / 2)); break; case SectionPlacement.BottomLeft: PtVertex = new Point2d(Inspt.X, Inspt.Y + this.D); break; case SectionPlacement.BottomCentre: PtVertex = new Point2d(Inspt.X - (this.Bf / 2), Inspt.Y + this.D); break; case SectionPlacement.BottomRight: PtVertex = new Point2d(Inspt.X - this.Bf, Inspt.Y + this.D); break; } Pts.Add(new Point3d(PtVertex.X, PtVertex.Y, 0)); oPolyline.AddVertexAt(0, PtVertex, 0, 0, 0); Pts.Add(new Point3d(PtVertex.X, PtVertex.Y, 0)); PtVertex = new Point2d(PtVertex.X + this.Bf, PtVertex.Y); oPolyline.AddVertexAt(1, PtVertex, 0, 0, 0); Pts.Add(new Point3d(PtVertex.X, PtVertex.Y, 0)); PtVertex = new Point2d(PtVertex.X, PtVertex.Y - this.tf); oPolyline.AddVertexAt(2, PtVertex, 0, 0, 0); Pts.Add(new Point3d(PtVertex.X, PtVertex.Y, 0)); PtVertex = new Point2d(PtVertex.X - (this.Bf / 2) + (this.tw / 2) + this.r1, PtVertex.Y); oPolyline.AddVertexAt(3, PtVertex, 0.414, 0, 0); Pts.Add(new Point3d(PtVertex.X, PtVertex.Y, 0)); PtVertex = new Point2d(PtVertex.X - this.r1, PtVertex.Y - this.r1); oPolyline.AddVertexAt(4, PtVertex, 0, 0, 0); Pts.Add(new Point3d(PtVertex.X, PtVertex.Y, 0)); PtVertex = new Point2d(PtVertex.X, PtVertex.Y - this.D + (2 * (this.r1 + this.tf))); oPolyline.AddVertexAt(5, PtVertex, 0.414, 0, 0); Pts.Add(new Point3d(PtVertex.X, PtVertex.Y, 0)); PtVertex = new Point2d(PtVertex.X + this.r1, PtVertex.Y - this.r1); oPolyline.AddVertexAt(6, PtVertex, 0, 0, 0); Pts.Add(new Point3d(PtVertex.X, PtVertex.Y, 0)); PtVertex = new Point2d(PtVertex.X + (this.Bf / 2) - (this.tw / 2) - r1, PtVertex.Y); oPolyline.AddVertexAt(7, PtVertex, 0, 0, 0); Pts.Add(new Point3d(PtVertex.X, PtVertex.Y, 0)); PtVertex = new Point2d(PtVertex.X, PtVertex.Y - this.tf); oPolyline.AddVertexAt(8, PtVertex, 0, 0, 0); Pts.Add(new Point3d(PtVertex.X, PtVertex.Y, 0)); PtVertex = new Point2d(PtVertex.X - this.Bf, PtVertex.Y); oPolyline.AddVertexAt(9, PtVertex, 0, 0, 0); Pts.Add(new Point3d(PtVertex.X, PtVertex.Y, 0)); PtVertex = new Point2d(PtVertex.X, PtVertex.Y + this.tf); oPolyline.AddVertexAt(10, PtVertex, 0, 0, 0); Pts.Add(new Point3d(PtVertex.X, PtVertex.Y, 0)); PtVertex = new Point2d(PtVertex.X + this.Bf / 2 - (this.tw / 2) - this.r1, PtVertex.Y); oPolyline.AddVertexAt(11, PtVertex, 0.414, 0, 0); Pts.Add(new Point3d(PtVertex.X, PtVertex.Y, 0)); PtVertex = new Point2d(PtVertex.X + this.r1, PtVertex.Y + this.r1); oPolyline.AddVertexAt(12, PtVertex, 0, 0, 0); Pts.Add(new Point3d(PtVertex.X, PtVertex.Y, 0)); PtVertex = new Point2d(PtVertex.X, PtVertex.Y + this.D - (2 * (this.tf + this.r1))); oPolyline.AddVertexAt(13, PtVertex, 0.414, 0, 0); Pts.Add(new Point3d(PtVertex.X, PtVertex.Y, 0)); PtVertex = new Point2d(PtVertex.X - this.r1, PtVertex.Y + this.r1); oPolyline.AddVertexAt(14, PtVertex, 0, 0, 0); Pts.Add(new Point3d(PtVertex.X, PtVertex.Y, 0)); PtVertex = new Point2d(PtVertex.X - (this.Bf / 2) + (this.tw / 2) + this.r1, PtVertex.Y); oPolyline.AddVertexAt(15, PtVertex, 0, 0, 0); Pts.Add(new Point3d(PtVertex.X, PtVertex.Y, 0)); PtVertex = new Point2d(PtVertex.X, PtVertex.Y + this.tf); oPolyline.AddVertexAt(16, PtVertex, 0, 0, 0); this.Draw(oPolyline); } public void Draw(Polyline Polyline) { Database db = AcApp.DocumentManager.MdiActiveDocument.Database; using (Transaction tr = db.TransactionManager.StartTransaction()) { BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); btr.AppendEntity(Polyline); tr.AddNewlyCreatedDBObject(Polyline, true); tr.Commit(); } }
What sort of jig should I be using? I would like it to behave similar to a blockjig. Any thoughts on this?
hi brent
call me a cheat, i just had a quick look and i think this is for you:
http://through-the-interface.typepad.com/through_the_interface/2008/03/using-a-jig-to.html
felix
You could use a DrawJig or EntityJig. I normally use the DrawJig for dragging block references.
Just wondering if you have considered making these objects Dynamic Blocks? When you add point parameters to your dyn block defs and insert those blocks via AutoCAD's insert command and tap the CTRL key during the drag it will step thru the various points as base insertion points. It would give you the interaction that you are looking for with added flexibility.
I know this code is ugly but you can change it on what you need
there are 2 classes in attachment
tested on A2010 x64 Win7
~'J'~
Thanks for the responses. I went back to basics over the weekend and got a very basic jig and modified it.
public class SectionJig : EntityJig { Point3d BasePt; PromptPointResult ppr = null; Matrix3d matrix; string SectionName = ""; public SectionJig(Polyline polyline, string sectionName) : base(polyline) { SectionName = sectionName; } public PromptPointResult StartJig() { Editor ed = AcApp.DocumentManager.MdiActiveDocument.Editor; BasePt = new Point3d(0, 0, 0); ppr = (PromptPointResult) ed.Drag(this); do { switch (ppr.Status) { case PromptStatus.OK: return ppr; break; // TODO: might not be correct. Was : Exit Do break; } } while (ppr.Status != PromptStatus.Cancel); return ppr; } protected override SamplerStatus Sampler(JigPrompts prompts) { ppr = prompts.AcquirePoint(string.Format("Select insertion point for {0}: ",SectionName)); if (ppr.Value.IsEqualTo(BasePt)) { return SamplerStatus.NoChange; } else { matrix = Matrix3d.Displacement(BasePt.GetVectorTo(ppr.Value)); this.Entity.TransformBy(matrix); BasePt = ppr.Value; return SamplerStatus.OK; } } protected override bool Update() { return false; } }
cadMeUp - I did consider using dynamic blocks, but I instead went for an xml file that has the data for all of the steel members in it.