我想讓應用程序的一部分需要一些autocad功能。所以我嘗試了獨立應用程序在互聯網上的任何事情,但沒有發生,我總是返回一個錯誤。 (它不是插件,只需打開預先安裝AutoCAD和借鑑的東西) 我第一次嘗試:如何製作一個獨立的autocad .net應用程序
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
「AutoCAD.Application.20」僅適用於AutoCAD 2015和2016.嘗試使用「AutoCAD.Application」來定位任何AutoCAD版本(LT除外)。 – gileCAD
當我使用「AutoCAD.Application」時,什麼也沒有發生。我的autocad是2015 –
@gileCAD我嘗試過「AutoCAD.Application」,但是我得到了「AutoCAD.Application.20」發生的同樣的錯誤。 –