|
发表于 2011-3-25 12:23:08
|
显示全部楼层
我又想了一下,只用加总平均的办法计算中心点未免有点太单一了.如果增加一个选项,由用户在屏幕上指定中心点会更好些- Dim SS As AcadSelectionSet, Ft(0) As Integer, Fd(0) As Variant, V As Variant, P(2) As Double, A() As Double, I As Integer, J As Integer, D As Double
" K' p" \; \( v+ F0 ^ - On Error Resume Next& O* X3 c) f6 |8 O$ x$ Q
- With ThisDrawing; k. ~! C" n+ e' _+ o; J
- '创建选择集,用于选择所有文字对象0 j6 [1 p" e- W9 N; Q
- Set SS = .SelectionSets.Add("SS")
6 X4 p( [1 e/ g& t( M6 z% i- B V i' e - '定义过滤器为选择单行文字对象$ K; P7 `# ^8 w
- Ft(0) = 0! c- Z2 Q4 L) v o5 Y
- Fd(0) = "TEXT"& K0 _6 o3 {: U# d7 S" i/ @
- '选择所有单行文字对象1 C! p& G( }5 U9 b
- SS.Select acSelectionSetAll, , , Ft, Fd( y- P7 ?" Q: b6 ?6 R8 t3 t
- '当存在单行文字对象时排序和替换/ w3 b( b( [8 l
- If SS.Count > 0 Then
4 m9 W- r; Y! w! s3 z* |5 x9 l - '由用户在屏幕上指定中心点
0 E! |! p! p, d - V = .Utility.GetPoint(, "指定中心点<默认>:")
/ h) ?5 ^% d% Z! X - '如果用户没有取消则排序和替换( I6 R3 U# `. K/ K2 u
- If Err <> -2147352567 Then
+ m3 [* z% C6 }4 J' ^ H - '用户指定了点( ]2 g5 C+ N' J- ~# ^: V
- If Err = 0 Then. ]# P' n0 Z- m, r: o A; u$ r0 w
- P(0) = V(0)0 F# ]! S! G+ i6 q# |9 s6 S: j
- P(1) = V(1)
$ O% M/ D6 V7 j! N - '用户选择了默认2 s, b, @: O+ @& I$ j2 p9 [- X/ ?
- Else
! |7 x$ j$ Y! @5 E - '计算所有单行文字的几何中心
4 B) \. Z& U- O- R3 Y5 v1 P5 c* I - For I = 0 To SS.Count - 17 [- k" ]; H' o! C. l) ]" v
- V = SS(I).InsertionPoint* F" B8 B1 |; F
- P(0) = P(0) + V(0) / SS.Count$ s8 m: _+ L* r* w$ Q
- P(1) = P(1) + V(1) / SS.Count: k+ l% S/ l3 \, m+ u+ L
- Next2 I) R8 p% j7 B, Z6 T
- End If
3 \! K, b: h; c: e8 \. Q - '重定义动态数组下标4 {" w, Y- D, z( ~# f5 [
- ReDim A(SS.Count - 1, 1). V H" I# Y) T* N. ?
- For I = 0 To SS.Count - 1
7 ?0 `6 ]; e+ x- p* e- H - '计算所有单行文字对象相对于中心点的角度,并记录其在选择集中的索引号
- ?, O. |3 s k; @- I# p/ I9 n - A(I, 0) = .Utility.AngleFromXAxis(SS(I).InsertionPoint, P)
6 l* D, L, T: x8 w3 Z7 M - A(I, 1) = I1 Y C0 p/ V0 i, C) B( U i; F
- Next
3 S" e {! @- {" H - '按角度从大到小的顺序排序# `5 `/ i4 c) I& S2 B" W g6 f. w, [
- For I = 0 To SS.Count - 2/ L! b2 d: s! R; t
- For J = I + 1 To SS.Count - 1+ w' `- U9 x" |. B* x1 ^
- If A(J, 0) > A(I, 0) Then5 U2 b. A1 s4 @" z0 q7 m
- D = A(J, 0)4 }/ m& u5 A& l5 w, n3 ?6 w8 Y: o
- A(J, 0) = A(I, 0)! B, q( ]5 _" ?& o5 l
- A(I, 0) = D
& |& D3 h4 G6 ^, Y/ i% N' g1 b( K" ^ - D = A(J, 1)- E* T, [2 ~! Y3 B
- A(J, 1) = A(I, 1)
* U: ~6 r, I1 l. m( r- s% X1 P9 X/ @ - A(I, 1) = D
8 e' t: f5 p3 s - End If0 P- }; V. I8 T
- Next" Z/ K0 o7 h% j
- Next4 N! T2 `6 @+ }. V7 B
- '替换
?) u Q, }! Q e0 i2 ]) V - For I = 0 To SS.Count - 14 `' l N3 Y' ^+ i! W
- SS(A(I, 1)).TextString = I + 1
( a- {5 c* {$ s* y( Z% x8 F2 _ - Next
, Q- [0 ?0 i5 ?; V2 Y - End If
! r6 n3 f! i% @9 q - End If
, I3 z4 n. `! ^% s3 ] - '删除用过的选择集, k! w+ A5 Z ?' S. g
- SS.Delete
4 d! k5 l+ z' _3 s1 a" W. ]# y - End With
复制代码 |
|