Exchange Forum > ActiveX and VBA
Vlax.cls for VBA and AutoLISP apps.
Page 1 of 7
1 2 3 4 5 6 7
Vlax.cls for VBA and AutoLISP apps.

#1

Nugent
Join Date:
10-05-2007
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.
 
VlaxExample1.lsp code in VE1 shortcut
Code:
(defun c:VE1 (/ Entity Entitylist EntitySelect TextHeight TextValue)
  (if (setq EntitySelect (entsel "\nSelect text to edit and change height: \n"))
    (if (= (cdr (assoc 0 (entget (car EntitySelect)))) "TEXT")
      (progn
        (setq Entity (car EntitySelect))
        (setq Entitylist (entget Entity))
        (setq TextValue (cdr (assoc 1 Entitylist)))
        (setq TextHeight (cdr (assoc 40 Entitylist)))
        (command "vbaload" "VlaxExample1.dvb")
        (command "vbarun" "thisdrawing.Main")
        (command "vbaunload" "VlaxExample1.dvb")
        (setq Entitylist (entmod (subst (cons 1 TextValue) (assoc 1 Entitylist) Entitylist)))
        (setq Entitylist (entmod (subst (cons 40 TextHeight) (assoc 40 Entitylist) Entitylist)))
        (entupd Entity)
        (princ "\nObject updated.")
      )
      (princ (strcat "\nObject selected was " (cdr (assoc 0 (entget (car EntitySelect))))))
    )
  )
  (princ)
)
VlaxExample1.dvb code in frmVlaxExample1
Code:
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
 



Attachments  VlaxExample1.lsp    VlaxExample1.dvb    VLAX.cls  
Vlax.cls for VBA and AutoLISP apps.

#2

Dante
Join Date:
08-13-2007
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?
Vlax.cls for VBA and AutoLISP apps.

#3

Nugent
Join Date:
10-05-2007
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.
Vlax.cls for VBA and AutoLISP apps.

#4

ML0940
Join Date:
12-14-2007
Hi Nugent
 
I am very interested in this code:
 
In AutoLISP:
(setq TextString “Hello World”)
In VBA:
Code:
  Dim VL As New VLAX
  txtTextString.Text = VL.GetLispSymbol (“TextString”)
  VL.SetLispSymbol “TextString”, txtTextString.Text
In AutoLISP:
(princ TextString)
 
I set the variable TextString in ACAD to "Hello World"
 
However, in VBA, I am getting a Problem loading Application Error
 
All I am trying to do is pass the variable from LISP to ACAD but I just don't seem to be having any luck.
 
I did insert the class module.
 
Any ideas?
 
Thank you,
 
Mark
Vlax.cls for VBA and AutoLISP apps.

#5

Nugent
Join Date:
10-05-2007
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
Vlax.cls for VBA and AutoLISP apps.

#6

ML0940
Join Date:
12-14-2007
Hi Nugent
 
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?
 
Any ideas?
 
Thank you,
 
Mark
Vlax.cls for VBA and AutoLISP apps.

#7

Nugent
Join Date:
10-05-2007
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
In AutoCAD:
!ImgName
"NewImage.gif"
Vlax.cls for VBA and AutoLISP apps.

#8

ML0940
Join Date:
12-14-2007
Great!
Thanks Nugent!
 
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
 
Mark
 
autodesk.autocad.customization.vba
Vlax.cls for VBA and AutoLISP apps.

#9

ML0940
Join Date:
12-14-2007
Nugent
The post I sent you is a bit older
 
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
Vlax.cls for VBA and AutoLISP apps.

#10

Nugent
Join Date:
10-05-2007
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
Page 1 of 7
1 2 3 4 5 6 7