如何制作一个独立的autocad .net应用程序

本文关键字:独立 autocad net 应用程序 一个 何制作 | 更新日期: 2023-09-27 18:06:48

我试图使一个应用程序,它的一部分需要一些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

如何制作一个独立的autocad .net应用程序

IID {10E73D12-A037-47E5-8464-9B0716BE3990}是安装不正确的AutoCAD 2017 AcadApplication的IID。

您需要使用ProgId: AutoCAD.Application。使用Autodesk.AutoCAD.Interop.dll和Autodesk.AutoCAD.Interop.Common.dll 20.0.51.0作为您使用AutoCAD 2015安装的参考。我想你实际上使用的是21.0.52.0 (AutoCAD 2017)。