Author Topic: Jigs to Create Multiple Enity's  (Read 2247 times)

0 Members and 1 Guest are viewing this topic.

GumbyCAD

  • Newt
  • Posts: 84
Jigs to Create Multiple Enity's
« on: February 10, 2014, 11:42:45 PM »
Hi Team,

I was wondering if a Jig could support multiple object creation?

I.e. Draw a rectangle and  line from Corner to Corner as part of the jig.

All the examples I have found only show the creation of a single entity.

Stephan

gile

  • Gator
  • Posts: 2520
  • Marseille, France
Re: Jigs to Create Multiple Enity's
« Reply #1 on: February 11, 2014, 01:27:32 AM »
Hi,

To deal with multiple entities, you have to inherit from drawJig rather than EntityJig. Google for DrawJig to find examples.
Speaking English as a French Frog

gile

  • Gator
  • Posts: 2520
  • Marseille, France
Re: Jigs to Create Multiple Enity's
« Reply #2 on: February 12, 2014, 01:18:09 AM »
Hi,

Here's a little snippet to draw a rectangle and a line between the specified corners. It works on the current UCS plane.

Code - C#: [Select]
  1. using Autodesk.AutoCAD.ApplicationServices;
  2. using Autodesk.AutoCAD.DatabaseServices;
  3. using Autodesk.AutoCAD.EditorInput;
  4. using Autodesk.AutoCAD.Geometry;
  5. using Autodesk.AutoCAD.Runtime;
  6.  
  7. [assembly: CommandClass(typeof(RectangleDrawJig.CommandMethods))]
  8.  
  9. namespace RectangleDrawJig
  10. {
  11.     public class CommandMethods
  12.     {
  13.         [CommandMethod("Test", CommandFlags.Modal)]
  14.         public void Test()
  15.         {
  16.             Document doc = Application.DocumentManager.MdiActiveDocument;
  17.             Database db = doc.Database;
  18.             Editor ed = doc.Editor;
  19.  
  20.             PromptPointResult ppr = ed.GetPoint("\nSpecify the first corner: ");
  21.             if (ppr.Status != PromptStatus.OK) return;
  22.             Matrix3d ucs = ed.CurrentUserCoordinateSystem;
  23.             Point3d basePt = ppr.Value;
  24.             using (Transaction tr = db.TransactionManager.StartTransaction())
  25.             using(Line line = new Line(basePt, basePt))
  26.             using(Polyline pline = new Polyline(4))
  27.             {
  28.                 Point2d basePt2d = new Point2d(basePt.X, basePt.Y);
  29.                 pline.AddVertexAt(0, basePt2d, 0.0, 0.0, 0.0);
  30.                 pline.AddVertexAt(1, basePt2d, 0.0, 0.0, 0.0);
  31.                 pline.AddVertexAt(2, basePt2d, 0.0, 0.0, 0.0);
  32.                 pline.AddVertexAt(3, basePt2d, 0.0, 0.0, 0.0);
  33.                 pline.Closed = true;
  34.                 RectangleJig jig = new RectangleJig(pline, line, ucs);
  35.                 PromptResult pr = ed.Drag(jig);
  36.                 if (pr.Status == PromptStatus.OK)
  37.                 {
  38.                     BlockTableRecord btr =
  39.                         (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
  40.                     pline.TransformBy(ucs);
  41.                     btr.AppendEntity(pline);
  42.                     tr.AddNewlyCreatedDBObject(pline, true);
  43.                     line.TransformBy(ucs);
  44.                     btr.AppendEntity(line);
  45.                     tr.AddNewlyCreatedDBObject(line, true);
  46.                 }
  47.                 tr.Commit();
  48.             }
  49.         }
  50.  
  51.         class RectangleJig : DrawJig
  52.         {
  53.             private Polyline pline;
  54.             private Line line;
  55.             private Matrix3d ucs2wcs, wcs2ucs;
  56.             private Point3d dragPt;
  57.             private Point2d basePt;
  58.  
  59.             public RectangleJig(Polyline pline, Line line, Matrix3d ucs)
  60.             {
  61.                 this.pline = pline;
  62.                 this.line = line;
  63.                 this.ucs2wcs = ucs;
  64.                 this.wcs2ucs = ucs.Inverse();
  65.                 this.dragPt = line.EndPoint;
  66.                 this.basePt = pline.GetPoint2dAt(0);
  67.             }
  68.  
  69.             protected override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw draw)
  70.             {
  71.                 Autodesk.AutoCAD.GraphicsInterface.WorldGeometry geo = draw.Geometry;
  72.                 if (geo != null)
  73.                 {
  74.                     geo.PushModelTransform(ucs2wcs);
  75.                     geo.Draw(line);
  76.                     geo.Draw(pline);
  77.                     geo.PopModelTransform();
  78.                 }
  79.                 return true;
  80.             }
  81.  
  82.             protected override SamplerStatus Sampler(JigPrompts prompts)
  83.             {
  84.                 PromptPointResult ppr = prompts.AcquirePoint("\nSpecify the opposite corner: ");
  85.                 if (ppr.Value.IsEqualTo(dragPt))
  86.                     return SamplerStatus.NoChange;
  87.                 dragPt = ppr.Value;
  88.                 Update();
  89.                 return SamplerStatus.OK;
  90.             }
  91.  
  92.             private void Update()
  93.             {
  94.                 Point3d pt = dragPt.TransformBy(wcs2ucs);
  95.                 line.EndPoint = pt;
  96.                 pline.SetPointAt(1, new Point2d(pt.X, basePt.Y));
  97.                 pline.SetPointAt(2, new Point2d(pt.X, pt.Y));
  98.                 pline.SetPointAt(3, new Point2d(basePt.X, pt.Y));
  99.             }
  100.         }
  101.  
  102.     }
  103. }
  104.  
Speaking English as a French Frog