Calling AutoCAD commands from .NET

In this earlier entry I showed some techniques for calling AutoCAD commands programmatically from ObjectARX and from VB(A). Thanks to Scott Underwood for proposing that I also mention calling commands from .NET, and also to Jorge Lopez for (in a strange coincidence) pinging me via IM this evening with the C# P/Invoke declarations for ads_queueexpr() and acedPostCommand(). It felt like the planets were aligned... 🙂

Here are some ways to send commands to AutoCAD from a .NET app:

  • SendStringToExecute from the managed document object
  • SendCommand from the COM document object
  • acedPostCommand via P/Invoke
  • ads_queueexpr() via P/Invoke

Here's some VB.NET code - you'll need to add in a COM reference to AutoCAD 2007 Type Library in addition to the standard .NET references to acmgd.dll and acdbmgd.dll.

Imports Autodesk.AutoCAD.Runtime

Imports Autodesk.AutoCAD.ApplicationServices

Imports Autodesk.AutoCAD.Interop

Public Class SendCommandTest

    Private Declare Auto Function ads_queueexpr Lib "acad.exe" _

        (ByVal strExpr As String) As Integer

    Private Declare Auto Function acedPostCommand Lib "acad.exe" _

        Alias "?acedPostCommand@@YAHPB_W@Z" _

        (ByVal strExpr As String) As Integer

    <CommandMethod("TEST1")> _

    Public Sub SendStringToExecuteTest()

        Dim doc As Autodesk.AutoCAD.ApplicationServices.Document

        doc = Application.DocumentManager.MdiActiveDocument

        doc.SendStringToExecute("_POINT 1,1,0 ", False, False, True)

    End Sub

    <CommandMethod("TEST2")> _

    Public Sub SendCommandTest()

        Dim app As AcadApplication = Application.AcadApplication

        app.ActiveDocument.SendCommand("_POINT 2,2,0 ")

    End Sub

    <CommandMethod("TEST3")> _

    Public Sub PostCommandTest()

        acedPostCommand("_POINT 3,3,0 ")

    End Sub

    <CommandMethod("TEST4")> _

    Public Sub QueueExprTest()

        ads_queueexpr("(command""_POINT"" ""4,4,0"")")

    End Sub

End Class

In case you're working in C#, here are the declarations of acedPostCommand() and ads_queueexpr() that Jorge sent to me:

[DllImport("acad.exe", CharSet = CharSet.Auto,

  CallingConvention = CallingConvention.Cdecl)]

extern static private int ads_queueexpr(string strExpr);

[DllImport("acad.exe", CharSet = CharSet.Auto,

  CallingConvention = CallingConvention.Cdecl,

  EntryPoint = "?acedPostCommand@@YAHPB_W@Z")]

extern static private int acedPostCommand(string strExpr);

You'll need to specify:

using System.Runtime.InteropServices;

