EaBIM一直以来积极响应国家“十二五”推进建筑业信息化的号召,对建筑领域的信息技术开展深入技术交流和探讨!致力于打造“BIM-建筑师-生态技术”三位一体综合资源交流共享平台,希望为BIM与可持续设计理念及技术的普及做出微小的贡献!!!

EaBIM

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
查看: 518|回复: 0
打印 上一主题 下一主题

[实体对象] 如何绘制一条PolyLine,给他添加扩展属性,并返回这个Polyline的ObjectId

[复制链接]

1514

主题

7465

帖子

1万

积分

admin

Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10

积分
12404

社区QQ达人

跳转到指定楼层
楼主
发表于 2014-1-8 14:46:45 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
想绘制一个矩形框,然后给这个矩形框添加一个名称和标记的扩展数据。然后返回这个矩形框的ObjectId。在绘制以后在通过这个矩形的ObjectId重新获得这个矩形的名称和标记。如何做到?下面是我写的一部分代码,没有完成,请大家帮忙了。

  1. <ol style="margin-left: 10px !important; color: rgb(102, 102, 102); font-family: 'Microsoft Yahei', Simsun; "><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">
  2. '通过用户指定点后再绘制这个矩形,矩形的长和宽也作为参数
  3. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">Public Shared Function AddRectangle(ByVal cenPt As Point3d, ByVal Height As Double, _
  4. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">                                        ByVal Length As Double) As ObjectId
  5. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">        Dim Pt(4) As Point3d
  6. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">        Pt(0) = New Point3d(cenPt.X - Length * 0.5, cenPt.Y - Height * 0.5, 0)
  7. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">        Pt(1) = New Point3d(cenPt.X + Length * 0.5, cenPt.Y - Height * 0.5, 0)
  8. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">        Pt(2) = New Point3d(cenPt.X + Length * 0.5, cenPt.Y + Height * 0.5, 0)
  9. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">        Pt(3) = New Point3d(cenPt.X - Length * 0.5, cenPt.Y + Height * 0.5, 0)
  10. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">        Pt(4) = New Point3d(cenPt.X - Length * 0.5, cenPt.Y - Height * 0.5, 0)
  11. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">        Dim Pts As New Point3dCollection(Pt)
  12. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">        ' 在内存中创建一个未经拟合的标准三维多段线对象.
  13. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">        Dim ent As New Polyline3d(Poly3dType.SimplePoly, Pts, False)
  14. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">
  15. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">        'Add the rectangle polyline entity to model space
  16. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">        Dim acEntId As ObjectId = AppendEntity(ent)
  17. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">
  18. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">        Dim dt As DataTable = New DataTable()
  19. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">        dt.TableName = "属性表"
  20. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">        dt.AppendColumn(CellType.CharPtr, "Name")
  21. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">        dt.AppendColumn(CellType.CharPtr, "Tag")
  22. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">        Dim row As DataCellCollection = New DataCellCollection()
  23. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">        Dim Name As DataCell = New DataCell()
  24. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">        Dim Tag As DataCell = New DataCell()
  25. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">        Name.SetString("矩形框")
  26. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">        Tag.SetString("矩形标记")
  27. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">        row.Add(Name)
  28. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">        row.Add(Tag)
  29. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">        dt.AppendRow(row, True)
  30. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">
  31. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">        ent.CreateExtensionDictionary()
  32. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">        Dim exDic As DBDictionary = New DBDictionary()  '如何将扩展数据记录下来啊?
  33. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">        exDic.SetAt("属性表", dt)
  34. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">
  35. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">
  36. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">        '返回ObjectId
  37. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">        Return acEntId
  38. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">    End Function
  39. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">
  40. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">' 将图形对象加入到模型空间的函数.
  41. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">    Public Shared Function AppendEntity(ByVal ent As Entity) As ObjectId
  42. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">        ' 得到当前文档图形数据库.
  43. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">        Dim db As Database = HostApplicationServices.WorkingDatabase
  44. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">        Dim entId As ObjectId
  45. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">        Using trans As Transaction = db.TransactionManager.StartTransaction
  46. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">            ' 以读方式打开块表.
  47. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">            Dim bt As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForRead)
  48. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">            ' 以写方式打开模型空间块表记录.
  49. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">            Dim btr As BlockTableRecord = trans.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
  50. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">            ' 将图形对象的信息添加到块表记录中,并返回ObjectId对象.
  51. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">            entId = btr.AppendEntity(ent)
  52. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">            ' 把图形对象添加到事务处理中.
  53. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">            trans.AddNewlyCreatedDBObject(ent, True)
  54. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">            ' 提交事务处理.
  55. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">            trans.Commit()
  56. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">        End Using
  57. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; background-color: rgb(255, 255, 255); color: rgb(51, 102, 153); ">        Return entId
  58. </li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; font-size: 12px; line-height: 1.8em; ">    End Function</li></ol>
复制代码
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
收藏收藏 转播转播 分享分享 分享淘帖 支持支持 反对反对

相关帖子

工作时间:工作日的9:00-12:00/13:30-18:00,节假日不在线,请勿留言
*滑块验证:
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|EaBIM网 ( 苏ICP备2020058923号-1  苏公网安备32011502011255号

GMT+8, 2024-11-23 14:57

Powered by Discuz! X3.2 Licensed

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表