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
'' 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
à octr_dwg_cmd.Module1.octr_dwg(String FichierZip) dans H:\developpement\octr_dwg_cmd\octr_dwg_cmd\Module1
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
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.
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.
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 ?
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register