- 积分
- 1142
- 明经币
- 个
- 注册时间
- 2011-2-28
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
- using Autodesk.AutoCAD.Runtime;
- using Autodesk.AutoCAD.ApplicationServices;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.EditorInput;
- using Autodesk.AutoCAD.Geometry;
- using System.Collections.Generic;
- [assembly: CommandClass(typeof(CAD0901.JigClass))]
- namespace CAD0901
- {
- class JigClass : DrawJig
- {
- private Polyline pl=new Polyline();
- private Point3d p1;
- private Point3d p2;
- [CommandMethod("jc")]
- public void MyTest()
- {
-
-
- Database db = HostApplicationServices.WorkingDatabase;
- Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
- try
- {
- Matrix3d mx = ed.CurrentUserCoordinateSystem;
- PromptPointOptions ppo = new PromptPointOptions("\n第一点");
- PromptPointResult ppr = ed.GetPoint(ppo);
- p1 = ppr.Value;
- using (Transaction trans = db.TransactionManager.StartTransaction())
- {
- BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId,
- OpenMode.ForRead);
- BlockTableRecord btr = (BlockTableRecord)trans.GetObject
- (bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
- PromptResult resJig = ed.Drag(this);
- if (resJig.Status == PromptStatus.OK)
- {
- btr.AppendEntity(pl);
- trans.AddNewlyCreatedDBObject(pl, true);
- trans.Commit();
- }
- }
- }
- catch (Exception ex)
- {
-
- }
-
- }
- protected override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw draw)
- {
- draw.Geometry.Draw(pl);
- return true;
- }
- protected override SamplerStatus Sampler(JigPrompts prompts)
- {
- JigPromptPointOptions jpo = new JigPromptPointOptions("\n另一点");
- jpo.UserInputControls = UserInputControls.Accept3dCoordinates;
- PromptPointResult pr = prompts.AcquirePoint(jpo);
- Point3d tempt = pr.Value;
- if (pr.Status==PromptStatus.Cancel)
- {
- return SamplerStatus.Cancel;
- }
- if (p2!= tempt)
- {
- p2 = tempt;
- pl.AddVertexAt(0, new Point2d(p1.X, p1.Y), 0, 0, 0);
- pl.AddVertexAt(1, new Point2d(p2.X, p1.Y), 0, 0, 0);
- pl.AddVertexAt(2, new Point2d(p2.X, p2.Y), 0, 0, 0);
- pl.AddVertexAt(3, new Point2d(p1.X, p2.Y), 0, 0, 0);
- pl.Closed = true;
- return SamplerStatus.OK;
- }
- else return SamplerStatus.NoChange;
- }
- private ObjectId AppendEntity(Entity ent)
- {
- ObjectId entId;
- Database db = HostApplicationServices.WorkingDatabase;
- using (Transaction trans = db.TransactionManager.StartTransaction())
- {
- BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId,
- OpenMode.ForRead);
- BlockTableRecord btr = (BlockTableRecord)trans.GetObject
- (bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
- entId = btr.AppendEntity(ent);
- trans.AddNewlyCreatedDBObject(ent, true);
- trans.Commit();
- }
- return entId;
- }
-
- }
- }
上面这段程序,拖出一个矩形框,结果悲剧了……
我该怎么改呢? |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
x
|