最近开始看CAD的二次开发……但是实践的时候遇到一个问题,每次出现ThisDrawing都会出错( c4 g. w' e7 `. y$ h' L
Name 'ThisDrawing' is not declared.
/ T A& c6 h5 n" @; Z# r3 {/ |) q8 K( q6 W- Y. v6 ?: D# u
下面是在网上原样copy的教学程序,可是却在所有的thisdrawing处出错,各位大侠帮忙解决一下吧……many thx……3 l2 X$ l, T3 |/ _# J$ o1 l5 j% z6 d$ a
因为我是菜鸟,可能里面有一些非常弱智的问题……大家见笑了
% t# Z$ q3 e5 y e, J& g; Y) [* O! b1 E8 c$ J! \9 e" K1 Y
——————————————! X8 h- l; G8 a/ W! I
Option Explicit On# ^- P; W8 _2 U6 h8 K, h; z, Z
Imports AutoCAD$ L q+ F0 v# ~1 k+ D: {" S
: t4 S: Y! ^4 |
Public Class Form1
5 z/ T% a4 V# p" ~7 l Sub Ch2_ConnectToAcad()
' P2 V3 G7 N% B# d Dim acadApp As AcadApplication
' c' V8 b' P9 C! v On Error Resume Next! Q& E. b- ^- \2 d1 B. x. h
1 r( a& l5 I4 N4 e! B% ]6 c& t
acadApp = GetObject(, "AutoCAD.Application")
( m$ u& [7 L- @) I1 K; S; V" d If Err.Number Then& d9 Y1 d' M! O3 B6 H% N
Err.Clear()/ x, |! ^8 m, R7 U1 z+ E% _, V5 C
acadApp = CreateObject("AutoCAD.Application")
3 P! ]! q' P$ q( v If Err.Number Then
) z5 {0 U! K0 |: b0 V7 s# { MsgBox(Err.Description)/ L" `1 \" ]% P6 l( v
Exit Sub- n' C4 S$ n; T$ o0 j5 t' X. I# B
End If
) N7 q" q7 p+ a7 N9 c L' j End If
$ r0 d4 ~- ~$ e MsgBox("Now running " + acadApp.Name + _" G. k$ @& v4 m. l4 r0 Y
" version " + acadApp.Version)
; { V- v @8 w& ?3 q F( F, P
Y$ p, c( B" \' b5 p End Sub
, n k0 `; R. ^/ F/ M$ h( A! v. d0 ]3 a0 G) ^2 w
7 q# ^- z. e- M5 M' ]
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load% N3 _- P: I& |* L2 G
! v t) K' P; b2 j9 V
+ U. c& |0 }0 J( J1 T' A8 x) F' S
End Sub3 M& g- c8 L* q: M( i: B
) e' _' ^7 c" h5 C- g u
: z8 q# O4 f1 ? o6 t1 t
; Y8 ~; g' F8 ?( ]% u( O7 O$ @
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
& k. \3 Y, V0 F9 K& o6 o/ R! n# s* O* P# h5 f# u0 q% E0 \
Dim Arc As AutoCAD.AcadArc' V3 ^: T9 e1 ?' |+ M7 p3 P1 r
Dim Pnt As Object
( e8 E# b) Q e, H5 A! y k! [ Err.Clear()7 q$ ~6 k% k! ]! k/ {4 v4 h! |
On Error Resume Next
( D5 K; [0 E% y/ A7 H7 G0 U# {* Y" R; f
'选择圆弧
; ^( N; ]$ z: y, G" Z9 x ThisDrawing.Utility.GetEntity(Arc, Pnt, "请选择圆弧:")1 z5 Q9 k: g7 ^: Y. V7 h8 M
If Err.Number <> 13 And Err.Number <> 0 Then Exit Sub
3 g1 j) W4 Z% g3 j6 C* Y8 u4 _! y; p3 D
Do Until Arc.ObjectName = "AcDbArc"( T' W) @7 q; R4 A8 D" V8 X* Q5 L
Err.Clear()
' W9 A r+ m, |; V7 K. M+ g: x$ c ThisDrawing.Utility.GetEntity(Arc, Pnt, "你所选的不是圆弧,请重新选择圆弧:")
+ J7 p& k. W' } h: A If Err.Number <> 13 And Err.Number <> 0 Then Exit Sub/ @' K K# y1 y9 v* k& w: p
Loop4 u6 Y4 S0 P1 r6 r' B- O
8 B" K* G, d' F9 x) ?
'获取圆弧各属性0 l4 a4 c1 b/ ]6 ?% p6 H, U: }
Dim Leng As Double
; b7 [# h v% S# ]; h# i Dim SPnt As Object2 G8 _. s! T8 [* [3 X
Dim EPnt As Object
. c- M% g1 \7 I. e Dim CPnt As Object7 Q, H% `- D: q* R( Y- O2 r) z' D _
Leng = Arc.ArcLength9 G2 z* _; f$ `' Q
SPnt = Arc.StartPoint
7 Y: x9 w" a) @- ^' a! M2 Y EPnt = Arc.EndPoint: o) Q3 `3 \, v1 M7 [
CPnt = Arc.Center
/ f4 i1 p6 g/ D: N4 S/ ~5 w
% [2 L0 O/ }5 e3 u% X2 \( h. b '选择标注点
- U8 X1 X% Q& Z9 q( z Dim PntforDim As Object
) k0 O( S. c' ^5 `# M3 g4 j( B ^ PntforDim = ThisDrawing.Utility.GetPoint(, "选择标注点位置:")7 E* x- f. a1 U/ B* m0 f: h7 x7 M
0 |3 L5 ?" I5 P
'对圆弧进行角度标注. \( \& B" ? ~) a' K ~ s
Dim DimAng As AutoCAD.AcadDim3PointAngular
. U! ]( o$ C6 X7 }6 D* m DimAng = ThisDrawing.ModelSpace.AddDim3PointAngular(CPnt, SPnt, EPnt, PntforDim)
; P0 [: X2 [: W* y! s7 x$ n4 m# M+ \3 |2 H+ ?
'获取角度标注的精度控制(小数点位). K' I: [% b, B1 j. {
Dim FormatDot As Integer
# e) {3 V8 I, s0 j x Dim FormatTxt As String9 X* q0 D+ g4 n) L
FormatDot = DimAng.TextPrecision
9 A. g9 M9 J3 B* ?1 R6 a. ^ '转换为精度控制格式' U0 X( x c Q+ z$ v2 Q
FormatTxt = "0."- f: D# E8 F B/ t8 N* F1 T
Dim I As Integer% y9 i! ^& W; }+ I& {
For I = 0 To FormatDot& m& q5 o* \! ]2 s0 x2 k' j- v
If I > 0 Then
0 \! u# Y Q: |8 u FormatTxt = FormatTxt & "0"
! V9 Y7 X3 {5 x& u+ ~. k End If3 ~, W9 [; V6 ?+ w: A' K! k3 M
Next0 L' J, g+ ]- Q/ B2 Z/ ]- I
'更改角度标注的文字内容
; Y, Z) [' A" J3 R) r h2 g DimAng.TextOverride = Format(Leng, FormatTxt)) Y6 J1 M/ p+ {* y: I
( ? u0 f2 P6 x2 c/ n2 O" t
End Sub
' n/ M* z. [' ]
. u3 q, _" ?: {) Y8 N" `; U$ s$ r% \* B5 \. S' J" b
! N) C4 a) l' D0 }% x* I1 I; K
End Class |