2016-09-13 85 views
0

我想讓應用程序的一部分需要一些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

+0

「AutoCAD.Application.20」僅適用於AutoCAD 2015和2016.嘗試使用「AutoCAD.Application」來定位任何AutoCAD版本(LT除外)。 – gileCAD

+0

當我使用「AutoCAD.Application」時,什麼也沒有發生。我的autocad是2015 –

+0

@gileCAD我嘗試過「AutoCAD.Application」,但是我得到了「AutoCAD.Application.20」發生的同樣的錯誤。 –

回答

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)。

+0

你好。感謝您的回答,我的COM參考是20.0.51.0.0,但我的Autodesk.AutoCAD.Interop.common.dll是21.0.0.0。看看我的[ScreenShot](https://1drv.ms/i/s!ApRBiX7lvlBibweEWHo3Uaj0M-k)。那麼我從哪裏可以得到20.0.51.0? –

+0

_謝謝你!!!!!你解決了。對不起,如果我不能投票,因爲我的名聲低於15._真的我沒有希望,並等待這麼多重複的答案。但你搖滾的人。對於那些有我的問題的人,Autodesk.AutoCAD.Interop.Common.dll應該與你的autocad版本相同,所以我只是從'DRIVE:\ Program Files \ Autodesk \ AutoCAD 2015 \ Autodesk.AutoCAD.Interop.Common .dll「和」DRIVE:\ Program Files \ Autodesk \ AutoCAD 2015 \ Autodesk.AutoCAD.Interop.dll「。現在一切正常。 –

+0

我的IDE總是添加引用與錯誤的版本,所以我只是決定創建一個新的項目,並將整個代碼複製到新項目中,並且一切正常!!!!! –

相關問題