最近开始看CAD的二次开发……但是实践的时候遇到一个问题,每次出现ThisDrawing都会出错0 d; M- ]2 X1 b# l" R; L
Name 'ThisDrawing' is not declared. + K8 \! k- ~" B
' D. ~6 g2 U6 R* @" Q8 |# w( Z ?下面是在网上原样copy的教学程序,可是却在所有的thisdrawing处出错,各位大侠帮忙解决一下吧……many thx……
1 h8 _) k; p9 A( T! q/ n因为我是菜鸟,可能里面有一些非常弱智的问题……大家见笑了
1 s1 ~6 [# v1 @ J& z6 g7 n: k1 t) }; i [ J/ P
——————————————8 }; D u5 y7 T x5 ^
Option Explicit On6 W+ b, ~5 h; |8 a# [
Imports AutoCAD
7 ]% j9 ]% E, P* Y( w& d' @9 T$ B" ` @0 }/ v) o# c
Public Class Form1
5 i/ R8 h: V4 W0 c i Sub Ch2_ConnectToAcad(), r/ C: ^+ H9 f& U6 I
Dim acadApp As AcadApplication
1 K- l n/ @# V/ Z% ^1 R5 z On Error Resume Next3 Y" c5 P7 U9 ~1 _- |* ]
, R; R3 ?2 a9 G$ R! N acadApp = GetObject(, "AutoCAD.Application")
# t6 p; p" F8 _6 ^; y If Err.Number Then) V' h4 a7 l1 r5 J
Err.Clear()5 n# ]/ L; \# T# W1 V
acadApp = CreateObject("AutoCAD.Application")
; }2 J- a% @5 f% e8 A+ z4 g" D% h- J2 B If Err.Number Then
9 \9 `' O+ u0 |; H+ | MsgBox(Err.Description)
* M1 A1 w: I" {+ r. ^ Exit Sub
6 X7 Z+ B( k1 {) } End If
! W b0 W+ A/ ?7 S' A End If
$ m; H d$ y" N/ V0 @6 l MsgBox("Now running " + acadApp.Name + _
2 p9 F) C' a* R$ p9 J0 @, @9 N " version " + acadApp.Version)
% T X- R4 u$ }/ Q
7 X; i* f+ f* ] End Sub) N7 a/ T0 |; Z7 F
# |+ X" h+ W4 c+ _1 b
7 A8 w% u/ Q" u6 n; O; _' C6 n Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
8 N k V W3 Z; f8 T$ b! j( w! L! K+ T( f/ X7 k
2 b: s! u$ @2 D: ^+ c9 R" Q; R4 ?6 p4 |+ _
End Sub
, _" o- P0 U7 g) f; d8 q) W k8 Q4 K$ p* ^1 N
# Q. `7 m- |$ k& I( ^- d* _. x; j" P$ ^! w- r
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click# n* {! D/ n7 n
, T9 V$ s8 k7 b/ e* ^ j Dim Arc As AutoCAD.AcadArc- Z# T' v$ H4 } J6 k" `& |0 P5 b
Dim Pnt As Object
- s Z% h0 J" ^6 ] Err.Clear()
; E9 X! X* b4 `2 A/ G G! \5 j1 Q On Error Resume Next/ l8 e! {( r3 ]/ c8 \6 F2 T# Y5 [
" T2 w; o' \) q/ T
'选择圆弧% Q' E& ~% V, G% w+ @$ q
ThisDrawing.Utility.GetEntity(Arc, Pnt, "请选择圆弧:")
. r9 s. L4 Z0 H If Err.Number <> 13 And Err.Number <> 0 Then Exit Sub
# f) F( h" n, }5 i4 ]- Y; [
1 z3 P3 C7 ~! O4 o2 H' w Do Until Arc.ObjectName = "AcDbArc"
3 i& J* f+ p( b# @/ ?- I: q# u, j Err.Clear()
; T6 x8 G, G' X* C3 X3 K6 r2 ] ThisDrawing.Utility.GetEntity(Arc, Pnt, "你所选的不是圆弧,请重新选择圆弧:")8 k- Y1 [2 I) [6 z& u1 ^/ J
If Err.Number <> 13 And Err.Number <> 0 Then Exit Sub, G7 p" M, H0 s5 `
Loop+ d, ?1 `4 C D5 g" o4 u
7 N4 m& A+ P& t '获取圆弧各属性- z. n9 c; z5 A x9 k) d* t b
Dim Leng As Double
5 w9 ]2 x- h# f/ n% U Dim SPnt As Object5 Y' \ Z: N* ^+ f3 v
Dim EPnt As Object+ B s+ h' a4 c# S5 G
Dim CPnt As Object
8 ^ t! S0 S( ^. Q; ? Leng = Arc.ArcLength
. w; {6 \9 F' e+ c) @ SPnt = Arc.StartPoint- U0 t# X U9 k. } p8 t v
EPnt = Arc.EndPoint
, K# Y' s d4 N3 n CPnt = Arc.Center* l. e* j; C# z( f7 X8 U9 Q) x
+ _6 \- ~) b4 v2 ]8 U
'选择标注点
' f$ T) ]. p: [ Dim PntforDim As Object. I9 T S# L1 L, y$ A
PntforDim = ThisDrawing.Utility.GetPoint(, "选择标注点位置:")( g* k+ s+ ?. S% p0 f
. B5 Z- k1 ~6 M9 g* s( C
'对圆弧进行角度标注9 o N# J' f) a4 v
Dim DimAng As AutoCAD.AcadDim3PointAngular
5 W) O% \) h2 m$ S' T3 o) k DimAng = ThisDrawing.ModelSpace.AddDim3PointAngular(CPnt, SPnt, EPnt, PntforDim)
$ ?4 n* ^1 H1 k1 X; }$ U" h! B% U
" S' w( ]' M3 z3 [! w8 } '获取角度标注的精度控制(小数点位)
5 w x8 s: n( [+ p8 U Dim FormatDot As Integer2 x1 M4 y* M% h6 x h# I! U3 g+ C
Dim FormatTxt As String; Z6 Z3 t2 v t- `2 C" d' f
FormatDot = DimAng.TextPrecision; ^* B4 o/ L' U6 ~3 e
'转换为精度控制格式6 o/ d% _; L T: {3 S# c
FormatTxt = "0."
: `4 S4 R {2 g% {/ b Dim I As Integer5 u5 P j" T$ |; W
For I = 0 To FormatDot4 J% s1 h7 ~# | s' O
If I > 0 Then2 ^. F4 \( A3 Q) a; W! l* j4 _7 F
FormatTxt = FormatTxt & "0"2 U- W4 T9 m8 J. I- V* d
End If
0 s8 W0 `, N; G0 U& W Next1 A! G$ a4 `2 J. I
'更改角度标注的文字内容
/ B0 A# j) L1 y! @# ` DimAng.TextOverride = Format(Leng, FormatTxt)) r4 d8 ^0 l, J" b
' b9 @5 y& u9 f9 W
End Sub
6 P5 a2 |& [" ?' ~0 W( L
7 y- s; t$ q9 Q, K: g% E, I! N" Q# V" g
% A$ x& X, J& G! w$ g; f: u
End Class |