获取选择实体问题
我写了一个双击弹出自定义实体,但是需要加一个读取实体扩展数据的判断,如果名字为Myshujia的扩展表存在则实现双击弹出窗体,如果不存在该表则不弹出,代码如下private void dm_DocumentLockModeChanged(object sender, DocumentLockModeChangedEventArgs e){
//双击事件
if (e.GlobalCommandName.ToUpper() == "PROPERTIES")
{
e.Veto();
Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
PromptEntityResult ent=ed.Editor
using (Transaction tran = db.TransactionManager.StartTransaction())
{
if (ent.Status == PromptStatus.OK)
{
Entity eent = (Entity)tran.GetObject(ent.ObjectId, OpenMode.ForWrite);
ResultBuffer rb = eent.XData;
TypedValue[] vals = rb.AsArray();
for (int i = 0; i < vals.Length; i++)
{
TypedValue[] val = vals;
if(val.Value.ToString=="Myshujia" )
{
using (Form2 form2 = new Form2())
{
Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(form2);
}
}
}
}
}
}
我需要的是默认的判断 不需要提示用户选择实体 怎么才能在双击时获取实体并读取扩展数据呢;帮我改改 private void dm_DocumentLockModeChanged(object sender, DocumentLockModeChangedEventArgs e)
{
if (e.GlobalCommandName.ToUpper() == "PROPERTIES")
{
Document dt = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
PromptSelectionResult res = dt.Editor.SelectImplied();
ObjectId idsel=res.Value.ObjectId;
using (Transaction tran = dt.TransactionManager.StartTransaction())
{
Entity eent = (Entity)tran.GetObject(idsel, OpenMode.ForWrite);
ResultBuffer rb = eent.XData;
if (eent.XData != null)
{
TypedValue[] vals = rb.AsArray();
if (vals.Value.ToString() == "Myshujia")
{
e.Veto();
using (Form2 form2 = new Form2())
{
Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(form2);
}
}
}
}
}
} xingang1005 发表于 2013-6-26 16:13 static/image/common/back.gif
private void dm_DocumentLockModeChanged(object sender, DocumentLockModeChangedEventArgs e)
...
我也想做这样的事情。
因为有些图形是用我自己开发的程序生成的块,我希望在双击我自己开发的块对照时可以根据块中保存的扩展数据来区分块的类型,从而弹出不同的修改程序的窗体。 SWAYWOOD 发表于 2013-11-12 13:07 static/image/common/back.gif
我也想做这样的事情。
因为有些图形是用我自己开发的程序生成的块,我希望在双击我自己开发的块对照时可 ...
写扩展数据,当双击实体时读取扩展数据,判断扩展数据内容根据不同的内容弹出不同的窗体 xingang1005 发表于 2013-11-12 13:11 static/image/common/back.gif
写扩展数据,当双击实体时读取扩展数据,判断扩展数据内容根据不同的内容弹出不同的窗体
是的,你有写好的代码让我参考一下吗?谢谢了 SWAYWOOD 发表于 2013-11-12 13:50 static/image/common/back.gif
是的,你有写好的代码让我参考一下吗?谢谢了
我有写好的双击实体的代码,根据实体ID读取扩展数据你自己写 xingang1005 发表于 2013-11-12 13:51 static/image/common/back.gif
我有写好的双击实体的代码,根据实体ID读取扩展数据你自己写
获取扩展数据我有方法,你把双击实体的代码发上来一下,谢谢! SWAYWOOD 发表于 2013-11-12 14:24 static/image/common/back.gif
获取扩展数据我有方法,你把双击实体的代码发上来一下,谢谢!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
namespace doubleclick25
{
public class doubleclick
{
public void add()
{
Initialize();
Application.ShowAlertDialog("添加双击事件成功!");
}
static DocumentCollection dm = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager;
static int num = 0;
public void Initialize()
{
//初始化关联
dm.DocumentLockModeChanged += new DocumentLockModeChangedEventHandler(dm_DocumentLockModeChanged);
}
public void Terminate()
{
//终止关联
dm.DocumentLockModeChanged -= new DocumentLockModeChangedEventHandler(dm_DocumentLockModeChanged);
}
private void dm_DocumentLockModeChanged(object sender, DocumentLockModeChangedEventArgs e)
{
dm.DocumentLockModeChanged -= new DocumentLockModeChangedEventHandler(dm_DocumentLockModeChanged);
if (num == 2)
{
if (e.GlobalCommandName.ToUpper() == "PROPERTIES")
{
Editor ed = dm.MdiActiveDocument.Editor;
// PromptSelectionResult res = ed.GetSelection();
PromptSelectionResult res = ed.SelectImplied();
ObjectId[] objids = res.Value.GetObjectIds();
if (res.Status == PromptStatus.OK)
{
e.Veto();
Application.ShowAlertDialog("你双击了" + objids);
}
num = 0;
}
}
else
num++;
dm.DocumentLockModeChanged += new DocumentLockModeChangedEventHandler(dm_DocumentLockModeChanged);
}
}
}
这个思路不错
页:
[1]
2