- 积分
- 1299
- 明经币
- 个
- 注册时间
- 2012-8-28
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2013-7-26 16:46:49
|
显示全部楼层
本帖最后由 7.兮♂贝 于 2013-7-26 17:20 编辑
//右键菜单
[CommandMethod("addcontext")]
public void AddContextMenu()
{
//右键菜单 对象
ContextMenuExtension m_ContextMenu = new ContextMenuExtension();
m_ContextMenu.Title = "ContextMenu Sample";
//右键菜单项及其事件
MenuItem MenuItem_1 = new MenuItem("Create Line");
MenuItem_1.Click += new EventHandler(MenuItem_1_Click);
//菜单项添加到右键菜单
m_ContextMenu.MenuItems.Add(MenuItem_1);
//加入到应用程序级的右键菜单中
Application.AddDefaultContextMenuExtension(m_ContextMenu);
//加入到某一种对象的右键菜单中
//Application.AddObjectContextMenuExtension(RXClass.GetClass(System.Type.GetType("Circle")), m_ContextMenu);
}
private void MenuItem_1_Click(object sender, System.EventArgs e)
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = doc.Editor;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
PromptPointOptions pointOpts,otherOpts;
PromptPointResult pointResult,otherResult;
Point3d firstPnt = new Point3d();
Point3d OtherPnt = new Point3d();
Line tLine;
pointOpts = new PromptPointOptions("please select a point: ");
pointResult = ed.GetPoint(pointOpts);
if (pointResult.Status == PromptStatus.OK)
firstPnt = pointResult.Value;
otherOpts = new PromptPointOptions("\n select other point: ");
otherResult = ed.GetPoint(otherOpts);
if (otherResult.Status == PromptStatus.OK)
OtherPnt = otherResult.Value;
try
{
//得到当前数据库块表
BlockTable bt = (BlockTable)(trans.GetObject(db.BlockTableId, OpenMode.ForRead));
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
tLine = new Line(firstPnt, OtherPnt);
//往数据库中添加实体
btr.AppendEntity(tLine);
trans.AddNewlyCreatedDBObject(tLine, true);
trans.Commit();
}
catch(Autodesk.AutoCAD.Runtime.Exception g)
{
Application.ShowAlertDialog(g.Message);
trans.Abort();
}
}
}
|
|