|
发表于 2011-8-6 06:51:03
|
显示全部楼层
貌似这是 ACAD 高版本 ActiveX 的一个BUG,到目前为止我们似乎还只能绕开它.
3 U: \# H0 A9 m8 i9 H' g可用的方法大体上有下面几种:
/ l5 `% n' O# b! F, _: u" W! |一.使用 Document 对象的 SendCommand 方法( w! X/ k# i$ f9 x {% G% w
/ ]" r0 z' Y; q" {3 `- ThisDrawing.SendCommand "-insert d:\drawing8.dwg" & vbCr & "2,2,0 1 1 0 "
4 d9 q! i# l: d# P" R# E
复制代码 & {; A; }' r r6 u" s9 j- k
二.首先创建一个用于过渡(中间?辅助?)的新文档,并做为全局变量,用 InsertBlock 方法插入外部块参照.当其它文档需要插入该外部块参照时,从这个过渡(中间?辅助?)文档中拷贝过来,而不再使用 InsertBlock 方法
; A0 g$ g1 t5 x, O9 \下面两段代码中都引用了 ObjectDbx 类库,目的是在后台运行这个过渡(中间?辅助?)文档,以免它在前台添乱.运行下面两段代码前应引用 ObjectDbx 类库
, _1 y0 ]1 o7 Q3 f-
* {* [/ m1 Q X3 n- ? - Dim AxDbDoc As New AxDbDocument, Objs(0) As AcadBlockReference, Inserted As Boolean' @1 n/ }9 i5 |
- 9 M- G8 @' E* m- `
- Sub Sub1(), P" j# @( d ~
- Dim insertionPnt(0 To 2) As Double
6 W- w: \& @9 }% W. z" l8 t( Y - Dim blockRefObj As AcadBlockReference
. M# W! ] w, G- B - Dim V As Variant, P(2) As Double* O" F, u3 l. Y8 h1 y6 k) a
- ( F# F3 F# r) U, j
- If Not Inserted Then
/ O- q% S6 y* X- x Z7 Z - Set Objs(0) = AxDbDoc.ModelSpace.InsertBlock(P, "d:\drawing8.dwg", 1, 1, 1, 0)% b' Y$ r! r, V2 V3 G% s
- Inserted = True9 q! ?- `0 O. Q' T
- End If6 @) k# ]1 o. a7 s5 V8 ?
-
6 h% F( n6 t/ i( W# C - V = AxDbDoc.CopyObjects(Objs, ThisDrawing.ModelSpace)
: q7 j- i0 Z9 ?: @ - Set blockRefObj = V(0)
, f, D4 M% Y3 _$ | - insertionPnt(0) = 2#: insertionPnt(1) = 2#: insertionPnt(2) = 0 ]: d: z* d* } H$ C
- blockRefObj.Move P, insertionPnt9 t& I; N( C( r, q4 g9 W
-
/ i1 B5 `7 S, S# T n% y4 E - ZoomAll
- U# m; Q8 I; K4 w- u) s/ a3 X; Y - End Sub
) A" N% r/ }4 @. c
复制代码 " ^' m8 P& ~: o& G9 F4 K
三.自己编写一段插入外部块的函数,代替 InsertBlock 方法插入外部块
0 r, p4 a2 H$ G3 D-
' `0 C* U, b' U7 c6 x* ^ - Sub Sub2()
$ x) P$ P0 b4 [9 Z6 w7 } - Dim insertionPnt(0 To 2) As Double
) ~1 h/ a6 t5 B C6 t9 p - Dim blockRefObj As AcadBlockReference
( I6 p% Q" I3 x: N2 | - insertionPnt(0) = 2#: insertionPnt(1) = 2#: insertionPnt(2) = 0
$ m/ j0 P: t" O* ]0 u4 S - Set blockRefObj = InsertBlock(ThisDrawing.ModelSpace, insertionPnt, "d:\drawing8.dwg", 1#, 1#, 1#, 0)
) x _6 v7 @, U$ i3 O! J - ZoomAll3 \4 F. Y0 J- p& b
- End Sub
' I, C# q- `2 {. D, F -
9 V) j; b3 q8 s1 n8 j1 g: Q - Private Function InsertBlock(ByVal Block As AcadBlock, ByVal InsertionPoint As Variant, _1 i4 i4 I$ U0 t5 k$ s" }. }% j
- ByVal Name As String, ByVal Xscale As Double, ByVal Yscale As Double, ByVal Zscale As Double, _
8 x X# x( w' l" x - ByVal Rotation As Double) As AcadBlockReference
% ^! C# o- W/ x( i/ i - Dim BlockName As String) K* q( {$ L3 c
- Dim D As New AxDbDocument, E() As AcadEntity, I As Integer, B As AcadBlock, P(2) As Double
. c# `6 ^* Z1 T' A( K: |/ ^ - 8 X6 ]' P8 M9 e9 w x0 |$ F
- On Error Resume Next
0 ]7 A: r5 H2 z+ k -
. S& k4 p2 Y' V - BlockName = Right(Name, Len(Name) - InStrRev(Name, ""))
) I, ]: z) F Y" `. ^ - BlockName = Left(BlockName, InStrRev(BlockName, ".") - 1)6 j1 m1 K3 D4 O, z( q
-
& {0 l! p+ l7 L( f - Set InsertBlock = Block.InsertBlock(InsertionPoint, BlockName, Xscale, Yscale, Zscale, Rotation)
8 i% x9 F I9 t3 T* h -
! B9 W) V, h) `) g1 n - If Err Then( i0 H* U$ m* J; D
- D.Open Name8 h& G0 K, o8 d7 @/ d7 e0 ~9 Z% o
- If D.ModelSpace.Count > 0 Then
" {( W) D/ o- _0 d - ReDim E(D.ModelSpace.Count - 1)
2 b. R9 A/ k! A& [; h1 w7 G7 o1 i - For I = 0 To D.ModelSpace.Count - 1
V4 |% A9 I1 ~; ]% Z. Q' e - Set E(I) = D.ModelSpace.Item(I)
1 |4 c) Q: m( c: l/ g! |! h1 T, A - Next/ p; m7 ^# U k; f% c! k* X/ [
- Set B = Block.Document.Blocks.Add(P, BlockName)* N( g( W3 H% a0 {2 U
- D.CopyObjects E, B
6 e( K: @7 L% y/ V+ Q" ~$ V% l - End If
5 q& v+ @* [3 J3 ^" P( T - Set InsertBlock = Block.InsertBlock(InsertionPoint, BlockName, Xscale, Yscale, Zscale, Rotation)
% A/ g* K; v/ O/ m - End If3 z3 H% ^; c0 T/ Q- n' _3 y
- End Function" n8 [, V8 |# J: Y
复制代码 |
|