How to run a AutoLisp routine in VBA?

How to run a AutoLisp routine in VBA?

Anonymous
Not applicable
1,143 Views
11 Replies
Message 1 of 12

How to run a AutoLisp routine in VBA?

Anonymous
Not applicable
see topic
0 Likes
1,144 Views
11 Replies
Replies (11)
Message 2 of 12

Anonymous
Not applicable
depending on what version of autocad you are using: you can either use the sendcommand or there are a number of acadunsupp (autocad unsupported) files available on the web that have evalLispExpr commands. hope that helps.
0 Likes
Message 3 of 12

Anonymous
Not applicable
Hi,

 

 

The VisualLisp Activex Model is in
VL.tlb

 

 

 

Dim VL As Object

 

Sub test()

 

   ' Get the VisualLisp Automation
interface
   Set VL =
CreateObject("VL.Application.1")
  
  

   '
   ' 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
  
   ' Get the Lisp list 'b'.
Use
   ' (setq b (list 100 1.234 "string"))
   ' in
Lisp to define it.
   b = GetLispList("b")
  
Debug.Print "list b contains:"
   For Index = LBound(b) To
UBound(b)
    Debug.Print b(Index)
  
Next
  
   '
   ' Setting Lisp symbols
and lists
   '
  
   ' Set the Lisp
symbol 'c' to 100.0
   Dim value As Double
   value =
100#
  
   PutLispSym "c", value
  

   ' Create the list
   ' ("VBA" 100
1.234)
   ' and store it in the Lisp symbol 'd'.
  
Dim values(0 To 2) As Variant
   values(0) = "VBA"
  
values(1) = 100
   values(2) = 1.234
  

   PutLispList "d", values
   
End
Sub

 

' This function returns the value of
' a Lisp
symbol.
' The Lisp symbol can be set in Lisp like:
' (setq x
1234)
Function GetLispSym(symbolName As String) As Variant
  

  
   Dim sym As Object
  

   If VL Is Nothing
Then
        Set VL =
CreateObject("VL.Application.1")
   End If
  

   ' Get the Lisp symbol 'symbolName'.
   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")
Function GetLispList(symbolName As String) As
Variant

 

   Dim sym As Object
   Dim
list As Object
  
  If VL Is Nothing
Then
        Set VL =
CreateObject("VL.Application.1")
   End If

 

  
   ' 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'.
Sub
PutLispSym(symbolName As String, value As Variant)

 

   Dim sym As Object
  

   If VL Is Nothing
Then
        Set VL =
CreateObject("VL.Application.1")
   End If

 

  
   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)
Sub
PutLispList(symbolName As String, values As Variant)

 

   ' Initialize the list using the first
value.
  
   Dim list As Object
   Dim
newList As Object
  
   If VL Is Nothing
Then
        Set VL =
CreateObject("VL.Application.1")
   End If
 

   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

 

 

 

Regards,

 

Pierre


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
see
topic
0 Likes
Message 4 of 12

Anonymous
Not applicable
Thanks Pierre, this is what i was looking for
0 Likes
Message 5 of 12

terrycadd
Enthusiast
Enthusiast
I am interested in testing the above code with AutoCAD 2005 and 2006. I get an "ActiveX component can't create object" error when I try to run the code. Also I am having trouble locating the VL.tlb part of the program. I realize that this post was discussed in 2003 and this is 2007. If anyone has a newer version of the code that works on 2005 and 2006, I would appreciate your help.
Thanks,
Terry
0 Likes
Message 6 of 12

Ed__Jobe
Mentor
Mentor
You could put (vl-load-com) in your acad.lsp to automatically load the lib. You also need to update the class name to "VL.Application.16"

You might also want to search this ng for vlax.cls.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 7 of 12

terrycadd
Enthusiast
Enthusiast
Ed,
Thanks for your quick reply. I toggled on the "Visual Lisp ActiveX module" under the "References" top menu, and changed all the "VL.Application.1" to "VL.Application.16" in the code. I tested it on AutoCAD 2005, and it now reports the error, "Run-time error '13': Type mismatch. I then tested it in AutoCAD 2006 and the error returned is, "Object required".
0 Likes
Message 8 of 12

Ed__Jobe
Mentor
Mentor
That code has a few typo's in it. Did you look for vlax.cls?

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 9 of 12

terrycadd
Enthusiast
Enthusiast
You mean like the following two lines?
Set newList = VL.ActiveDocument.Functions.Item("list").funcall(values(Item))
& nbsp; ' ...and append it to the existing list.
The ";" causes an error unless you remove it.

I will look into vlax.cls. Thanks for your help.
Terry
0 Likes
Message 10 of 12

Ed__Jobe
Mentor
Mentor
A lot more than that. I didn't have time to debug it. vlax makes it easy to run lisp. All you need to do is have your lisp formatted as a string. If you find an older copy of vlax, you will need to update its class string in GetObject.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 11 of 12

terrycadd
Enthusiast
Enthusiast
Ed,
I searched the forum for vlax.cls topics and found over a dozen discussions. The version that I downloaded was VLAX.CLS v1.4 (Last updated 8/27/2001). You mentioned updating its class string in GetObject. Are you referring to the following code?
Set VL = ThisDrawing.Application.GetInterfaceObject("VL.Application.16")
Where can I download the latest vlax.cls code? I am having problems searching on the http://www.acadx.com/ website. There are so many unrelated ads.
Also, are there examples of using vlax.cls similar to the examples in the code in this thread?
Thanks again for your help.
Terry
0 Likes
Message 12 of 12

Ed__Jobe
Mentor
Mentor
Yes, I meant GetInterfaceObject.
acadx.com is dead. That's why I mentioned that you update it yourself. As for examples, see your thread at augi.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes