我正在尝试创建一个应用程序,其中一部分需要一些autocad功能。所以我尝试在互联网上进行独立应用程序,但没有任何反应,我总是返回错误。 (它不是插件,只是打开预先安装的autocad并绘制一些东西) 我的第一次尝试:
AcadApplication gbl_app = new AcadApplication();
AcadDocument gbl_doc = gbl_app.ActiveDocument;
gbl_app.Application.Visible = true;
这是第一行中出现的错误。
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in SBDesign.exe
Additional information:
Retrieving the COM class factory for component with CLSID {0D327DA6-B4DF-4842-B833-2CFF84F0948F}
failed due to the following error: 80040154
Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
我的第二次尝试:
AcadApplication acAppComObj = null;
const string strProgId = "AutoCAD.Application.20";
// Get a running instance of AutoCAD
try
{
acAppComObj = (AcadApplication)Marshal.GetActiveObject(strProgId);
}
catch // An error occurs if no instance is running
{
try
{
// Create a new instance of AutoCAD
acAppComObj = (AcadApplication)Activator.CreateInstance(Type.GetTypeFromProgID(strProgId), true);
}
catch(Exception er)
{
// If an instance of AutoCAD is not created then message and exit
System.Windows.Forms.MessageBox.Show("Instance of 'AutoCAD.Application'" +
" could not be created.");
return;
}
}
// Display the application and return the name and version
acAppComObj.Visible = true;
System.Windows.Forms.MessageBox.Show("Now running " + acAppComObj.Name +
" version " + acAppComObj.Version);
这就是错误:
Unable to cast COM object of type 'System.__ComObject' to interface type 'Autodesk.AutoCAD.Interop.AcadApplication'.
This operation failed because the QueryInterface call on the COM component for
the interface with IID '{10E73D12-A037-47E5-8464-9B0716BE3990}'
failed due to the following error:
No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
那么我怎样才能创建一个独立的应用程序?
谢谢 A.H
答案 0 :(得分:0)
IID {10E73D12-A037-47E5-8464-9B0716BE3990}是AutoCAD 2017 AcadApplication的IID,似乎未正确安装。
您需要使用ProgId:AutoCAD.Application.20并使用Autodesk.AutoCAD.Interop.dll和Autodesk.AutoCAD.Interop.Common.dll 20.0.51.0作为参考,以使用AutoCAD 2015安装。我认为您实际上使用的是21.0.52.0(AutoCAD 2017)。