明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1177|回复: 0

[原创]尺寸线块有多少个子块统计?

[复制链接]
发表于 2008-7-29 14:09:00 | 显示全部楼层 |阅读模式
尺寸实体名(块)尺寸块内的子实体个数AcDb2LineAngularDimension15AcDb2LineAngularDimension15AcDb2LineAngularDimension14AcDbRotatedDimension14AcDb2LineAngularDimension13AcDbRotatedDimension11AcDb2LineAngularDimension11AcDbAlignedDimension11AcDbRotatedDimension10AcDb2LineAngularDimension10AcDbRotatedDimension9AcDb2LineAngularDimension9AcDbDiametricDimension8AcDbRotatedDimension7AcDbRadialDimension6AcDbDiametricDimension6AcDbRadialDimension5
原程序是在AutoCAD二次开发p127页基础上改动的。
  1. Function FixDimText(Dimension As AcadDimension) As String
  2.     '在复制标注对象前先保存当前图形中的块数量
  3.     Dim xlSheet As Worksheet
  4.     Set xlSheet = ReturnxlSheet
  5.     Dim ii As Integer
  6.    
  7.     Dim BlockCount As Long
  8. ''
  9. ''
  10.     BlockCount = ThisDrawing.Blocks.Count
  11.     With xlSheet
  12.       ii = .Range("A65536").End(xlUp).Row + 2
  13.     End With
  14.     '复制需要锁定文字内容的标注对象
  15.    
  16.     '检查块数量是否增加,而且新增加的块名前缀是否为"*D"
  17.     Dim NewBlockCount As Long
  18.     Dim CopyDimension As AcadDimension
  19.     Set CopyDimension = Dimension.Copy
  20.    
  21.     NewBlockCount = ThisDrawing.Blocks.Count
  22.    
  23.    
  24.    
  25.     If NewBlockCount = BlockCount + 1 And Left(ThisDrawing.Blocks(BlockCount).Name, 2) = "*D" Then
  26.    
  27.         '遍历块中的对象,取得文字内容
  28.         Dim EntityInBlock As AcadEntity
  29.         For Each EntityInBlock In ThisDrawing.Blocks(BlockCount)
  30.     With EntityInBlock
  31.       
  32. '
  33.       xlSheet.Cells(ii, 1) = Dimension.ObjectName
  34.       xlSheet.Cells(ii, 2) = Dimension.Handle
  35.       xlSheet.Cells(ii, 3) = Dimension.TextOverride
  36.       xlSheet.Cells(ii, 4) = BlockCount
  37.       xlSheet.Cells(ii, 5) = CopyDimension.ObjectName
  38.       xlSheet.Cells(ii, 6) = CopyDimension.Handle
  39.       xlSheet.Cells(ii, 7) = Dimension.TextOverride
  40.       xlSheet.Cells(ii, 8) = NewBlockCount
  41. '
  42.       xlSheet.Cells(ii, 9) = .ObjectName
  43.       xlSheet.Cells(ii, 10) = .Handle
  44.       xlSheet.Cells(ii, 11) = ThisDrawing.Blocks(BlockCount).Name
  45.       xlSheet.Cells(ii, 12) = ThisDrawing.Blocks(BlockCount).Count
  46.       ii = ii + 1
  47.    
  48.       'Debug.Print .ObjectName, .Handle, BlockCount,
  49.     End With
  50.             If EntityInBlock.ObjectName = "AcDbMText" Then
  51.                 '将文字内容替换掉标注对象的文字内容
  52.                 Dimension.TextOverride = EntityInBlock.TextString
  53.                 'Exit For
  54.             End If
  55.         Next
  56.     End If
  57.     '删除复制的标注对象
  58.     CopyDimension.Delete
  59.     FixDimText = Dimension.TextOverride
  60. End Function
  61. '将图形中所有的标注对象锁定文字内容
  62. Sub FixAllDim()
  63. '
  64.     Dim xlSheet As Worksheet
  65.     Set xlSheet = ReturnxlSheet
  66.     xlSheet.Range("a:z").ClearContents
  67. '
  68.    
  69.     Dim SSet As AcadSelectionSet
  70.     On Error Resume Next
  71.     '建立选择集
  72.     ThisDrawing.SelectionSets("mccad").Delete
  73.     Set SSet = ThisDrawing.SelectionSets.Add("mccad")
  74.     '建立过滤器
  75.     Dim fType(0) As Integer
  76.     Dim fData(0) As Variant
  77.     fType(0) = 0
  78.     fData(0) = "DIMENSION"
  79.     '选择过滤出图形中所有的标注对象
  80.     SSet.Select acSelectionSetAll, , , fType, fData
  81.     Dim i As Long
  82.     For i = 0 To SSet.Count - 1
  83.         '锁定标注的文字内容
  84.         FixDimText SSet(i)
  85.     Next
  86. End Sub

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

本版积分规则

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

GMT+8, 2024-11-26 07:44 , Processed in 0.167507 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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