I am attempting to call an inbuilt AutoCad Electrical LISP command "c:wd_insym2"
from .NET.
I have recently installed AutoCad 2016 which now has the Editor.Command and Editor.CommandAsync functions, however all the help/forum posts that I can find refer to using it to call AutoCad commands such as LINE, CIRCLE etc.
I want to call a lisp command, such as:
(c:wd_insym2 "HPB11.dwg" (list 0 0) 1.0 nil)
which inserts a pushbutton symbol at 0, 0
.
Here's what I've got (I have been using CommandAsync because I have had trouble sending that command synchronously using Application.Invoke before: AutoCad Command Rejected "Undo" when using Application.Invoke()
<CommandMethod("SendCmdAsync", CommandFlags.Modal)>
Async Sub SendCmdAsync()
Dim doc As Document = DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Dim cmd As String = "(c:wd_insym2 " & ControlChars.Quote & "HPB11.dwg" & ControlChars.Quote & " (list 0 0) nil nil)"
ed.WriteMessage(vbNewLine & "Trying to execute: <" & cmd & ">" & vbNewLine)
Await ed.CommandAsync(cmd)
ed.WriteMessage(vbNewLine & "Done.")
End Sub
When I run it it says 'LISP command not available'.
Is what I'm doing possible, and if so, what am I doing wrong?
I sort of solved the issue - evidently you can't use Command and CommandAsync to run Lisp commands - they're only for AutoCAD commands.
The best way of doing this is Application.Invoke: https://forums.autodesk.com/t5/net/unable-to-find-an-entry-point-in-dll-acad-exe/m-p/5522036/highlight/true#M43404
Although, with my specific Electrical command (c:wd_insym2), when I try this technique in AutoCAD 2014, it gives me an error 'AutoCAD command rejected UNDO'. However, I have just noticed that in AutoCAD 2016 it works fine - I guess they've changed the API somewhere along the line.