明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1813|回复: 1

[转帖]获取Dimension的defpoint

[复制链接]
发表于 2008-4-3 13:25:00 | 显示全部楼层 |阅读模式
本帖最后由 作者 于 2008-6-26 8:51:28 编辑

来自http://discussion.autodesk.com/thread.jspa?messageID=430762
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
http://www.vbdesign.net/ 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


返回对齐标注或转角标注的标注点坐标
http://www.mjtd.com/e-zine/mezine0505.HTM#605
锁定dim标注数值VBA版(支持公差等格式)
http://bbs.mjtd.com/forum.php?mod=viewthread&tid=27492&extra=&page=1
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

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
 楼主| 发表于 2008-4-10 11:54:00 | 显示全部楼层
本帖最后由 作者 于 2008-4-10 11:55:15 编辑
  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
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-25 21:19 , Processed in 0.175645 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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