- 积分
- 848
- 明经币
- 个
- 注册时间
- 2008-8-16
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
鼠标拉框后 1 绘制出这个框
2 不让entity被选中
下面代码有异常,框没有绘制出来,另外 2 没有解决
全局变量 Point3d startPt;
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.PromptingForCorner += new PromptPointOptionsEventHandler(Editor_PromptingForCorner);
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.PromptedForCorner += new PromptPointResultEventHandler(Editor_PromptedForCorner);
void Editor_PromptingForCorner(object sender, PromptPointOptionsEventArgs e)
{
startPt = e.Options.BasePoint;
}
void Editor_PromptedForCorner(object sender, PromptPointResultEventArgs e)
{
Point3d endPt = e.Result.Value;
Editor ed=Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
//Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(startPt.X.ToString() + ":" + startPt.Y.ToString() + ":" + endPt.X.ToString());
//PromptSelectionResult res = ed.SelectImplied();
//if (res.Status != PromptStatus.OK) return;
//if (res.Value.Count == 0) return;
//Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("d2d");
Database db = ed.Document.Database;
Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
using (Transaction tr = tm.StartTransaction())
{
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("d1d");
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForWrite);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
Polyline entity = new Polyline();
//之前的代码出现异常
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("d2d");
entity.AddVertexAt(entity.NumberOfVertices, new Point2d(startPt.X, startPt.Y), 0, -1, -1);
entity.AddVertexAt(entity.NumberOfVertices, new Point2d(endPt.X, startPt.Y), 0, -1, -1);
entity.AddVertexAt(entity.NumberOfVertices, new Point2d(endPt.X, endPt.Y), 0, -1, -1);
entity.AddVertexAt(entity.NumberOfVertices, new Point2d(startPt.X, endPt.Y), 0, -1, -1);
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("d3d");
entity.Closed = true;
entity.ColorIndex = 1;
entity.LineWeight = LineWeight.LineWeight005;
//entity.Layer = layername;// layer.Name;
btr.AppendEntity(entity);
tr.AddNewlyCreatedDBObject(entity, true);
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("d4d");
//for (int i = 0; i < res.Value.Count; i++)
//{
// Entity entity = tr.GetObject(res.Value[i].ObjectId, OpenMode.ForWrite) as Entity;
// entity.Unhighlight();
// Autodesk.AutoCAD.ApplicationServices.Application.UpdateScreen();
//}
tr.Commit();
}
}
各位大神,帮助看下。谢谢
|
|