明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1658|回复: 0

[原创]AcadDimension

[复制链接]
发表于 2008-4-6 11:13:00 | 显示全部楼层 |阅读模式
本帖最后由 作者 于 2008-9-17 10:55:34 编辑

  Sub lll()
''
  Dim dd As AcadDimension
  Dim r1 As AcadDim3PointAngular, r2 As AcadDimAligned, r3 As AcadDimAngular
  Dim r4 As AcadDimDiametric, r5 As AcadDimOrdinate, r6 As AcadDimRadial
  Dim r7 As AcadDimRotated
  Dim r8 As AcadDimStyle, r9 As AcadDimStyles
''
Dim ii As Integer
ii = 1
  Dim Ent As AcadEntity
  For Each Ent In ThisDrawing.ModelSpace
    'Debug.Print Ent.ObjectName
   
    Select Case Ent.ObjectName
     Case "AcDbdimension"
       Debug.Print ii, Ent.ObjectName, TypeOf Ent Is AcadDimension
     Case "AcDbAlignedDimension"
       Debug.Print ii, Ent.ObjectName, TypeOf Ent Is AcadDimension
     Case "AcDb2LineAngularDimension"
       Debug.Print ii, Ent.ObjectName, TypeOf Ent Is AcadDimension
     Case "AcDbDiametricDimension"
       Debug.Print ii, Ent.ObjectName, TypeOf Ent Is AcadDimension
     Case "AcDbLeader"
       Debug.Print ii, Ent.ObjectName, TypeOf Ent Is AcadDimension
     Case "AcDbOrdinateDimension"
       Debug.Print ii, Ent.ObjectName, TypeOf Ent Is AcadDimension
     Case "AcDbRadialDimension"
       Debug.Print ii, Ent.ObjectName, TypeOf Ent Is AcadDimension
     Case "AcDbRotatedDimension"
       Debug.Print ii, Ent.ObjectName, TypeOf Ent Is AcadDimension
     Case "AcDbStyle"
       Debug.Print Ent.ObjectName
     Case "AcDbStyles"
       Debug.Print Ent.ObjectName
    End Select
  
  ii = ii + 1
  Next
End Sub
Debug.Print
1            AcDbRadialDimension           True
2            AcDbRotatedDimension        True
3            AcDbDiametricDimension      True
4            AcDbAlignedDimension         True
5            AcDbLeader                          False
6            AcDbOrdinateDimension       True
结论:
AcDbdimension---包含
1            AcDbRadialDimension           True
2            AcDbRotatedDimension        True
3            AcDbDiametricDimension      True
4            AcDbAlignedDimension         True
6            AcDbOrdinateDimension       True
AcDbdimension--不包含
5            AcDbLeader                          False

http://bbs.mjtd.com/forum.php?mod=viewthread&tid=15468&replyID=73915&skin=1
http://bbs.mjtd.com/forum.php?mod=viewthread&tid=18920&replyID=&skin=1
       gpcode(0) = 0
         datavalue(0) = "DimRadial"
         groupcode = gpcode: datacode = datavalue
          Set myss = ThisDrawing.SelectionSets.Add("ms1")
          Call myss.Select(acSelectionSetAll, , , groupcode, datacode)
http://bbs.mjtd.com/forum.php?mod=viewthread&tid=18920

70

         



标注类型:
值 0-6 是整数值,表示标注类型。值 32、64 和 128 是添加到整数值的位值(在 R13 及以后的版本中始终设置为 32)
0 = 旋转、水平或垂直;1 = 对齐
2 = 角度;3 = 直径;4 = 半径
5 = 三点角度;6 = 坐标
32 = 表示块参照(组码 2)仅由该标注参照。
64 = 坐标类型。这是一个位值(位 7),仅与整数值 6 一起使用。如果设置该值,则坐标为 X 类型;如果不设置,则坐标为 Y 类型。
128 = 这是一个添加到其他组 70 值的位值(位 8)(如果标注文字已放置到用户定义的位置,而不是放置到默认位置)

