2016-09-13 52 views
0

私は、その一部にいくつかのオートカード機能が必要なアプリケーションを作成しようとしています。だから私はスタンドアロンアプリケーションのためにインターネットで何かを試しましたが、何も起こらず、私はいつもエラーを返します。 (それは、ちょうどプリインストールオープン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)). 

私の2回目の試行:

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}が正しくインストールされていないことのようですIIDのAutoCAD 2017のAcadApplicationです。

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

_Thank you !!!!!あなたは解決しました。申し訳ありませんが、私の評判が15未満であるので投票できません。本当に私は絶望的であり、非常に多くの重複した回答を待っています。しかし、あなたはロックマン。私の問題を抱えている人には、Autodesk.AutoCAD.Interop.Common.dllはオートキャドと同じバージョンでなければならないので、私は 'DRIVE:\ Program Files \ Autodesk \ AutoCAD 2015 \ Autodesk.AutoCAD.Interop.Common .dll'と 'DRIVE:¥Program Files¥Autodesk¥AutoCAD 2015¥Autodesk.AutoCAD.Interop.dll'と入力します。そしてすべてが今働きます! –

+0

私のIDEは間違ったバージョンのリファレンスを常に追加していましたので、私はちょうど新しいプロジェクトを作成し、コード全体を新しいプロジェクトにコピーすることにしました。 –

関連する問題