EaBIM

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

作者: 萧闫子    时间: 2014-1-8 14:46
标题: [实体对象] 如何绘制一条PolyLine,给他添加扩展属性,并返回这个Polyline的ObjectId
想绘制一个矩形框,然后给这个矩形框添加一个名称和标记的扩展数据。然后返回这个矩形框的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>
复制代码





欢迎光临 EaBIM (https://eabim.net/) Powered by Discuz! X3.2