VBA written earlierCodeIf all are rewritten with. net, it will be hard work and financial, and there is no interest in rewriting. So I used a very lazy method.
Use com to call AutoCAD 200x Type Library and AutoCAD/objectdbx common xx. X Type Library, which defines the thisdrawing object in VBA and can run normally written VBA code without any modifications.
For the form in VBA, you can export it as a VB form first, then use the Upgrade Wizard to upgrade to. net, and make necessary modifications.
Autodesk provides related video tutorials and a tool for exporting VBA to VB. VBA → Vb → VB. NET
Related videos & tools: http://download.autodesk.com/media/adn/VBA_Migration/DevTV_Recording.zip
[VB. NET]
Code
1 Imports Autodesk. AutoCAD. InterOP
2
3 Public Class Class1
4
5 Readonly Property Thisdrawing () As Autodesk. AutoCAD. InterOP. acaddocument
6 Get
7 Return Autodesk. AutoCAD. applicationservices. application. documentmanager. mdiactivedocument. acaddocument
8 End Get
9 End Property
10
11 < Autodesk. AutoCAD. runtime. commandmethod ( " Test " ) > _
12 Sub Test ()
13 Thisdrawing. Utility. Prompt ( " Hello world! " )
14 End sub
15
16 End Class
[C #]
Code
1 Using System;
2 Using System. Collections. Generic;
3 Using System. text;
4 Using Autodesk. AutoCAD. InterOP;
5
6 Namespace Cstest
7 {
8 Public Class Class1
9 {
10 Public Static Acaddocument thisdrawing
11 {
12 Get
13 {
14 Return (Acaddocument) Autodesk. AutoCAD. applicationservices. application. documentmanager. mdiactivedocument. acaddocument;
15 }
16 }
17
18 [Autodesk. AutoCAD. runtime. commandmethod ( " Test " )]
19 Public Void Test ()
20 {
21 Thisdrawing. Utility. Prompt ( " Hello world! " );
22 }
23
24 }
25 }
26
27