zoukankan      html  css  js  c++  java
  • 转:实体ToolTip显示XData

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

    先上效果吧。

     

    实体ToolTip显示XData - Castor - 趁年轻,多折腾~~

     下面是实现的代码:

     

    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 += newPointMonitorEventHandler(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(" 未指向实体");

                }

            }

            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, 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 = newPromptEntityOptions(" 请选择实体");

                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 = newRegAppTableRecord();

                    ratr.Name = regAppName;

                    rat.Add(ratr);

                    trans.AddNewlyCreatedDBObject(ratr, true);

                }

                trans.Commit();

                trans.Dispose();

            }

        }

     

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

    原文地址:http://blog.csdn.net/gisoracle/article/details/7276782

  • 相关阅读:
    JAVA安卓和C# 3DES加密解密的兼容性问题(2013年8月修改版)
    eval绑定decimal数据后,如何去掉后面没有意义的0?
    Linq使用Group By经验总结
    mysql 分页存储过程 一次返回两个记录集(行的条数,以及行记录),DataReader的Read方法和NextResult方法
    把 HttpHandler.ashx 修改为 异步编程 异步操作
    td内容自动换行 ,td超过宽度显示点点点… , td 使用 overflow:hidden 无效,英文 数字 不换行 撑破div容器
    window.location.href = window.location.href 跳转无反应 a 超链接 onclick 点击跳转无反应
    C#怎么调用百度地图Web API
    .Net MVC 当前上下文中不存在名称“Style”
    无法使用备份文件 'D:20160512.bak',因为原先格式化该文件时所用扇区大小为 512,而目前所在设备的扇区大小为 4096
  • 原文地址:https://www.cnblogs.com/wenwu/p/3234648.html
Copyright © 2011-2022 走看看