SendCommand System.Runtime.InteropServices.COMException

SendCommand System.Runtime.InteropServices.COMException

pcardinal
Contributor Contributor
2,610 Views
3 Replies
Message 1 of 4

SendCommand System.Runtime.InteropServices.COMException

pcardinal
Contributor
Contributor

 

Sub Main()

  Dim acAppComObj AsAcadApplication

  Dim strProgId AsString = "AutoCAD.Application.19"

  OnErrorResumeNext

  '' Get a running instance of AutoCAD

     acAppComObj = GetObject(, strProgId)

    '' An error occurs if no instance is running

   If Err.Number > 0 Then

       Err.Clear()

      '' Create a new instance of AutoCAD

       acAppComObj = CreateObject(strProgId)

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

   If Err.Number > 0 Then 

            Err.Clear()

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

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

      Return

   EndIf

    EndIf

       

'' 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) & ") ")

EndSub

 

 

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

 

Regards,

0 Likes
2,611 Views
3 Replies
Replies (3)
Message 2 of 4

norman.yuan
Mentor
Mentor

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.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 4

pcardinal
Contributor
Contributor

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

acDocComObj.SendCommand(...)

 

 

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")

DocumentExtension.CloseAndDiscard(acNewDoc)

 

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.

 

 

 

 

0 Likes
Message 4 of 4

Balaji_Ram
Alumni
Alumni

Hello,

 

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 ?

 

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

0 Likes