Problem of writing lisps using excel vba

Problem of writing lisps using excel vba

skchui6159
Advocate Advocate
462 Views
5 Replies
Message 1 of 6

Problem of writing lisps using excel vba

skchui6159
Advocate
Advocate

Sub RunTwoLispInSpecificAutoCADFile()
Dim acadApp As Object
Dim acadDoc As Object
Dim dwgPath As String
Dim lispCode1 As String
Dim lispCode2 As String
Dim lispCode3 As String

' Setting Path
dwgPath = "C:\Users\XXX\Desktop\Sample\6-1-2025\Drawing1.dwg"

' Use AUTOCAD Application to run
On Error Resume Next
Set acadApp = GetObject(, "AutoCAD.Application")
If Err.Number <> 0 Then
Set acadApp = CreateObject("AutoCAD.Application")
End If
On Error GoTo 0

' Show AutoCAD
acadApp.Visible = True

' Opening DWG document
Set acadDoc = acadApp.Documents.Open(dwgPath)

' Running LISP
lispCode1 = "(command ""circle"" (list 5 0) 50 """" """")" ' LISP1
lispCode2 = "(command ""circle"" (list 5 0) 100 """" """")" ' LISP2"
lispCode3 = "(command ""circle"" (list 5 0) 200 """" """")" ' LISP3"

' LISP to AutoCAD
acadApp.ActiveDocument.SendCommand lispCode1 & vbCr
acadApp.ActiveDocument.SendCommand lispCode2 & vbCr
acadApp.ActiveDocument.SendCommand lispCode3 & vbCr

' Clear Ram if excel
Set acadDoc = Nothing
Set acadApp = Nothing
End Sub

 

Anyone know Why it doesn't works automatically in excel?

0 Likes
463 Views
5 Replies
Replies (5)
Message 2 of 6

Ed__Jobe
Mentor
Mentor

It’s not helpful if you just say “it’s not working “. Give some details of what’s happening and what trouble shooting you did. What does AutoCAD’s command line history show? If you get something like UNKNOWN COMMAND then your lisp is probably not formatted correctly. Instead of double quotes, use the backslash escape character, e.g. \”.  But first you should be using the VBA api to add a circle. Use the AddCircle method. 

Also, use the link in my signature to post your code in a code window to preserve the formatting. 

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 3 of 6

skchui6159
Advocate
Advocate
Sub RunTwoLispInSpecificAutoCADFile()
    Dim acadApp As Object
    Dim acadDoc As Object
    Dim dwgPath As String
    Dim lispCode1 As String
    Dim lispCode2 As String
    Dim lispCode3 As String

    ' Setting Path
    dwgPath = "C:\Users\xxxx\Desktop\Sample\6-1-2025\Drawing1.dwg"

    ' Use AUTOCAD Application to run
    On Error Resume Next
    Set acadApp = GetObject(, "AutoCAD.Application")
    If Err.Number <> 0 Then
        Set acadApp = CreateObject("AutoCAD.Application")
    End If
    On Error GoTo 0

    ' Show AutoCAD
    acadApp.Visible = True

    ' Opening DWG document
    Set acadDoc = acadApp.Documents.Open(dwgPath)

    ' Running LISP
'    lispCode1 = "(command ""circle"" (list 5 0) 50 """" """") "" "" (command ""circle"" (list 5 0) 100 """" """")" '  LISP1
    lispCode1 = Range("B2").Value & vbCr & Range("B3").Value
    'lispCode2 = Range("B3").Value

    '  LISP to AutoCAD
    acadApp.ActiveDocument.SendCommand lispCode1 & vbCr
    'acadApp.ActiveDocument.SendCommand lispCode2 & vbCr

    ' Clear Ram if excel
    Set acadDoc = Nothing
    Set acadApp = Nothing
End Sub
0 Likes
Message 4 of 6

skchui6159
Advocate
Advocate

It will show like that 

skchui6159_0-1736298025002.png

 

0 Likes
Message 5 of 6

skchui6159
Advocate
Advocate
 Autocad Action (Lisp)
Excel cell -B2 Value(command "_circle" (list 5 0) 50 "")
Excel cell -B3 Value(command "_circle" (list 5 0) 70 "")
0 Likes
Message 6 of 6

Ed__Jobe
Mentor
Mentor

Why are you trying to use Excel to create AutoCAD entities? Why not just use lisp or VBA?

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