http://bbs.mjtd.com/forum.php?mod=viewthread&tid=51052&replyID=16447&skin=1
  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.   Dim sSet As AcadSelectionSet
  17.   'ThisDrawing.Utility.GetEntity objDim0, varPickPt, "Select dimension: "
  18.   Set sSet = ReadTable
  19. For Each objDim0 In sSet
  20. On Error Resume Next
  21.   If objDim0 Is Nothing Then
  22.     MsgBox "You failed to pick a dimension object", vbCritical
  23.     Exit Sub
  24.   ElseIf TypeOf objDim0 Is AcadDimension Then
  25.     Set objDimDefBlk = GetDefinition(objDim0.Handle)
  26.     For intCntr = 0 To objDimDefBlk.Count - 1
  27.       Set objTestEntity = objDimDefBlk(intCntr)
  28.       If TypeOf objTestEntity Is AcadPoint Then
  29.         Set objTestPt = objTestEntity
  30.         Select Case intCntr2
  31.           Case 0
  32.             varDimLdrSPt = objTestPt.Coordinates
  33.             intCntr2 = intCntr2 + 1
  34.           Case 1
  35.             varDimLdrEpt = objTestPt.Coordinates
  36.             intCntr2 = intCntr2 + 1
  37.           Case 2
  38.             varDimTxtPt = objTestPt.Coordinates
  39.             intCntr2 = intCntr2 + 1
  40.         End Select
  41.       End If
  42.     Next
  43.     Debug.Print "Start Point = " & varDimLdrSPt(0) & "," & varDimLdrSPt(1) & vbCrLf & _
  44.     "End Point = " & varDimLdrEpt(0) & "," & varDimLdrEpt(1)
  45.   End If
  46. Next objDim0
  47. End Sub
  48. Function GetDefinition(strHandle As String) As AcadBlock
  49.   ' Returns a dimension's controlling block
  50.   Dim objBlk As AcadBlock
  51.   Dim strLeft As String
  52.   Dim strRight As String
  53.   Dim blnTest As Boolean
  54.   On Error GoTo Err_Control
  55.     strLeft = Left(strHandle, Len(strHandle) - 2)
  56.     strRight = "&H" & Right(strHandle, 2)
  57.     strRight = strRight + 1
  58.     strHandle = strLeft & Hex(strRight)
  59.     blnTest = True
  60.     Set objBlk = ThisDrawing.HandleToObject(strHandle)
  61.     Set GetDefinition = objBlk
  62. Exit_Here:
  63.     Exit Function
  64. Err_Control:
  65.     Select Case Err.Number
  66.   Case 13 'Type Mismatch
  67.   If blnTest Then
  68.     strRight = strRight + 1
  69.     strHandle = strLeft & Hex(strRight)
  70. Err.Clear
  71.     'single increment only! Reset test
  72.     blnTest = Not blnTest
  73.     Resume
  74.   Else
  75.     'second time in or other mismatch
  76.     Err.Raise Err.Number, Err.Source, Err.Description, _
  77.     Err.HelpFile, Err.HelpContext
  78.   End If
  79.   Case -2147467259
  80.       Err.Clear
  81.      MsgBox "Invalid dimension entity...", vbCritical
  82.     End
  83.   Case Else
  84.     Err.Raise Err.Number, Err.Source, Err.Description, _
  85.     Err.HelpFile, Err.HelpContext
  86.   End Select
  87. End Function
  88. Function CreatSelectionSet(InputEntityObjectName As Variant) As AcadSelectionSet
  89.    On Error Resume Next
  90.    Dim ii
  91.    'Dim SSet As AcadSelectionSet
  92.    Dim Pt1, Pt2
  93.    If Not IsNull(ThisDrawing.SelectionSets.Item("SelectEntity")) Then
  94.      Set CreatSelectionSet = ThisDrawing.SelectionSets.Item("SelectEntity")
  95.      CreatSelectionSet.Delete
  96.    End If
  97.    Set CreatSelectionSet = ThisDrawing.SelectionSets.Add("SelectEntity")
  98.    'Pt1 = ThisDrawing.Utility.GetPoint(, "Input First Point")
  99.    'Pt2 = ThisDrawing.Utility.GetPoint(Pt1, "Input First Point")
  100.    Dim gpCode(0) As Integer
  101.    Dim dataValue(0) As Variant
  102.    gpCode(0) = 0
  103.    For ii = 0 To UBound(InputEntityObjectName)
  104.      dataValue(ii) = InputEntityObjectName(ii)
  105.    Next ii
  106.    CreatSelectionSet.Select acSelectionSetAll, , , gpCode, dataValue
  107. End Function
  108. Function ReadTable() As AcadSelectionSet
  109.    Dim sSet As AcadSelectionSet
  110.    Dim InputEntityObjectName As Variant
  111.    InputEntityObjectName = Array("Dimension")
  112.    Set sSet = CreatSelectionSet(InputEntityObjectName)
  113.    Dim Ent As AcadEntity
  114.    Set ReadTable = sSet
  115. End Function
  116. Sub llss()
  117.   Dim sSet As AcadSelectionSet
  118.   Dim objDim As AcadDimension, objDimCopy As AcadDimension
  119.   Set sSet = ReadTable
  120.   
  121.   For Each objDim In sSet
  122.     Set objDimCopy = objDim.Copy()
  123.     'Debug.Print objDimCopy.Handle, objDim.Handle
  124.    
  125.     objDimCopy.color = 1
  126.     objDim.Delete
  127.   Next objDim
  128. End Sub
