乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 108|回复: 1

[编程交流] at的读取字段表达式

[复制链接]

2

主题

3

帖子

1

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 22:45:54 | 显示全部楼层 |阅读模式
大家好,
 
我有一个带有属性引用的块引用。
 
其中一个参考是计算字段,该字段给出了多段线的面积。
 
这是其计算表达式:
%%).区域\f“%lu2”>%
 
其中2129748024是链接多段线的ID。
 
为了提取对象id号(2129748024),我想得到上面的表达式。我的目标是获取id号,并使用它将新属性插入到块中,该块将具有对应于同一多段线长度的计算字段。
 
我在www.vbaexpress上发布了这个问题。com还没有解决方案。
 
提前谢谢。
回复

使用道具 举报

1

主题

1069

帖子

1050

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
69
发表于 2022-7-7 00:35:29 | 显示全部楼层
这段代码有点脏,很棘手,你必须把它抹掉
(抱歉格式错误)
  1. <CommandMethod("foo")> _
  2.        Public Sub
  3. GetFieldFromAttribute()
  4. Dim doc As Document =
  5. Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
  6. Dim db As Database =
  7. doc.Database
  8. Dim ed As Editor = doc.Editor
  9. Try
  10. Dim tab As String =
  11. Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("ctab").ToString
  12. Dim blockname As String = ed.GetString(vbLf & "Enter blockname:
  13. ").StringResult
  14. Dim opts As PromptSelectionOptions = New
  15. PromptSelectionOptions
  16. opts.SingleOnly =
  17. True
  18. opts.MessageForRemoval = vbLf & "Select block
  19. only"
  20. opts.MessageForAdding = vbLf & "Select single
  21. block"
  22. Dim filt As SelectionFilter = New SelectionFilter({New TypedValue(0, "insert"),
  23. New TypedValue(2, blockname), New TypedValue(410,
  24. tab)})
  25. Dim psr As PromptSelectionResult = ed.GetSelection(opts,
  26. filt)
  27. If psr.Status <> PromptStatus.OK Then Exit Sub
  28. If psr.Value.Count <> 1 Then Exit Sub
  29. Dim id As ObjectId = psr.Value.GetObjectIds(0)
  30. If id.IsNull Then Exit Sub
  31. Using tr As Transaction = db.TransactionManager.StartTransaction()
  32. Dim obj As DBObject = tr.GetObject(psr.Value.GetObjectIds(0), OpenMode.ForRead)
  33. If TypeOf obj Is BlockReference Then
  34. Dim bref As BlockReference = CType(tr.GetObject(id, OpenMode.ForRead),
  35. BlockReference)
  36. Dim attcoll As AttributeCollection =
  37. bref.AttributeCollection
  38. Dim att As
  39. AttributeReference
  40. For Each aid As ObjectId In
  41. attcoll
  42. Dim aobj As DBObject = tr.GetObject(aid,
  43. OpenMode.ForRead)
  44. att = TryCast(DirectCast(aobj, AttributeReference),
  45. AttributeReference)
  46. If att Is Nothing Then Exit
  47. Sub
  48. If att.Tag.Equals("LENGTH", StringComparison.CurrentCultureIgnoreCase)
  49. Then
  50. If att.HasFields
  51. Then
  52. Dim fld As Field = tr.GetObject(att.GetField(),
  53. OpenMode.ForRead)
  54. Dim code As String =
  55. fld.GetFieldCode
  56. Dim pos1 As Int32 =
  57. code.IndexOf("_ObjId")
  58. Dim pos2 As Integer =
  59. code.IndexOf(">%")
  60. Dim leng1 As Integer =
  61. "_ObjId".Length
  62. Dim leng2 As Integer =
  63. ">%".Length
  64. Dim idstr As String = code.Substring(pos1 + leng1 + 1, pos2 - (pos1 + leng1) -
  65. 1)
  66. MsgBox("ID from field code: " & idstr)
  67. Dim objId As ObjectId = New ObjectId(New IntPtr(Convert.ToInt32(idstr)))
  68. Dim fieldchild As DBObject = tr.GetObject(objId,
  69. OpenMode.ForRead)
  70. If TypeOf fieldchild Is Polyline
  71. Then
  72. Dim poly As Polyline = DirectCast(fieldchild,
  73. Polyline)
  74. MsgBox("Compare:" & vbLf & "Return from attribute: " &
  75. att.TextString & vbLf & "Return from Polyline: " &
  76. poly.Area.ToString)
  77. End
  78. If
  79. Exit
  80. For
  81. End
  82. If
  83. End If
  84. Next
  85. End
  86. If
  87. End Using
  88.            Catch ex
  89. As
  90. Autodesk.AutoCAD.Runtime.Exception
  91. ed.WriteMessage(ex.Message + vbLf +
  92. ex.StackTrace)
  93. End Try
  94.        End Sub
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-1-31 17:55 , Processed in 0.232311 second(s), 56 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表