Call Lisp from VBA

Call Lisp from VBA

Anonymous
Not applicable
893 Views
2 Replies
Message 1 of 3

Call Lisp from VBA

Anonymous
Not applicable
Is there a way to call a lisp routine from a VBA program?
0 Likes
894 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
mcguirepm wrote:

> Is there a way to call a lisp routine from a VBA program?

You can use SendCommand but you may have synchronize problems as (from
best I remember) it doesn't wait for it to execute.

Also search these groups for VL.Application, but it has it's own set of
problems.

Good Luck, Terry
0 Likes
Message 3 of 3

Anonymous
Not applicable

Terry W. Dotson a écrit :

mcguirepm wrote:



Is there a way to call a lisp routine from a VBA program?



You can use SendCommand but you may have synchronize problems as (from
best I remember) it doesn't wait for it to execute.

Also search these groups for VL.Application, but it has it's own set of
problems.

Good Luck, Terry


Hello,

Try the VLAX class from Franck Okendo :





'VERSION 1.0 CLASS

'BEGIN

'  MultiUse = -1  'True

'End

'Attribute VB_Name = "VLAX"

'Attribute VB_GlobalNameSpace = False

'Attribute VB_Creatable = False

'Attribute VB_PredeclaredId = False

'Attribute VB_Exposed = False

'VLAX.CLS v1.4 (Last updated 8/27/2001)

' Copyright 1999-2001 by Frank Oquendo

'

' Permission to use, copy, modify, and distribute this software

' for any purpose and without fee is hereby granted, provided

' that the above copyright notice appears in all copies and

' that both that copyright notice and the limited warranty and

' restricted rights notice below appear in all supporting

' documentation.

'

' FRANK OQUENDO (THE AUTHOR) PROVIDES THIS PROGRAM "AS IS" AND WITH

' ALL FAULTS. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY

' OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. THE AUTHOR

' DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE

' UNINTERRUPTED OR ERROR FREE.

'

' Use, duplication, or disclosure by the U.S. Government is subject to

' restrictions set forth in FAR 52.227-19 (Commercial Computer

' Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)

' (Rights in Technical Data and Computer Software), as applicable.

'

' VLAX.cls allows developers to evaluate AutoLISP expressions from

' Visual Basic or VBA

'

' Notes:

' All code for this class module is publicly available througout
various posts

' at news://discussion.autodesk.com/autodesk.autocad.customization.vba.
I do not

' claim copyright or authorship on code presented in these posts, only
on this

' compilation of that code. In addition, a great big "Thank you!" to
Cyrille Fauvel

' demonstrating the use of the VisualLISP ActiveX Module.

'

' Dependencies:

' Use of this class module requires the following application:

' 1. VisualLISP



Private vl As Object

Private VLF As Object



'Private Sub Class_Initialize()

'Set vl = ThisDrawing.Application.GetInterfaceObject("VL.Application.1")

' For AutoCAD 2004

'Set vl =
ThisDrawing.Application.GetInterfaceObject("VL.Application.16")

'Set VLF = vl.ActiveDocument.Functions

'End Sub



Private Sub Class_Initialize()

If Left(ThisDrawing.Application.Version, 2) = "15" Then

Set vl = ThisDrawing.Application.GetInterfaceObject("VL.Application.1")

ElseIf Left(ThisDrawing.Application.Version, 2) = "16" Then

Set vl = ThisDrawing.Application.GetInterfaceObject("VL.Application.16")

ElseIf Left(ThisDrawing.Application.Version, 2) = "17" Then

Set vl = ThisDrawing.Application.GetInterfaceObject("VL.Application.16")

ElseIf Left(ThisDrawing.Application.Version, 2) = "18" Then

Set vl = ThisDrawing.Application.GetInterfaceObject("VL.Application.16")



'error occurs

End If



Set VLF = vl.ActiveDocument.Functions

End Sub



Private Sub Class_Terminate()

Set VLF = Nothing

Set vl = Nothing

End Sub



Public Function EvalLispExpression(lispStatement As String)

Dim sym As Object, ret As Object, retVal

Set sym = VLF.Item("read").funcall(lispStatement)

On Error Resume Next

retVal = VLF.Item("eval").funcall(sym)

If Err Then

EvalLispExpression = ""

Else

EvalLispExpression = retVal

End If

End Function



Public Sub SetLispSymbol(symbolName As String, Value)

Dim sym As Object, ret, symValue

symValue = Value

Set sym = VLF.Item("read").funcall(symbolName)

ret = VLF.Item("set").funcall(sym, symValue)

EvalLispExpression "(defun translate-variant (data) (cond ((= (type
data) 'list) (mapcar 'translate-variant data)) ((= (type data)
'variant)(translate-variant (vlax-variant-value data))) ((= (type data)
'safearray)(mapcar 'translate-variant (vlax-safearray->list data)))
(t data)))"

EvalLispExpression "(setq " & symbolName & "(translate-variant
" & symbolName & "))"

EvalLispExpression "(setq translate-variant nil)"

End Sub



Public Function GetLispSymbol(symbolName As String)

Dim sym As Object, ret, symValue

symValue = Value

Set sym = VLF.Item("read").funcall(symbolName)

GetLispSymbol = VLF.Item("eval").funcall(sym)

End Function



Public Function GetLispList(symbolName As String) As Variant

Dim sym As Object, list As Object

Dim count, elements(), I As Long

Set sym = VLF.Item("read").funcall(symbolName)

Set list = VLF.Item("eval").funcall(sym)

count = VLF.Item("length").funcall(list)

ReDim elements(0 To count - 1) As Variant

For I = 0 To count - 1

elements(I) = VLF.Item("nth").funcall(I, list)

Next

GetLispList = elements

End Function



Public Sub NullifySymbol(ParamArray symbolName())

Dim I As Integer

For I = LBound(symbolName) To UBound(symbolName)

EvalLispExpression "(setq " & CStr(symbolName(I)) & " nil)"

Next

End Sub



0 Likes