The first three dialogs, similar to the above, are standard VBA message boxes, and the fourth the AutoLISP alert box. By using the Visual Lisp "eval" method, we were able to "call" a standard VBA function from within Visual Lisp.
Let's get a bit more clever now, and try and pass information backwards and forwards between Visual Lisp and VBA.
Open the VBA Editor and create a new Project. Insert a UserForm and add a TextBox and two command buttons, retaining their default names. Your UserForm should look something like this :
Now add the following coding to the the Click events for the OK and Cancel buttons :
Private Sub CommandButton1_Click()
ThisDrawing.SetVariable "USERS1", TextBox1.Text
End
End Sub
'--------------------------------------------------------
Private Sub CommandButton2_Click()
End
End Sub
|
Save you Project as "Testdial.dvb".
Now open Notepad and copy and paste the following :
(defun c:testdial ()
(vl-load-com)
(setq applic (vlax-get-acad-object))
(if (findfile "testdial.dvb")
(progn
(vl-vbaload "testdial.dvb")
(vla-eval applic "userform1.show")
(alert (strcat "You entered : " (getvar "users1")))
);progn
(alert "\nCannot find DVB file")
);if
(princ)
);defun
(princ)
|
Load and run "Testdial.lsp". A dialog like this should appear :
Enter something into the TextBox and select "OK".
An alert box like this should appear:
This is what happened :
-
First, we loaded and called the VBA dialog.
-
Secondly, we entered the information.
-
Still in VBA, we stored the information into a User system variable.
-
We then closed the dialog.
-
Back in Visual Lisp, we retrieved the information from the User system variable and displayed it in an AutoLISP alert box.
On the next page, we'll have a look at a more practical use for this procedure.
|