简单的写了下 只实现了选点的 很多东东都没考虑 O(∩_∩)O~
- class PolygonJig: DrawJig
- {
- enum SelectState
- {
- OnPoint,
- OnEdge
- }
- Polyline _pl;
- SelectState state = SelectState.OnPoint;
- Point3d _position;
- int _id;
- public PolygonJig(Polyline pl, int id)
- {
- _pl = pl;
- _id = id;
- }
- protected override SamplerStatus Sampler(JigPrompts prompts)
- {
- switch (state)
- {
- case SelectState.OnPoint:
- JigPromptPointOptions jigOpts = new JigPromptPointOptions();
- jigOpts.UserInputControls =
- UserInputControls.Accept3dCoordinates |
- UserInputControls.NoZeroResponseAccepted |
- UserInputControls.NoNegativeResponseAccepted;
- PromptPointResult res = prompts.AcquirePoint(jigOpts);
- Point3d pnt = res.Value;
- if (pnt != _position)
- _position = pnt;
- else
- return SamplerStatus.NoChange;
- if (res.Status == PromptStatus.Cancel)
- return SamplerStatus.Cancel;
- else
- return SamplerStatus.OK;
- case SelectState.OnEdge:
- return SamplerStatus.Cancel;
- }
- return SamplerStatus.Cancel;
- }
- protected override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw draw)
- {
- _pl.SetPointAt(_id, _position.Convert2d(new Plane()));
- draw.Geometry.Draw(_pl);
- draw.Geometry.Text(_position, Vector3d.ZAxis, Vector3d.XAxis, 20, 0.75, 0, _pl.Area.ToString());
- return true;
- }
- }
- [CommandMethod("cc")]
- public static void CC()
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Editor ed = doc.Editor;
- Database db = doc.Database;
- var optEnt = new PromptEntityOptions("\n请选择多边形");
- optEnt.SetRejectMessage("选择错误!");
- optEnt.AddAllowedClass(typeof(Polyline), false);
- var resEnt = ed.GetEntity(optEnt);
- if (resEnt.Status != PromptStatus.OK)
- return;
- using (var tr = db.TransactionManager.StartTransaction())
- {
- Polyline pl = tr.GetObject(resEnt.ObjectId, OpenMode.ForWrite) as Polyline;
- pl.Highlight();
-
- int n = Convert.ToInt32(Math.Round(pl.GetParameterAtPoint(pl.GetClosestPointTo(resEnt.PickedPoint, true)), MidpointRounding.AwayFromZero));
- if (n >= pl.EndParam) n = 0;
- var jig = new PolygonJig(pl, n);
- ed.Drag(jig);
- tr.Commit();
- }
- }
|