|
发表于 2010-9-1 21:07:20
|
显示全部楼层
有个问题:你是要查找名为"属性块"的块参照,还是要查找带有属性的块参照?' H- [4 q7 u' b% f) F: b
如果是前者,上面的代码就可以了.如果是后者,要用下面的代码
5 P& |& y& B, }$ [: `- Sub A()
0 _# p' B/ W3 E! [/ s/ L4 v$ ^7 o - Dim E As AcadEntity, BR As AcadBlockReference, B As Boolean, Atts As Variant
0 t1 w- D) h, R" { |2 t - For Each E In ThisDrawing.ModelSpace
. o, X( C+ h+ m( y, |- l - If E.ObjectName = "AcDbBlockReference" Then3 h6 r1 `4 Q7 J# K# ^# B
- Set BR = E7 s* L* I. F% S! n% v
- Atts = BR.GetAttributes$ y" o+ ~# M# w# l: B8 A
- If UBound(Atts) >= 0 Then
. j( g7 j5 m- l. B - B = True3 {8 n( G9 W, b# i6 S3 L* T
- Exit For2 F( \* v! M. ^8 [/ P4 V
- End If( l% x$ Y% c. t2 M* P
- End If
. [! @. L2 o7 Q" B - Next
, H% T' @+ X* a- j. G- t - If B Then
4 g% f6 U5 u. @7 l - MsgBox "存在"5 A/ S+ Z: H0 C% e( a% a
- Else
+ \7 B, t$ b; s& M - MsgBox "不存在"4 m8 E9 z3 `( D( n, w, e
- End If
1 q/ o2 i) f" k* `6 F - End Sub8 s$ O# _$ b4 y2 ?) T) r
复制代码 先声明一个变体变量,用块参照对象的"GetAttributes"方法获得块参照对象的属性数组并存放在这个变体变量中,再检查这个数组的下标,如果是-1则说明数组为空,该块参照对象没有属性;如果数组下标大于或等于0,则说明该块参照有属性. |
|