13 Posts
0 Kudos
Registered: ‎04-10-2001
Post 1 of 4

SendCommand System.Runtime.InteropServices.COMException

865 Views, 3 Replies
01-25-2013 11:31 AM


Sub Main()

  Dim acAppComObj AsAcadApplication

  Dim strProgId AsString = "AutoCAD.Application.19"


  '' Get a running instance of AutoCAD

     acAppComObj = GetObject(, strProgId)

    '' An error occurs if no instance is running

   If Err.Number > 0 Then


      '' Create a new instance of AutoCAD

       acAppComObj = CreateObject(strProgId)

      '' Check to see if an instance of AutoCAD was created

   If Err.Number > 0 Then 


            '' If an instance of AutoCAD is not created then message and exit

            MsgBox("Instance of 'AutoCAD.Application' could not be created.")





'' Display the application and return the name and version

        acAppComObj.Visible =True


'' Get the active document

    Dim acDocComObj AsAcadDocument

    acDocComObj = acAppComObj.ActiveDocument

'' Optionally, load your assembly and start your command or if your assembly is demandloaded, simply start the command of your in-process assembly.


    acDocComObj.SendCommand("(command " & Chr(34) & "NETLOAD" & Chr(34) & " "       Chr(34) & "H://x64/Debug/octr_dwg_cmd.dll" & Chr(34) & ") ")


      acDocComObj.SendCommand("(xxx " & Chr(34) & "ss" & Chr(34) & ") ")




The code execute à LISP function from octr_dwg_cmd.dll and produce the following:



(xxx "ss") System.Runtime.InteropServices.COMException (0x80200033): Erreur de fichier
   à System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   à Autodesk.AutoCAD.ApplicationServices.DocumentCollectionExtension.Add(DocumentCollection docCol, String templateFileName)
   à octr_dwg_cmd.Module1.octr_dwg(String FichierZip) dans H:\developpement\octr_dwg_cmd\octr_dwg_cmd\Module1.vb:ligne 12
   à octr_dwg_cmd.octr_dwg_cmd.MyCommands.MyLispFunction(ResultBuffer args) dans H:\developpement\octr_dwg_cmd\octr_dwg_cmd\myCommands.vb:ligne 76
   à Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorker(MethodInfo mi, Object commandObject, Boolean bLispFunction)
   à Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorkerWithExceptionFilter(MethodInfo mi, Object commandObject, Boolean bLispFunction)
   à Autodesk.AutoCAD.Runtime.PerDocumentCommandClass.Invoke(MethodInfo mi, Boolean bLispFunction)
   à Autodesk.AutoCAD.Runtime.CommandClass.CommandThunk.InvokeLisp(); erreur: Demande ADS erronée



When I input at the command line of AutoCAD the same (xxx "ss"), the result is OK. The problem occurs whit the SendCommand of my EXE program.



Any help will be appreciated



*Expert Elite*
1,084 Posts
215 Kudos
Registered: ‎04-27-2009
Post 2 of 4

Re: SendCommand System.Runtime.InteropServices.COMException

01-25-2013 12:30 PM in reply to: pcardinal

One possible reason is that the AutoCAD session does not have an ActiveDocument, thus,


acDocComObj could be Nothing, so, the call to


acDocuComObj.SendCommand() will fail.


For example, when your code starts, if there is no existing Acad session, your code call CreateObject() to create an AutoCAD session. In this case, AutoCAD does not automatically add a new blank drawing, thus, after the Acad Session is created by CreateObject(), it is likely acAppComObj.ActiveDocument is nothing, hence the error.


So, you want to test if AcadApplication.ActiveDocument is Nothing or not, or you can tell if there is document by testing if AcadApplication.Documents.Count=0.


13 Posts
0 Kudos
Registered: ‎04-10-2001
Post 3 of 4

Re: SendCommand System.Runtime.InteropServices.COMException

01-25-2013 12:58 PM in reply to: norman.yuan

I have an Active Document because I use it to call SendCommand (and I have no problem to load my DLL)

Dim strProgId As String = "AutoCAD.Application.19"

Dim acAppComObj As AcadApplication = CreateObject(strProgId)

Dim acDocComObj As AcadDocument = acAppComObj.ActiveDocument




The problem seems to be in my DLL where I am creating a New Doc (acNewDoc). When the new doc is created, it seems that there is a problem loading the template (AutoCAD returns garbage in the Command window).


code in my DLL creating the problem

Dim acDocMgr AsDocumentCollection = Application.DocumentManager

Dim acNewDoc AsDocument = DocumentCollectionExtension.Add(acDocMgr,acad.dwt")



Strange because like I mentionned it, I have no problem to execute the function from the command line of AutoCAD by typing it but having problem executing it from an EXE.





ADN Support Specialist
761 Posts
100 Kudos
Registered: ‎03-21-2011
Post 4 of 4

Re: SendCommand System.Runtime.InteropServices.COMException

02-01-2013 08:47 AM in reply to: pcardinal



How is the new document related to the Lisp callable command that the .Net assembly implements.


Can you provide a buildable sample project to demonstrate the issue ?




Developer Technical Services
Autodesk Developer Network

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!