乐筑天下

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

[转帖]获取Dimension的defpoint

[复制链接]

120

主题

326

帖子

7

银币

中流砥柱

Rank: 25

铜币
806
发表于 2008-4-3 13:25:00 | 显示全部楼层 |阅读模式
来自
About the type of dimension, just that it IS a dimension. From there, you grab the
hidden block for the dimension. The trick is to grab the
dimension's block using the handle of the dimension. Check out his website
for more info on obtaining the dimension's block.
对于尺寸线类型要从捕捉隐藏的尺寸线定义块入手,其策略是正在使用的尺寸块的句柄。
  1. Option Explicit
  2. Sub DimPts()
  3. Dim objDim0 As AcadDimension
  4. Dim objDimDefBlk As AcadBlock
  5. Dim varPickPt As Variant
  6. Dim varDimLdrSPt As Variant
  7. Dim varDimLdrEpt As Variant
  8. Dim varDimTxtPt As Variant
  9. Dim intCntr As Integer
  10. intCntr = 0
  11. Dim intCntr2 As Integer
  12. intCntr2 = 0
  13. Dim objTestEntity As AcadEntity
  14. Dim objTestPt As AcadPoint
  15. Dim strMessage As String
  16. ThisDrawing.Utility.GetEntity objDim0, varPickPt, "Select dimension: "
  17. If objDim0 Is Nothing Then
  18. MsgBox "You failed to pick a dimension object", vbCritical
  19. Exit Sub
  20. ElseIf TypeOf objDim0 Is AcadDimension Then
  21. Set objDimDefBlk = GetDefinition(objDim0.Handle)
  22. For intCntr = 0 To objDimDefBlk.Count - 1
  23. Set objTestEntity = objDimDefBlk(intCntr)
  24. If TypeOf objTestEntity Is AcadPoint Then
  25. Set objTestPt = objTestEntity
  26. Select Case intCntr2
  27. Case 0
  28. varDimLdrSPt = objTestPt.Coordinates
  29. intCntr2 = intCntr2 + 1
  30. Case 1
  31. varDimLdrEpt = objTestPt.Coordinates
  32. intCntr2 = intCntr2 + 1
  33. Case 2
  34. varDimTxtPt = objTestPt.Coordinates
  35. intCntr2 = intCntr2 + 1
  36. End Select
  37. End If
  38. Next
  39. MsgBox "Start Point = " & varDimLdrSPt(0) & "," & varDimLdrSPt(1) & vbCrLf & _
  40. "End Point = " & varDimLdrEpt(0) & "," & varDimLdrEpt(1)
  41. End If
  42. End Sub
  43. Function GetDefinition(strHandle As String) As AcadBlock
  44. ' Returns a dimension's controlling block
  45. Dim objBlk As AcadBlock
  46. Dim strLeft As String
  47. Dim strRight As String
  48. Dim blnTest As Boolean
  49. On Error GoTo Err_Control
  50. strLeft = Left(strHandle, Len(strHandle) - 2)
  51. strRight = "&H" & Right(strHandle, 2)
  52. strRight = strRight + 1
  53. strHandle = strLeft & Hex(strRight)
  54. blnTest = True
  55. Set objBlk = ThisDrawing.HandleToObject(strHandle)
  56. Set GetDefinition = objBlk
  57. Exit_Here:
  58. Exit Function
  59. Err_Control:
  60. Select Case Err.Number
  61. Case 13 'Type Mismatch
  62. If blnTest Then
  63. strRight = strRight + 1
  64. strHandle = strLeft & Hex(strRight)
  65. Err.Clear
  66. 'single increment only! Reset test
  67. blnTest = Not blnTest
  68. Resume
  69. Else
  70. 'second time in or other mismatch
  71. Err.Raise Err.Number, Err.Source, Err.Description, _
  72. Err.HelpFile, Err.HelpContext
  73. End If
  74. Case -2147467259
  75. Err.Clear
  76. MsgBox "Invalid dimension entity...", vbCritical
  77. End
  78. Case Else
  79. Err.Raise Err.Number, Err.Source, Err.Description, _
  80. Err.HelpFile, Err.HelpContext
  81. End Select
  82. End Function