读Dimension数据
  1. Dim ReturnXls As New ObjectXlsMdbTxtData
  2. Sub ReadTextFromDwg()
  3.   Dim xls As Worksheet
  4.   Set xls = ReturnXls.ReturnxlSheet("Sheet1")
  5.   Dim ee As AcadEntity, gg As AcadBlock
  6.   Dim objMtext As AcadMText
  7.   With ThisDrawing.Utility
  8.     For jj = 1 To 1
  9.         tt = xls.Cells(2, jj)
  10.         .GetEntity ee, pp, tt
  11.         Select Case InStr(ee.ObjectName, "Dimension")
  12.           Case Is > 0
  13.             Set gg = GetDefinition(ee.Handle)
  14.             For kk = 0 To gg.Count - 1
  15.               
  16.               Select Case gg.Item(kk).ObjectName
  17.                 Case "AcDbMText"
  18.                   Set objMtext = gg.Item(kk)
  19.                   Debug.Print objMtext.TextString
  20.               End Select
  21.             Next kk
  22.         End Select
  23.         
  24.         
  25.     Next jj
  26.   End With
  27. End Sub
  28. Function GetDefinition(strHandle As String) As AcadBlock
  29.    ' Returns a dimension's controlling block
  30.    Dim objBlk As AcadBlock
  31.    Dim strLeft As String
  32.    Dim strRight As String
  33.    Dim blnTest As Boolean
  34.    On Error GoTo Err_Control
  35.      strLeft = Left(strHandle, Len(strHandle) - 2)
  36.      strRight = "&H" & Right(strHandle, 2)
  37.      strRight = strRight + 1
  38.      strHandle = strLeft & Hex(strRight)
  39.      blnTest = True
  40.      Set objBlk = ThisDrawing.HandleToObject(strHandle)
  41.      Set GetDefinition = objBlk
  42. Exit_Here:
  43.      Exit Function
  44. Err_Control:
  45.      Select Case Err.Number
  46.    Case 13 'Type Mismatch
  47.    If blnTest Then
  48.      strRight = strRight + 1
  49.      strHandle = strLeft & Hex(strRight)
  50. Err.Clear
  51.      'single increment only! Reset test
  52.      blnTest = Not blnTest
  53.      Resume
  54.    Else
  55.      'second time in or other mismatch
  56.      Err.Raise Err.Number, Err.Source, Err.Description, _
  57.      Err.HelpFile, Err.HelpContext
  58.    End If
  59.    Case -2147467259
  60.        Err.Clear
  61.       MsgBox "Invalid dimension entity...", vbCritical
  62.      End
  63.    Case Else
  64.      Err.Raise Err.Number, Err.Source, Err.Description, _
  65.      Err.HelpFile, Err.HelpContext
  66.    End Select
  67. End Function
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-26 11:54 , Processed in 0.172170 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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