注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

信息 灵感 创新

I? =Information,Inspiration,Innovation

 
 
 

日志

 
 
关于我

we are 5. Mathematics, Computation, Programming, Engineering, and Making fun of life.

网易考拉推荐

实体ToolTip显示XData  

2010-12-13 16:00:09|  分类: ObjectARX |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

首先要说明,实现方式不是我的原创,其中ToolTip的实现转自这里,然后XData的设置和获取来自Kean的博客,当然我自己也做了点研究,在这里,然后把这两个技术结合起来就是你将要看到的东西。

先上效果吧。 

实体ToolTip显示XData - Lemniscate - 信息,灵感,创新
代码如下:

public class Class1:IExtensionApplication

    {

        void IExtensionApplication.Initialize()

        {

            Mytooltip();

        }

        void IExtensionApplication.Terminate()

        {

        }

        public void Mytooltip()

        {

            Document doc = Application.DocumentManager.MdiActiveDocument;

            Editor ed = doc.Editor;

            ed.PointMonitor += new PointMonitorEventHandler(MytooltipOn);

        }

        private void MytooltipOn(object sender, PointMonitorEventArgs e)

        {

            Database db = Application.DocumentManager.MdiActiveDocument.Database;

            FullSubentityPath[] ePaths = e.Context.GetPickedEntities();

            if (ePaths.Length > 0)

            {

                FullSubentityPath ePath = ePaths[0];

                using (Transaction trans = db.TransactionManager.StartTransaction())

                {

                    ObjectId entId = ePath.GetObjectIds()[0];

                    Entity ent = (Entity)trans.GetObject(entId, OpenMode.ForRead);

                    e.AppendToolTipText(GetXData(ent));

                    trans.Commit();

                }

            }

            else

            {

                e.AppendToolTipText("\n未指向实体");

            }

        }

        static public string GetXData(Entity ent)

        {

            string ret = "";

            Document doc = Application.DocumentManager.MdiActiveDocument;

            Editor ed = doc.Editor;

            ResultBuffer rb = ent.XData;

            if (rb == null)

                return "该实体不包含XData.";

            else

            {

                int n = 0;

                foreach (TypedValue tv in rb)

                {

                    ret += string.Format("类型值{0} - 类型: {1}, : {2}\n", n, tv.TypeCode, tv.Value);

                    n++;

                }

                rb.Dispose();

                return ret;

            }

        }

        [CommandMethod("SetXD")]

        static public void SetXData()

        {

            Document doc = Application.DocumentManager.MdiActiveDocument;

            Editor ed = doc.Editor;

            PromptEntityOptions peo = new PromptEntityOptions("\n请选择实体");

            PromptEntityResult per = ed.GetEntity(peo);

            if (per.Status == PromptStatus.OK)

            {

                Transaction trans = doc.TransactionManager.StartTransaction();

                DBObject obj = trans.GetObject(per.ObjectId, OpenMode.ForWrite);

                AddRegAppTableRecord("Test");

                ResultBuffer rb = new ResultBuffer();

                rb.Add(new TypedValue(1001, "Test"));

                rb.Add(new TypedValue(1000, "Greeting! I am the XData"));

                rb.Add(new TypedValue(1000, "Today is very Cold"));

                obj.XData = rb;

                rb.Dispose();

                trans.Commit();

                trans.Dispose();

            }

        }

        static void AddRegAppTableRecord(string regAppName)

        {

            Document doc = Application.DocumentManager.MdiActiveDocument;

            Editor ed = doc.Editor;

            Database db = doc.Database;

            Transaction trans = doc.TransactionManager.StartTransaction();

            RegAppTable rat = (RegAppTable)trans.GetObject(db.RegAppTableId, OpenMode.ForRead, false);

            if (!rat.Has(regAppName))

            {

                rat.UpgradeOpen();

                RegAppTableRecord ratr = new RegAppTableRecord();

                ratr.Name = regAppName;

                rat.Add(ratr);

                trans.AddNewlyCreatedDBObject(ratr, true);

            }

            trans.Commit();

            trans.Dispose();

        }

    }

 命令SetXD用于设置XData,不然新建的实体是不包含XData的。指向一个实体后,将会自动显示该实体的XData

  评论这张
 
阅读(1445)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2016