CAD设计论坛

 找回密码
 立即注册
论坛新手常用操作帮助系统等待验证的用户请看获取社区币方法的说明新注册会员必读(必修)
查看: 1303|回复: 4

[求助] 菜鸟学习VBA二次开发遇到的弱问题……

[复制链接]
发表于 2007-6-10 16:16 | 显示全部楼层 |阅读模式
最近开始看CAD的二次开发……但是实践的时候遇到一个问题,每次出现ThisDrawing都会出错
; y5 v  T+ }9 W7 M5 t- hName 'ThisDrawing' is not declared.        % L9 T( e3 H4 }4 Y& O

& V; J- G0 x+ |1 d- d下面是在网上原样copy的教学程序,可是却在所有的thisdrawing处出错,各位大侠帮忙解决一下吧……many thx……% X" j  G8 ?. q9 G4 I! \$ o& _  T% L7 D) w
因为我是菜鸟,可能里面有一些非常弱智的问题……大家见笑了! a, J* w+ }9 I# Z9 V8 V- M; _
* Q+ i9 G. [. F
——————————————
! s$ d- ^. c& i0 [/ z5 n: p' L6 d- I
Option Explicit On- d! }9 _) m5 [' X2 X, f
Imports AutoCAD
- i. O+ J$ M  e  c  m) q5 F( P4 ^4 ^8 j- L* x1 x
Public Class Form1
# }9 [' s2 O  N& D$ R1 f( _# |    Sub Ch2_ConnectToAcad()
( i+ ?3 a, b+ @2 f0 V        Dim acadApp As AcadApplication" D& B0 e$ {/ A2 u
        On Error Resume Next
4 E* O! D5 r2 S( D5 j. q- }2 {
4 C# V! S. Y5 F/ v  e        acadApp = GetObject(, "AutoCAD.Application")
' z4 X8 ]9 M7 e: ?# D        If Err.Number Then* @+ }8 Z7 k6 i* {* H) g' ~
            Err.Clear()
3 z, R7 s3 I! U( ?            acadApp = CreateObject("AutoCAD.Application")
" Y5 o5 f% i! i4 r            If Err.Number Then
9 u* s6 T2 e3 c. w2 }1 U' D                MsgBox(Err.Description)
% @6 ]2 C; {' E2 M) N                Exit Sub
# s# ?  i4 T+ \# W            End If! d! G: Y, K+ ]  q/ j( c* `2 F4 {& s
        End If  |1 O2 J6 u, l* S8 F+ j: `% i" @
        MsgBox("Now running " + acadApp.Name + _
) T5 I: S! T4 I; L( t: Q7 S; x) Q        " version " + acadApp.Version)
; D2 |  i" c7 y' w7 ~" I: R
& c9 J! J" [! P0 O/ ?5 A    End Sub
$ f- F$ x6 U9 T( X1 H
) N$ f" N. Y9 _+ v8 N9 y
+ u6 P) C# g% o& U1 t# X4 I    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
$ h6 ^- h/ v! q7 |, F; t7 }- M) X& I8 F7 p3 k

( e" ]  W2 y% a% W8 T1 j% p$ m% ?
4 {9 g+ {% ?* c1 F. [; |6 u    End Sub
- u- X7 `) i0 ^0 i/ b2 e
) w8 J! L7 q7 R$ E) }& Q7 I' D+ C2 w% M# }6 S- Q
! {" Q. J7 S7 i
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
1 s- G! }3 m) a6 E6 }3 w9 d/ b# W( E8 ?  H3 j6 D% ?
        Dim Arc As AutoCAD.AcadArc( V( y3 h3 t: K. P
        Dim Pnt As Object7 n  R% A  M( U0 s! k7 B% v
        Err.Clear()4 g: x: P9 J% v: |: H/ @" _0 y
        On Error Resume Next
( ~  E! ~3 E/ ]3 H2 l: j
( Y5 {7 L: {$ v9 _6 e        '选择圆弧7 g$ ~4 i" L9 z( j
        ThisDrawing.Utility.GetEntity(Arc, Pnt, "请选择圆弧:")
6 C+ \( _( u* ^- q        If Err.Number <> 13 And Err.Number <> 0 Then Exit Sub
* b! h; Q! w* r% g$ ?' S! ~# M8 @0 Y. G) C6 e7 d+ G
        Do Until Arc.ObjectName = "AcDbArc"
- K5 h( \' D7 F* |5 M            Err.Clear()3 [' `+ e- K$ n; c5 m: I$ z. P
            ThisDrawing.Utility.GetEntity(Arc, Pnt, "你所选的不是圆弧,请重新选择圆弧:")$ H: [1 c/ m7 N4 m8 ^3 X
            If Err.Number <> 13 And Err.Number <> 0 Then Exit Sub
! h4 e, o. A" Z5 k        Loop; c( p& [1 q) X% f

( x# m  V2 s( P  k# u, ]        '获取圆弧各属性0 j" H4 f, N4 u) m
        Dim Leng As Double
# G) W# Z, J# i9 F" L6 t7 Z0 q        Dim SPnt As Object
8 m4 \- u  @& p( ?: J* `, B0 {        Dim EPnt As Object
+ m7 U& }% q' X) ]        Dim CPnt As Object
! D8 t5 O' V! L- f  X! ~        Leng = Arc.ArcLength3 Z- D& }1 }( |' j3 E9 T% ^) z
        SPnt = Arc.StartPoint3 j2 k4 U9 D8 l
        EPnt = Arc.EndPoint: T& @1 D' P6 ^3 G+ e
        CPnt = Arc.Center, V& g, x$ F" G& J  \' H
0 B2 o0 h1 T$ B5 q
        '选择标注点
) R" t0 W& i$ I1 y        Dim PntforDim As Object- ?5 W2 Y7 x, }+ a4 L( p0 M/ Z
        PntforDim = ThisDrawing.Utility.GetPoint(, "选择标注点位置:")! B* k; }; u2 r
$ Q$ ~, x. D% [4 L
        '对圆弧进行角度标注/ ~  q2 W! ?  [" [
        Dim DimAng As AutoCAD.AcadDim3PointAngular1 j# G1 \0 ?4 ^# k5 J
        DimAng = ThisDrawing.ModelSpace.AddDim3PointAngular(CPnt, SPnt, EPnt, PntforDim): H: @6 H! m1 ?! K

( c$ s- f$ s' d( Y. b        '获取角度标注的精度控制(小数点位)3 x% P4 C* H( G3 ^  i2 o4 f* I4 i! n
        Dim FormatDot As Integer
# M: q. l  C3 D  u* m9 x5 E        Dim FormatTxt As String; O9 Z* F% d. X) ~5 O; ?) H* G1 ?  \
        FormatDot = DimAng.TextPrecision
+ n* r& D! `+ ~1 g7 p        '转换为精度控制格式' F2 B) ]9 C0 F& x
        FormatTxt = "0."
: F( U& Y/ R; V6 R4 t0 m: k        Dim I As Integer
1 v) g! c' i2 `- \        For I = 0 To FormatDot" b' M/ n' C" \9 B
            If I > 0 Then
4 `7 J5 m9 ]9 L4 C! b                FormatTxt = FormatTxt & "0"1 K" |( j, @  h6 O$ W
            End If& O7 p' `8 g; f1 b) T% E7 j, X
        Next3 Y" K- O2 C7 A' U! p. M2 b
        '更改角度标注的文字内容
/ w0 A: w4 _* h4 c9 A        DimAng.TextOverride = Format(Leng, FormatTxt)* k2 \! I* E9 o% V( v
1 K# m* [9 p8 W: I9 q% k
    End Sub: S7 M! S: @; F

4 V4 w( ~1 q5 f' X6 E8 X
& o: T# U4 ], q7 F5 v" K& r
) X! }2 d* M+ ^. \' @' |End Class
 楼主| 发表于 2007-6-10 17:41 | 显示全部楼层
……没人理我嘛……
发表于 2007-6-11 18:59 | 显示全部楼层
都是英语看不懂
发表于 2008-5-19 13:51 | 显示全部楼层
哈哈
发表于 2008-10-17 11:55 | 显示全部楼层
看不懂哦 
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关于|免责|隐私|版权|广告|联系|手机版|CAD设计论坛

GMT+8, 2026-2-25 17:25

CAD设计论坛,为工程师增加动力。

© 2005-2026 askcad.com. All rights reserved.

快速回复 返回顶部 返回列表