Connecting vba to lisp

Connecting vba to lisp

Anonymous
Not applicable
509 Views
4 Replies
Message 1 of 5

Connecting vba to lisp

Anonymous
Not applicable
I have a written a lisp that needs linking to vba. My lisp dumps output
information to a csv file. I don't know much about vba, but there's a guy
in our office that can write vba, and he wants to know if he can incorporate
his vba program within my lisp. I reckon thats impossible! Is that right
guys? So how do you connect lisp with vba? Do you need to shell out?
I remember Tony Tanzillo saying recently in one of the posts it's difficult.
However all my information is in the form of strings, which may make it
easier
T.I.A. Russ

(I have put the same post in the customization ng,
but I wanted to see what you guys had to say)
0 Likes
510 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
Hi Kiwi,
I haven't tried to link them yet so unfortunately I'm not the one with the
answers.
But I've seen lots of posts on the subject. Lisp can call a vba sub. Vba
could call a lisp with Send Command. But there's timing problems using that
approach. As a side note, if you're writing with any of the vla functions
you're already writing vba. 🙂 I think it depends on exactly how you need
to link them. If your lisp is just outputting to a text file you could have
vba read the file and do whatever it needed to do with the info. If vba has
to do some work and then give results to lisp then again any stored kind of
information, eg external: text file, database, binary file. or internal:
variable, dictionary, xrecord, xdata, attributes, text entities, etc would
be readable and writable by either language. But getting them (vb and
lisp)to 'run time' mesh together and stay in sync, that seems to be the
difficulty from what people have said. Vba can start the lisp but may not
be able to tell when it's done running or when information has been set and
is ready to read, if it tries to retreive some value back from the lisp. if
that makes any sense. You may need to be a little more specific what you
want to do. the pros here will definitely offer the specific solution or
point the way. or you and your co-worker could do a mind-meld and then
you'd both know both languages....frightening...
:-) you can do it! Have fun. Mark

Kiwi Russ wrote in message
news:DAEFD0042A08F66C2FC3A75F67BF76C0@in.WebX.maYIadrTaRb...
> I have a written a lisp that needs linking to vba. My lisp dumps output
> information to a csv file.
you could also write it to a dictionary which vba could then read?

I don't know much about vba, but there's a guy
> in our office that can write vba, and he wants to know if he can
incorporate
> his vba program within my lisp. I reckon thats impossible! Is that right
> guys? So how do you connect lisp with vba? Do you need to shell out?
> I remember Tony Tanzillo saying recently in one of the posts it's
difficult.
> However all my information is in the form of strings, which may make it
> easier
> T.I.A. Russ
>
> (I have put the same post in the customization ng,
> but I wanted to see what you guys had to say)
>
>
>
0 Likes
Message 3 of 5

Anonymous
Not applicable
Hi Russ,
There are a couple of articles on our site covering this subject. Read
"Data Exchange with VBA and LISP" and "Writing hybrid apps". And as always,
post any specific questions here and I'm sure that someone will be able to
help.
--
Bobby C. Jones
www.AcadX.com


"Kiwi Russ" wrote in message
news:DAEFD0042A08F66C2FC3A75F67BF76C0@in.WebX.maYIadrTaRb...
> I have a written a lisp that needs linking to vba. My lisp dumps output
> information to a csv file. I don't know much about vba, but there's a guy
> in our office that can write vba, and he wants to know if he can
incorporate
> his vba program within my lisp. I reckon thats impossible! Is that right
> guys? So how do you connect lisp with vba? Do you need to shell out?
> I remember Tony Tanzillo saying recently in one of the posts it's
difficult.
> However all my information is in the form of strings, which may make it
> easier
> T.I.A. Russ
>
> (I have put the same post in the customization ng,
> but I wanted to see what you guys had to say)
>
>
>
0 Likes
Message 4 of 5

Anonymous
Not applicable
If you want to use data in your VB application that is set with setq in LISP, you can use a not documented object called VL.Application. This only works when Autocad is running and some Lisp program was running (to startup the Lisp subsystem). It is also simple to start Lisp programs from VB (e.g. through sendcommand). So it might be useful to consider to use a VB main which calls Lisp.

Below an object that handles the Lisp-connection:

Private VL As Object ' variable for lisp interface object

' This function returns the value of a Lisp symbol.
' The Lisp symbol can be set in Lisp like: (setq x 1234)
Public Function GetLispSym(symbolName As String) As Variant
Dim sym As Object
' Get the Lisp symbol 'symbolName'.
GetLispSym = vbEmpty
If VL Is Nothing Then Exit Function
Set sym = VL.ActiveDocument.Functions.item("read").funcall(symbolName)
GetLispSym = VL.ActiveDocument.Functions.item("eval").funcall(sym)
End Function

' This function gets a Lisp list
' and put its elements into a
' Variant array.
' The list can be something like:
' (100 1.234 "string")
Public Function GetLispList(symbolName As String) As Variant
Dim sym As Object
Dim list As Object
Dim items As Long
Dim item As Variant
Dim i As Long
GetLispList = vbEmpty
If VL Is Nothing Then Exit Function
' Get the Lisp symbol 'symbolName'.
Set sym = VL.ActiveDocument.Functions.item("read").funcall(symbolName)
Set list = VL.ActiveDocument.Functions.item("eval").funcall(sym)
' Get the number of elements in this list.
items = VL.ActiveDocument.Functions.item("length").funcall(list)
ReDim VarItems(0 To items - 1) As Variant
' Get every item from the list.
For i = 1 To items
item = VL.ActiveDocument.Functions.item("nth").funcall(i - 1, list)
VarItems(i - 1) = item
Next
GetLispList = VarItems
End Function

' This function creates a new Lisp symbol 'symbolName'.
' It gets the value specified by 'value'.
Public Sub PutLispSym(symbolName As String, value As Variant)
Dim sym As Object
If VL Is Nothing Then Exit Sub
Set sym = VL.ActiveDocument.Functions.item("read").funcall(symbolName)
VL.ActiveDocument.Functions.item("set").funcall sym, value
End Sub

' This function creates a new Lisp list
' and assigns it to the symbol 'symbolName'.
' The 'values' parameter has to contain
' an array of variants, and this array
' is converted to the Lisp list:
' Array: "VBA" 100 1.234
' List: ("VBA" 100 1.234)
Public Sub PutLispList(symbolName As String, values As Variant)
' Initialize the list using the first value.
Dim list As Object
Dim newList As Object
Dim item As Long
If VL Is Nothing Then Exit Sub
Set list = VL.ActiveDocument.Functions.item("list").funcall(values(0))
' Append the other items
For item = LBound(values) + 1 To UBound(values)
' Create a new list for the next item...
Set newList = VL.ActiveDocument.Functions.item("list").funcall(values(item))
' ...and append it to the existing list.
Set list = VL.ActiveDocument.Functions.item("append").funcall(list, newList)
Next
' Assign the new list to 'symbolName'
Dim sym As Object
Dim res As Object
Set sym = VL.ActiveDocument.Functions.item("read").funcall(symbolName)
Set res = VL.ActiveDocument.Functions.item("set").funcall(sym, list)
End Sub

Private Sub Class_Initialize()
' Get the VisualLisp Automation interface
Set VL = Nothing
On Error Resume Next
Set VL = CreateObject("VL.Application.1")
End Sub

Private Sub Class_Terminate()
Set VL = Nothing
End Sub
0 Likes
Message 5 of 5

Anonymous
Not applicable
Many thanks to the replies. Now I am fairly confident I that I can complete
the project.
I may have a few specific questions later regarding this vba thingy.
cheers Russ
0 Likes