cannot find embedded type 'autocad.iacadapplication'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello all.
I am writing a Windows Service application using Visual Studio 2013 which is to start AutoCAD Mechanical 2016, make the app visible, do some stuff and issue a SendCommand. The command that I am sending works when I run it manually in the AutoCAD Mechanical 2016 UI.
The problem is that the SendCommand never fires.
My only relevant import is System.Runtime.InteropServices.
My code:
'startup autocad Process.Start("C:\Program Files\Autodesk\AutoCAD 2016\acad.exe", "/p <<ACADMPP>> /product ACADM /language ""en-US""") 'wait till the thing opens. 0 min 30 seconds maybe? System.Threading.Thread.Sleep(New TimeSpan(0, 0, 30)) Dim acAppComObj As AutoCAD.AcadApplication = Nothing Const strProgId As String = "AutoCAD.Application.20.1" Try ' Get a running instance of AutoCAD acAppComObj = DirectCast(Marshal.GetActiveObject(strProgId), AutoCAD.AcadApplication) ' .AcadApplication) Catch ex As Exception ' If an instance of AutoCAD is not created then message and exit EventLog1.WriteEntry(String.Format("Instance of 'AutoCAD.Application' could not be attached.{0}{1}", vbCrLf, ex.Message)) 'Return False GoTo NOGOOD End Try 'EventLog1.WriteEntry("Acad successfully attached.") acAppComObj.Visible = True 'open up a new document - need to copy local for security reasons acAppComObj.Documents.Add(fi2.FullName) EventLog1.WriteEntry(String.Format("Opened doc: {0}", fi2.FullName)) 'wait for a few seconds System.Threading.Thread.Sleep(5000) ' Get the active document Dim acDocComObj As AutoCAD.AcadDocument Try acDocComObj = acAppComObj.ActiveDocument Catch ex As Exception EventLog1.WriteEntry(String.Format("Could not open the active document.{0}{1}", vbCrLf, ex.Message)) 'Return False GoTo NOGOOD End Try [...] [... OTHER CODE THAT REFERENCES acAppComObj AND acDocComObj WORKS FINE] [...] 'plot pdf acDocComObj.SendCommand("-AUTOPLOTTOPDF ")
So the SendCommand never fires. Also, the application never becomes visible. Is it possible that the SendCommand will only fire in a visible app?
If I break on the acAppComObj.Visible = True line and step through it, .Visible always stays False. It does not error.
However, if I break on that same line and manually set it to True using an immediate command, This messagebox pops up:
cannot find the interop type that matches the embedded type 'autocad.iacadapplication'. are you missing an assembly reference?
So it is refernecing IAcadApplication rather than AcadApplication.
Is this because I am writing a Service app? How can I fix this?
Thanks!!