I’ve been looking into Vlax.cls by Frank Oquendo for passing variables between AutoLISP and VBA. In the attached example program I’m passing the text value and height to VBA, and then changing the values in a VBA form. The program then returns back to AutoLISP and updates the text value and height. Keep in mind that the concept is more important than the example program.
The basic method is as follows.
Code:
In AutoLISP:
(setq TextString “Hello World”)
In VBA:
Dim VL As New VLAX
txtTextString.Text = VL.GetLispSymbol (“TextString”)
VL.SetLispSymbol “TextString”, txtTextString.Text
In AutoLISP:
(princ TextString)
To include Vlax.cls in your VBA project, select Import File… from the top File menu, then browse and select the Vlax.cls file.
There are other functions and methods in Vlax.cls. These are the only two that I’ve had a chance to look into so far.
Your comments and other examples are welcome.
Option Explicit
Private Sub UserForm_Initialize()
Dim VL As New VLAX
Dim dblVal As Double
Dim strVal As String
strVal = VL.GetLispSymbol("TextValue")
dblVal = VL.GetLispSymbol("TextHeight")
txtTextValue.Text = strVal
dblTextHeight.Text = CStr(dblVal)
txtTextValue.SetFocus
End Sub
Private Sub cmdOK_Click()
Dim VL As New VLAX
VL.SetLispSymbol "TextValue", txtTextValue.Text
VL.SetLispSymbol "TextHeight", CDbl(dblTextHeight.Text)
Unload Me
End Sub
Private Sub cmdCancel_Click()
Unload Me
End Sub
Nugent,
This is a very cool alternative for passing variables back and forth between VBA and AutoLISP. I have a question that maybe you can help me with. When I run your example program I'm not getting the error message "Execution error" that I get when I run my BorderInfo program. Do you have any idea what might be causing this?
In your BorderInfo program I replaced all your “End” commands with “Unload Me” and the error message does not appear. There is a problem if the attribute for COUNTRY is not one of the items in the VBA cboCountry.List.
Mark,
I should have explained it in more detail. I'm new to VBA also.
That's why I like the concept of this VLAX.cls function.
Here's how it works on my computer.
In AutoCAD on the command line type:
(setq TextString "Hello World")
In VBA from the top File menu, select Import File, and browse and select the VLAX.cls file.
In the ThisDrawing code area paste the following code.
Run the VBA code then toggle back to AutoCAD and on the command line type:
!TextString or (alert TextString)
It should return "I said Hello World!"
Code:
Option Explicit
Private Sub Test()
Dim VL As New VLAX
Dim strVal As String
strVal = VL.GetLispSymbol("TextString")
MsgBox strVal
strVal = "I said Hello World!"
VL.SetLispSymbol "TextString", strVal
End Sub
I am the opposite;
I am not new to VBA but I am not really familiar with LISP or VLISP.
On Friday I did finally figure out what you were doing.
Using THe VLAX Class Module, I was able to successfully send a variable from VBA to ACAD; I validated that by typing !Myvariablename at The ACAD Command Line and it worked
I was not able to retreive a variable (that I created) from ACAD in VBA.
So, In ACAD, I typed (setq imgname as "Test.tif")
At the command line, I type !imgname and it returns Test.tif
In VBA, I tried using the getvarible method:
Imgnme = ThisDrawing.GetVariable("Imgname")
but
I am getting an error message, Error getting system variable
So, it looks like with this method, I can only retrieve native ACAD system variables.
As opposed to using this long VLAX Class Module, I would like to do something like this:
Code:
Sub LispToVBA()
Dim VL As Object
Dim strText As String
strText = "Imgname"
Set VL = CreateObject("VL.Application.16")
'This does not work
'VL.GetLispSymbol strText
Msgbox strText
End Sub
In this example, VBA is effectively connecting to VLISP but I do not know The VLISP command (method) needed to get the variable from ACAD.
If you look at the above code, I did try The GetLispSymbol method but that is not working either?
Mark,
I know you mentioned that you prefer not to use the VLAX.cls module, but I think you have to use the VLAX.cls module for this to work. I just ran the following two with no errors.
Lisp2VBA example
In AutoCAD:
(setq ImgName "Test.tif")
In VBA:
Code:
Sub Lisp2VBA()
Dim VL As New VLAX
Dim strVal As String
strVal = VL.GetLispSymbol("ImgName")
MsgBox strVal
End Sub
VBA2Lisp example
In VBA:
Code:
Sub VBA2Lisp()
Dim VL As New VLAX
Dim strVal As String
strVal = "NewImage.gif"
VL.SetLispSymbol "ImgName", strVal
End Sub
That is great that it works but I am sure there is a way to do it without The VLAX Class. However, you will still need to use a function(s) that are probably already incorporated in The VLAX class I'm sure.
Take a look at this post and tell me what you think.
I was playing with it, then I got pulled away
I'm sure you have a later version of VLISP then that which is in the example. I have V 16
Ex:
Code:
Sub Test ()
Dim VL As Object
'Get the VisualLisp Automation interface
Set VL = CreateObject("VL.Application.16") 'Version 16 on my computer
'Getting symbols and lists from Lisp
' Get the value of the Lisp symbol 'a'.
' Use (setq a 1234) in Lisp to set it.
a = GetLispSym("a")
Debug.Print "symbol a is: " & a
Mark,
I couldn't get your code to work until I commented out and changed a few things. Thanks for the link info.
I'll take a look at it after work.
Code:
Sub Test()
'Dim VL As Object
Dim VL As New VLAX
' Get the VisualLisp Automation interface
'Set VL = ThisDrawing.Application.GetInterfaceObject("VL.Application.16")
'Set VL = CreateObject("VL.Application.16") 'Version 16 on my computer
' Getting symbols and lists from Lisp
' Get the value of the Lisp symbol 'a'.
' Use (setq a "1234") in Lisp to set it.
a = VL.GetLispSymbol("a")
Debug.Print "symbol a is: " & a
MsgBox a
End Sub