How to generate a user with VisualBasic

  • Detail

How to generate a user interface module with VisualBasic for the convenience of VisualLISP

the simplest and most effective method is to write an in-process automation client for AutoCAD. For example: a VB ActiveX DLL. This DLL can be loaded from Visual Lisp, VBA, Java (through automation) and ObjectARX in the future. It can be an automatic client of AutoCAD, any automatic server, or multiple servers

1. Start visual basic 5 or 6

2. Select ActiveX DLL in the new project wizard

3. Change the project name to "myproject"

4. There is a default class module in the project. Change its name to "MyClass"

5. Add a function or subroutine to the class module. For example:

'this function takes two arguments, and will return a list of data to the calling function

Public Function MyFn(ByRef arg1 as Integer, ByRef arg2 as Double) As Variant

ow vbModal

' Create a list of items to return to the caller (the items are in this case purely arbitrary)

MyFn = Array(1.0,"Arbitrary string",2)

End Function

(here, myform is a form that you must add to the project. At the same time, remember that myfn is a function that will return a value or a group of values to the calling routine.)

6. Click file -

make L. This will generate a DLL and register it as CO with ▲▼ key head M. (if you want to run this DLL on other machines, you need to first confirm that this DLL is installed and registered on all machines. This usually requires you to generate an installation package with Visual Basic.)

7. If you want to use this DLL from Visual Lisp, you need to define a simple function and load it into AutoCAD:

(defun ShowDialog (/acadapp vbapp retval retlist)

;; required in AutoCAD 2000, not R14

(if (car (atoms-family 1 '("vl-load-com"))) (vl-load-com))

;; get the main AutoCAD application object

(setq acadApp (vlax-get-acad-object))

;; Load VB ActiveX DLL into autocad's address space (e the experimental results of this machine adopt the combined action of tension and torsion to characterize the plastic stress-strain relationship, which is suitable for the insertion force and pull-out force test of various connectors)

;; (setq vbApp (vlax-invoke acadApp "GetInterfaceObject" "Class")

(setq vbApp (vla-GetInterfaceObject acadApp "Class"))

(if (not vbApp)

(princ "nError loading ActiveX DLL.")

(vlax invoke vbapp "myfn"

7; arg1, an integer

1.5; arg2, a'double'




to call the exposed ActiveX methods, enter on the command line:


the following will be returned to autocad:

(1.0 "Arabic string" 2)

you will find that you can pass parameters to VB dialog box and process the return value in AutoCAD. This is very useful for generating Options dialog boxes, because some parameters need to be initialized and the modified values need to be returned to AutoCAD

7. If you want to use this DLL from VBA, you need to add this DLL to the reference. (if you register it with com, it will be added to the list of ActiveX servers. Then it can be referenced by VBA. Otherwise, please browse and select L.)

8. Then you can use the following mechanism to load this internal process ActiveX DLL and call its functions:

sub myvbap to list the new material industry in 1roject ()

dim omyapp as object

dim vreturn as variant

set omyapp = tinterfaceobject ("class"


vreturn = FN (7,1.5)

End Sub

Copyright © 2011 JIN SHI