返回对齐标注或转角标注的标注点坐标
锁定dim标注数值VBA版(支持公差等格式)
Change Programe
  1. Sub ll()
  2.   Dim varPickPt As Variant
  3.   Dim ddd As AcadDimension, strHandle As String
  4.   Dim strLeft As String, strRight As String
  5.   Dim bb As AcadBlock
  6.   'Set ddd = ThisDrawing.HandleToObject(ThisDrawing.ModelSpace.Item(ThisDrawing.ModelSpace.Count - 1).Handle)
  7.   ThisDrawing.Utility.GetEntity ddd, varPickPt, "Select Dimension"
  8.   Debug.Print ddd.ObjectName, ddd.Handle
  9. Dim ii As Integer, iii As Integer
  10. For ii = 1 To 13
  11.   'Debug.Print ddd.Handle
  12.   strLeft = Left(ddd.Handle, Len(ddd.Handle) - 2)
  13.   Debug.Print strLeft
  14.   strRight = "&H" & Right(ddd.Handle, 2)
  15.   Debug.Print strRight
  16.   strRight = strRight + ii
  17.   strHandle = strLeft & Hex(strRight)
  18.   Debug.Print strHandle
  19.   
  20.   Debug.Print ii, TypeName(ThisDrawing.HandleToObject(strHandle))
  21.   If TypeName(ThisDrawing.HandleToObject(strHandle)) = "IAcadBlock" Then
  22.     Set bb = ThisDrawing.HandleToObject(strHandle)
  23.     For iii = 0 To bb.Count - 1
  24.       Debug.Print bb(iii).ObjectName
  25.     Next
  26.     Exit For
  27.   End If
  28. Next ii
  29. Debug.Print "aaaaaaaa"
  30. End Sub

本帖以下内容被隐藏保护;需要你回复后,才能看到!

游客,如果您要查看本帖隐藏内容请回复
回复

使用道具 举报

120

主题

326

帖子

7

银币

中流砥柱

Rank: 25

铜币
806
发表于 2008-4-10 11:54:00 | 显示全部楼层
  1. Sub ls()
  2. Dim ii As Integer
  3. Dim strLeft As String, strRight As String
  4. ii = 2
  5. Dim xlSheet1 As Worksheet, xlSheet2 As Worksheet
  6. Set xlSheet1 = xlApp.Sheets(1)
  7. Dim Ent As AcadBlock, Ee As AcadEntity
  8. Debug.Print "ModelSpace"
  9.     Dim SSet As AcadSelectionSet
  10.     On Error Resume Next
  11.     '建立选择集
  12.     ThisDrawing.SelectionSets("mccad").Delete
  13.     Set SSet = ThisDrawing.SelectionSets.Add("mccad")
  14.     '建立过滤器
  15.     Dim fType(0) As Integer
  16.     Dim fData(0) As Variant
  17.     fType(0) = 0
  18.     fData(0) = "DIMENSION"
  19.     '选择过滤出图形中所有的标注对象
  20.     SSet.Select acSelectionSetAll, , , fType, fData
  21.     Dim i As Long
  22.     For i = 0 To SSet.Count - 1
  23.       xlSheet1.Cells(ii, 1).Value = SSet(i).ObjectName
  24.       xlSheet1.Cells(ii, 2).Value = TypeName(SSet(i))
  25.       xlSheet1.Cells(ii, 3).Value = "'" & SSet(i).Handle
  26.       cc = SSet(i).Handle
  27.       strLeft = Left(cc, Len(cc) - 2)
  28.       strRight = "&H" & Right(cc, 2)
  29.       xlSheet1.Cells(ii, 4).Value = strLeft + Hex(strRight + 1)
  30.       
  31.       ii = ii + 1
  32.     Next
  33. ' For Each Ee In ThisDrawing.ModelSpace
  34. ' Next
  35. Set xlSheet1 = Nothing
  36. Set xlSheet2 = xlApp.Sheets(2)
  37. Debug.Print
  38. Debug.Print "Blocks"
  39. ii = 2
  40. For Each Ent In ThisDrawing.Blocks
  41.    If TypeName(Ent) = "IAcadBlock" And Ent.Handle  "55" Then
  42.      xlSheet2.Cells(ii, 1).Value = Ent.ObjectName
  43.      xlSheet2.Cells(ii, 2).Value = TypeName(Ent)
  44.      xlSheet2.Cells(ii, 3).Value = "'" & Ent.Handle
  45.      xlSheet2.Cells(ii, 4).Value = Ent.Count
  46.      ii = ii + 1
  47.    End If
  48. Next
  49. Set xlSheet2 = Nothing
  50. End Sub
  51. Function xlApp() As Object
  52. '  Dim xlApp As Object    ' This Line ,Not set Excel , run Excel
  53.       'Dim xlsheet As Object
  54.       
  55.       ' 发生错误时跳到下一个语句继续执行
  56.       On Error Resume Next
  57.       ' 连接Excel应用程序
  58.       Set xlApp = GetObject(, "Excel.Application")
  59.       
  60.       If Err.Number  0 Then
  61.           Set xlApp = CreateObject("Excel.Application")
  62.           xlApp.Visible = True
  63.           xlApp.Workbooks.Add
  64.       End If
  65.       ' 返回当前活动的工作表
  66. End Function
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-7-4 22:24 , Processed in 0.388150 second(s), 62 queries .

© 2020-2025 乐筑天下

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