.NET

Reply
Contributor
pcardinal
Posts: 13
Registered: ‎04-10-2001
Message 1 of 4 (760 Views)

SendCommand System.Runtime.InteropServices.COMException

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

 

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,

*Expert Elite*
norman.yuan
Posts: 965
Registered: ‎04-27-2009
Message 2 of 4 (751 Views)

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.

 

Contributor
pcardinal
Posts: 13
Registered: ‎04-10-2001
Message 3 of 4 (744 Views)

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

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.

 

 

 

 

ADN Support Specialist
Balaji_Ram
Posts: 666
Registered: ‎03-21-2011
Message 4 of 4 (692 Views)

Re: SendCommand System.Runtime.InteropServices.COMException

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

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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community