to get DllImport to work, of course.

  1. Alexander Rivilis Avatar
    Alexander Rivilis

    Hi, Kean!
    And what about P/Invoke acedCmd() as Tony Tanzillo doing hear: discussion.autodesk....

    Best Regards,
    Alexander Rivilis.

  2. Hi Alexander,

    Yes... this is certainly possible - both acedCommand() and acedCmd() could be P/Invoked if you really wanted. I tend to avoid using them from a native command, it's just safest not to go down that path due to re-entrancy issues.

    If you only register your function as a [LispFunction] then there is less risk, although frankly I always tread carefully with these two functions and use them only when absolutely necessary.

    Cheers,

    Kean

  3. Hello, Kean!
    Thanks for your great articles!!
    Can you write some articles about the Toolbar and Menu using .NET?The sample given by the ObjectARX SDK is really poor explained.
    Thanks again!!

  4. Hi CSharpBird,

    It's my pleasure. 🙂

    I was thinking of something in this direction - I'll certainly add it to my list and see whether someone in the team feels like taking it on as a topic.

    BTW - my team also owns the ObjectARX SDK samples, so if you have specific feedback about them, do drop me an email about what more you'd like to see.

    Regards,

    Kean

  5. Is it possible to pass in parameters through the command method similar to lisp functions?

    Something similar to <commandmethod("test2", param1,="" param2)_="" i="" am="" trying="" to="" figure="" out="" a="" way="" to="" use="" a="" macro="" to="" call="" a="" block="" insert="" command="" and="" pass="" in="" the="" block="" name="" and="" destination="" layer="" as="" parameters.="" thanks="" to="" anyone="" who="" has="" any="" input.="" joel="">

  6. [CommandMethod("TEST4", param1, param2]_

    I guess this part didn't post due to the angle brackets so I replaced them with square brackets

  7. Commands by nature do not take arguments - you will either need to define an equivalent LispFunction (which is easy to do) or use Editor.GetString() etc. to get the parameters that are entered (perhaps programmatically using (command)) at the command-line.

    Kean

  8. Massimo Cicognani Avatar
    Massimo Cicognani

    Sorry to bring up this post, but I've read so much but never got a final and neat solution.

    I believe that a very common task for Acad programmers is to perform repeatitive task over a bunch of drawings.
    That's usually done with the help of a dialog form or a palette or something similar to allow the user to select the drawing to manipulate and then press that cute button that will allow the program to work unattended and them to get a coffee break.

    Well, maybe 90% of the tasks can be solved with a clean NET programming, but sometimes there is simply no other way than to send a command string to autocad, just to mention one, a beatiful "_audit _y " since the NET equivalent is still a work-in-progress.

    My question is: since most of the cases, we're working in the Application context, what is the best practice to execute a command, wait for its execution, save the document at hand and continue with the next file?

    I've seen many solutions, included Tony's that would address exactely this case and implements a sort of ExecuteInDocumentContext() function, but (maybe to my fault) I often get into re-entrancy issues and I'm unable to get a stable and reliable solution.

  9. Kean Walmsley Avatar

    You automatically enter the document context when you send a command to the command-line. I would expect that sending a sequence of commands either asynchronously (via SendStringToExecute) or synchronously (via SendCommand) would work for what you want.

    Perhaps I'm missing something?

    Kean

  10. Massimo Cicognani Avatar
    Massimo Cicognani

    I think the problem is exactely in how to send command synchronously in a NET environment.
    SendCommand would be great, I've used it for years in VBA after all, but I'm trying to stay COM-free 'cause I have to target multiple platform, both 32 and 64bit, and multiple AutoCAD versions.
    NET is a great help from this point of view, but maybe is not enough?

  11. Kean Walmsley Avatar

    I personally don't see a big problem with using COM (you could probably avoid referencing the TLB by using low level IDispatch marshalling, but that's just a guess).

    Another approach is to create a "continuation command", which is fired at the end of the other commands you're sending and allows your application to pick up control.

    Kean

  12. Hi Kean,
    I learned about the undocumented function acedEvaluateLisp, that works great for evaluating lisp commands. To P/Invoke in NET:

    [DllImport("acad.exe", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl,EntryPoint = "?acedEvaluateLisp@@YAHPB_WAAPAUresbuf@@@Z")]
    extern private static int acedEvaluateLisp(string lispLine, out IntPtr result);

    I am running into an issue when I try to execute the same code on a 64 bit operating system. The code throws an exception that the EntryPoint is invalid. As you mentioned earlier using acedCommand and acedCmd causes re-entrance and that leads into all sorts of problems, and any of the other function mentioned not applicable, since I need the lisp executed synchronously. Any ideas?

  13. Hi Ivan,

    The signature is probably different on x64 - I suggest checking via Dumpbin.

    I would avoid using an undocumented function such as this, especially via P/Invoke... have you tried using acedInvoke()?

    [DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl)]
    extern static private int acedInvoke(IntPtr args, out IntPtr result);

    Regards,

    Kean

  14. Hi Kean,

    I have a problem maybe you can help with. I want to call a command without closing/disposing my form. The command will not execute until I have done this. Any ideas?

  15. I think I solved the problem with a suggestion you made above to

    Another approach is to create a "continuation command", which is fired at the end of the other commands you're sending and allows your application to pick up control.

    Thanks!

  16. Hello.
    I an query:
    by example send a command with:
    SendStringToExecute (_POINT 1,1,0 ", False, False, True)
    as I capture the parameters _point ie get the 1,1,0.
    thanks

  17. You can do this from your own command: otherwise you might be able to add some kind of user-input event handler to find you when points are selected.

    Kean

  18. vijay kumar pandu Avatar
    vijay kumar pandu

    hi kean

    when i pick a point in autocad then i display a dialogbox
    if use clicks on ok in dialoag box then i used to pick the another point in auto cad

    now i load a lisp file and execute a lispfunction inputing these two points to the function

    then basing on these points a drawing is generated using lisp function

    here is my code

    <autodesk.autocad.runtime.commandmethod("dvk")> _
    Public Sub HelloCommand()
    PointArryListX = New ArrayList
    PointArryListY = New ArrayList
    acadApp.DocumentManager.MdiActiveDocument.SendStringToExecute("(LOAD " & Chr(34) + "c:/LispSld/generatedwg.lsp" & Chr(34) & " )" & vbCr, False, False, True)
    Dim plp As String = ""
    Dim f As Cable.Form1
    Dim myDB As Database
    Dim myEd As Editor
    Dim myPEO As New Autodesk.AutoCAD.EditorInput.PromptPointOptions(vbLf & "Select a DVK Point:")
    Dim myPS As Autodesk.AutoCAD.EditorInput.PromptStatus
    Dim myTransMan As Autodesk.AutoCAD.DatabaseServices.TransactionManager
    Dim myTrans As Autodesk.AutoCAD.DatabaseServices.Transaction
    AcadDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
    Do
    f = New Cable4.Form1
    plp = ""
    myDB = AcadDoc.Database
    myEd = AcadDoc.Editor
    myPEO = New Autodesk.AutoCAD.EditorInput.PromptPointOptions(vbLf & "Select a dvk Point " + PointArryListX.Count.ToString() + " :")
    'myPEO.SetRejectMessage("You must select a Point." & vbCrLf)
    myPEO.AllowNone = True
    myPEO.UseBasePoint = False
    Dim myPER As Autodesk.AutoCAD.EditorInput.PromptPointResult
    myPER = myEd.GetPoint(myPEO)
    myPS = myPER.Status
    Select Case myPS
    Case Autodesk.AutoCAD.EditorInput.PromptStatus.OK
    Dim picked As Point3d = myPER.Value
    PointArryListX.Add(picked.X.ToString())
    PointArryListY.Add(picked.Y.ToString())

    Case Autodesk.AutoCAD.EditorInput.PromptStatus.Cancel
    'MsgBox("You cancelled.")
    Exit Sub
    Case Autodesk.AutoCAD.EditorInput.PromptStatus.Error
    MsgBox("Error warning.")
    Exit Sub
    Case Else
    Exit Sub
    End Select
    'If f.ShowDialog() <> DialogResult.Cancel Then
    ' plp = "y"
    'Else
    ' plp = "n"
    'End If
    f.ShowDialog()
    plp = Cable4.myClass1.pLoop
    If plp = "y" Then
    Series = Cable4.myClass1.txtSeries
    Tag = Cable4.myClass1.txtTag
    Width = Cable4.myClass1.txtWidth
    Thick = Cable4.myClass1.txtThick
    Height = Cable4.myClass1.txtHeight
    End If
    'f.Close()
    If PointArryListX.Count > 1 Then
    Dim cnt As Integer
    cnt = PointArryListX.Count
    Dim cmd As String = ""
    cmd = cmd + "_ca" + vbCr
    cmd = cmd + PointArryListX.Item(cnt - 2) + vbCr
    cmd = cmd + PointArryListY.Item(cnt - 2) + vbCr
    cmd = cmd + PointArryListX.Item(cnt - 1) + vbCr
    cmd = cmd + PointArryListY.Item(cnt - 1) + vbCr
    cmd = cmd + Series + vbCr
    cmd = cmd + Tag + vbCr
    cmd = cmd + Width + vbCr
    cmd = cmd + Thick + vbCr
    cmd = cmd + Height + vbCr
    cmd = cmd + "Ladder" + vbCr
    cmd = cmd + "Tray_Type" + vbCr
    cmd = cmd + "n" + vbCr
    acadApp.DocumentManager.MdiActiveDocument.SendStringToExecute(cmd, True, False, True)
    acadApp.DocumentManager.MdiActiveDocument.SendStringToExecute("y" + vbCr, True, False, True)

    End If

    Loop While plp = "y"

    but i could not call the lisp function
    when itry to call the lisp function
    the command is prompting to select a point

    please help me

  19. Hi Vijay,

    Sorry - I don't have time to provide a debugging service for my readers.

    I suggest posting via the ADN site, if you're a member, or otherwise the AutoCAD .NET Discussion Group.

    Regards,

    Kean

  20. Emilia Mazurkiewicz Avatar
    Emilia Mazurkiewicz

    Hi Kean,
    I have a problem maybe you can help with.
    In VB. Net sending commands directly to the AutoCAD command line by using SendStringToExecute method.
    EchoCommand parameter set to False. Command sent not visible in the AutoCAD command line, but we can see it after clicking the right mouse. Is there any method to see .NET command as last one insteed the LISP one sent by .NET?
    Regards,
    Emilia

  21. Hi Emilia,

    Sorry - I don't provide support services via this blog.

    Please submit your question to the ADN team, if you're a member, or otherwise the AutoCAD .NET Discussion Group.

    Regards,

    Kean

  22. Hi Kean ,
    I wanna ask u : if I wanna execute an interruptible cad command through .net (it takes an input from the user e.g : _appload ) .Please tell me how could I send the path of the lisp file with the command itself.(when I execute the command ,the open file dialog box is displayed then I can browse to file normally , but I want to pass the path as a parameter .(I don't want the open file dialog to be displayed to the user) ??
    Any help ???

  23. Have you tried putting (command "") around it, or setting FILEDIA/CMDDIA to 0, first?

    Kean

  24. Hi Kean,

    Don't you love when someone comments on one of your posts coming on 5 years old? 🙂

    Anyhow, I noticed that a command's session/document context appears to control whether the COM SendCommand() is executed synchronously or asynchronously, well at least for AutoCAD 2012. I was going mad trying to get some code to execute synchronously and thought it was worth mentioning. If you try the following you'll see what I mean...

    // Command in "session" context will execute synchronously.
    [CommandMethod("Async")]
    public static void Async() {
    AcadApplication app = Application.AcadApplication as AcadApplication;
    app.ActiveDocument.SendCommand("._CIRCLE 0,0 5 ._ZOOM Extents ");
    Application.ShowAlertDialog("Rectangle created!");
    }

    // Command in "session" context will execute synchronously.
    [CommandMethod("Sync", CommandFlags.Session)]
    public static void Sync() {
    AcadApplication app = Application.AcadApplication as AcadApplication;
    app.ActiveDocument.SendCommand("._CIRCLE 0,0 5 ._ZOOM Extents ");
    Application.ShowAlertDialog("Rectangle created!");
    }

    Cheers,
    Art

  25. Sorry typo... code titles should be:
    "// Command in "document" context will execute asynchronously"
    "// Command in "session" context will execute synchronously"

    Art

  26. Kean Walmsley Avatar
    Kean Walmsley

    Hi Art,

    I don't mind comments on 5-year old posts, as long as they don't ask questions. 😉

    Thanks for the pointer - I wasn't aware of the distinction (although it does make some sense). I'm curious whether it's a recent phenomenon or has always worked like that. Hmmm.

    Regards,

    Kean

  27. Hi kean,
    first of all i'd like to thank you for your code and your time.

    Secondly, i post to ask you a question.
    In fact, i would like to create an independant VB.net project with an active X (only including dwg true view viewer or objectARX activeX)
    I as able to load the dwg with the activeX.
    But my main problem is to zoom "programmatically" (i mean in code...) because, if I use the activeX zoom_center function, it doesn't "need" parameters and it is waiting for 2 clic to do the zoom...
    So i try to use the "sendcommand" command and found this post... but i was not able to make it works.
    Do you have any idea on using the function zoom_center? or how to override it ? or how to make what i want but not by installing the full autocad program on the computer ? because my app will only have to display the dwg and to zoom_in/out (no other edition, or creation)

    Thx in advance for your help

  28. Kean Walmsley Avatar

    It's been a while since I've used the TrueView API, myself, and - in any case - I make a point of avoiding providing support via my blog (I just don't have the time - if I started doing so I wouldn't have time for anything else).

    Please post your question via ADN, if you're a member, or otherwise one of our online discussion groups.

    Regards,

    Kean

  29. Hi....
    I want to add my custom toolbar into autocad..toolbar and form designed in dot net . i want to add the toolbar and also fire some events from toolbar...so can u provide me some helping application....i m beginner here..so i need initial startup ...i m using object arx 2009 .
    Thanks in advance.....

  30. Hi ...
    I m getting my toolbar when I run my objectarx application...but when I clicked any button on toolbar..command display at the command text but can not automatically fired up...until i press the enter..please suggest me some solution....
    If possible i need some code.....
    Thanks in advance....
    Rakesh Shinde, Pune...

  31. Rakesh,

    This is not a forum for support.

    Please post your question to ADN, if you're a member, or otherwise to one of our online discussion groups.

    Regards,

    Kean

  32. Artvegas thank you so much for that clarification. I've spent the better part of a day trying to get SendCommand to execute synchronously, and was just about to give up. For informative purposes I'm running AutoCad 2011 32 bit, so that behaviour has been active at least since 2011.

  33. Hi Kean,

    I'm reading your blog this a long time and using your code examples quite a bit - Thank you!

    But using SendCommand in C#, .Net 4.0, VS 2010, ACAD 2012 will not work for me, when I need to send an object id.

    The following code fails, with the message that xxxxxxxxx (long number) is not a function.

    PromptEntityResult acEntRes = acDoc.Editor.GetEntity(acEntObts);

    if (acEntRes.Status == PromptStatus.OK) {

    AcadApplication acAPP = (AcadApplication)Application.AcadApplication;

    acAPP.ActiveDocument.SendCommand("(command " + (char)34 + "._REVCLOUD" + (char)34 + " " + (char)34 + "_o" + (char)34 + " " + (char)34 + acEntRes.ObjectId + (char)34 + ")");

    }

    Might you give me any advise on how to resolv this topic?

    Best greets,

    Mario

  34. Hi Mario,

    Try getting the handle for the entity you want and passing it to the command-line as the argument to the (handent) function to make the entity name get passed to the command:

    (handent "1BD")

    Cheers,

    Kean

  35. Hi Kean,

    thanks for your advise - it helped!

    The correct code for creating a revcloud from given entity is:

    AcadApplication acAPP = (AcadApplication)Application.AcadApplication;
    acAPP.ActiveDocument.SendCommand( "(command " +
    (char)34 + "._REVCLOUD" + (char)34 + " " + (char)34 + "_o" + (char)34 + " " + "(handent " + (char)34 + acEntRes.ObjectId.Handle.ToString() + (char)34 + ")" + (char)34 + "_no" + (char)34 + ")" + " ");

    Best greets,

    Mario

  36. Hi Kean. I need help!

    i have a c# project. this project load lisp file (synchronous) with :
    [System.Security.SuppressUnmanagedCodeSecurity]
    [DllImport("accore.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl, EntryPoint = "?acedEvaluateLisp@@YAHPEB_WAEAPEAUresbuf@@@Z")]
    extern public static int acedEvaluateLisp(string lispLine, out IntPtr result);

    It's Ok with AutoCAD 2013 when i run Acad.exe.
    It's KO with AutoCAD 2013 when i run accoreconsole.exe

    Bug? Have you a solution for this?

    Best greets

  37. Hi Olivier,

    Sorry - I'm not sure what's wrong, here. I haven't personally ever P/Invoked this method, that I can recall. I suggest posting your question via ADN or to the AutoCAD .NET Discussion Group.

    Regards,

    Kean

  38. hello Mr. Kean
    please tell me, Can I use trial version of Autocad2010

  39. I have no idea. I assume we only make trial versions available for more recent versions, but then this really isn't my area of expertise.

    Kean

  40. Hi Kean,

    Many thanks. I was struggling with passing entities to SendCommand

  41. Hi, Kean,

    Is is ok if I use 'SendStringToExecute' in .Net 2005(C#) for AutoCAD 2005?

    Code sample as below:
    Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
    doc.SendStringToExecute("_QSave" + "\n", true, false, true);

    Thanks

    BR,
    Jay
    2014.3.10

  42. Hi Jay,

    If it works for you, then fine. I can't say whether it's "OK" or not, as .NET was a preview release and - in any case - AutoCAD 2005 hasn't been supported for some years now.

    Hopefully it'll work for you,

    Kean

  43. Hi, Kean,

    Thanks for your reply. But~~~~

    It doesn't work~~

    I found there is no [SendStringToExecute] Method after I add acdbmgd.dll and acmgd.dll into reference in .Net 2005 C# develop environment.

    Thanks

    BR,
    Jay
    2014.3.11

  44. This is unsurprising: .NET was in preview mode in AutoCAD 2005.

    If you need to write an app for 2005 I suggest using the COM API (whether from VBA or .NET), LISP or ObjectARX. Or using a newer version of the product, of course.

    Kean

  45. Hi, Kean,

    Thanks for reply.

    Actually I need to write a customize application that must be added on CAD 2005 environment(Includes some user control ex: window form,button,textbox or datagrid...etc).

    For my requirement, I think .Net is a best develop tool(Because UI design is easily).

    Becuase using .Net, I can build .Net assembly(*.dll) and use 'Netload' command to load them and run commands that I define in AutoCAD.

    As your experience about CAD development,all tools (Maybe languages) that you suggest me to use (ex.COM API/LISP/ObjectARX) also can meet my requirement?(Write an UI application that can add on AutoCAD 2005)

    Sorry...I am not too much experience on developing customize application for AutoCAD 2005....

    Many thanks for your sharing if you don't mind~~~~

    Best regards,

    Jay
    2014.3.13

  46. Please post follow-up questions to the discussion groups. This is getting way off topic, and my blog is really not a support forum.

    Kean

  47. Hello Kean!

    I had a quick question.

    As Artvegas pointed out, setting commandflags.session is a good way to ensure that any calls using sendcommand() will be executed sequentially.

    I was wondering if there is a way to force sendcommand to execute sequentially when it's being used in the context of defining a Lispfunction?

    Thanks!

    1. Hello Ian,

      I don't know how you'd do this from LispFunctions before 2015: from this release onwards, however, you have much greater control over the way commands can be executed via Editor.Command() and Editor.CommandAsync().

      Regards,

      Kean

      1. Thanks for the reply Kean!

        I'm glad to hear that 2015 has added those controls over how commands can be executed.

        I will have to check them out.

        In the meantime, i'll have to figure something out for the older editions of AutoCAD. We have to support down to 2012.

  48. Hi Kean! Thanks for all your articles, they've been a big help to me and other developers I work with. I was wondering what SendStringToExecute would look like in calling the UNDO command because doc.SendStringToExecute("_UNDO M") and ("_UNDO B") don't seem to work to mark a position to undo to and then undo-ing back to it.

    1. Kean Walmsley Avatar

      Hi Nick,

      Calling undo programmatically is a tricky business. What are you trying to do? Perhaps there's a better way...

      Regards,

      Kean

      1. Thanks for your reply! I'm trying to create two functions, one of which when called marks the position of the drawing (like typing UNDO M into the command line) and the other when called brings the drawing back to the marked position (like typing UNDO B into the command line). The idea is that every time one of my plug-ins does something it marks the position of the drawing first and then if something goes wrong partway through it can rollback to before any changes were made automatically

        1. Kean Walmsley Avatar

          I tried implementing a couple of commands to do this, and - with my limited testing - they seemed to work OK:

          [CommandMethod("UM")]
          public void UndoMark()
          {
          Application.DocumentManager.MdiActiveDocument.Editor.Command("_.UNDO", "_M");
          }

          [CommandMethod("UB")]
          public void UndoBack()
          {
          Application.DocumentManager.MdiActiveDocument.Editor.Command("_.UNDO", "_B");
          }

          SendStringToExecute() won't work synchronously, but it's not always easy to call commands otherwise, depending on your context.

          Kean

          1. Works great! Thanks so much

            Nick Gilbert

          2. Hey Kean. Your code works well when everything is contained in one program. However when I try to use ed.command("um") in a separate plug-in with both that plug-in and the one with your code NETLOADed into AutoCAD, it throws an eInvalidInput exception. Does it do the same for your code?

            1. Hi Nick,

              The fact it's in a different plugin really shouldn't matter (I've called other commands in this way without any issues).

              eInvalidInput usually happens when you're calling a command from the application context (from a modeless dialog or an event handler, for instance). There's an API in 2016 that helps address this (keanw.com/2015/03/autocad-2016-calling-commands-from-autocad-events-using-net.html) or you can stick with SendStringToExecute().

              Regards,

              Kean

              1. Davide Pizzolato Avatar

                What if I want to wait to wait the end of the command?
                SendStringToExecute is not awaitable...

                1. It executes asynchronously. As far as I recall, you either need to us SendCommand() through COM for synchronous, or queue up consecutive commands via SendStringToExecute(). But this is from memory, and I don't have time to provide support: please post follow-up questions to the AutoCAD .NET forum.

                  Kean

  49. Hi Kean! I want to execute the AutoCAD Commands like Purge,Audit etc through UI using SendStringToExecute. But its not working for those commands which i mentioned above. Please provide me solution if there is any possible.

    1. Kean Walmsley Avatar

      Hi Vinoth,

      I don't know what's not working: I suggest posting some code to the AutoCAD .NET Discussion Group.

      Regards,

      Kean

Leave a Reply to Gary Whitcher Cancel reply

Your email address will not be published. Required fields are marked *