2016-09-13 4 views
0

Ich versuche, eine Anwendung zu machen, dass ein Teil davon einige AutoCAD-Funktionen benötigt. Also habe ich alles im Internet für Standalone-Anwendungen ausprobiert, aber nichts passiert und ich gebe immer einen Fehler zurück. (Es ist nicht Plugin, nur offen vorinstalliert Autocad und zieht etwas) Meinen ersten Versuch:Wie man eine autonome autocad.net-Anwendung erstellt

AcadApplication gbl_app = new AcadApplication(); 
AcadDocument gbl_doc = gbl_app.ActiveDocument; 
gbl_app.Application.Visible = true; 

Und das ist Fehler, die in erster Linie erhöhen.

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

Mein zweiter Versuch:

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

Und das ist der Fehler:

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

Also wirklich, wie kann ich eine Standalone-Anwendung zu machen?

Danke A. h

+0

"AutoCAD.Application.20" funktioniert nur mit AutoCAD 2015 und 2016. Verwenden Sie "AutoCAD.Application", um eine AutoCAD-Version (außer LT) als Ziel zu verwenden. – gileCAD

+0

Wenn ich "AutoCAD.Application" verwende, passiert nichts. Mein AutoCAD ist 2015 –

+0

@gileCAD Ich habe "AutoCAD.Application" versucht, aber ich bekomme den gleichen Fehler, der für "AutoCAD.Application.20" passiert. –

Antwort

0

IID {10E73D12-A037-47E5-8464-9B0716BE3990} die IID von AutoCAD 2017 AcadApplication, die nicht korrekt installiert zu sein scheint.

Sie müssen die ProgId: AutoCAD.Application.20 verwenden und Autodesk.AutoCAD.Interop.dll und Autodesk.AutoCAD.Interop.Common.dll 20.0.51.0 für Ihre Referenzen verwenden, um Ihre AutoCAD 2015-Installation zu verwenden. Ich denke, Sie verwenden 21.0.52.0 (AutoCAD 2017).

+0

Hallo. Vielen Dank für Ihre Antwort. Meine COM-Referenzen sind 20.0.51.0.0, aber meine Autodesk.AutoCAD.Interop.common.dll ist 21.0.0.0. Sehen Sie sich meinen [ScreenShot] (https://1drv.ms/i/s!ApRBiX7lvlBibweEWHo3Uaj0M-k) an. Also woher bekomme ich 20.0.51.0? –

+0

_Danke !!!!! Du hast es gelöst. Sorry, wenn ich nicht wählen kann, weil mein Ruf weniger als 15 ist. Really war ich hoffnungslos und wartete auf so viele doppelte Antworten. Aber Sie rocken den Menschen. Für diejenigen, die mein Problem haben, sollte Autodesk.AutoCAD.Interop.Common.dll die gleiche Version Ihres AutoCAD sein, also habe ich Referenzen von 'DRIVE: \ Programme \ Autodesk \ AutoCAD 2015 \ Autodesk.AutoCAD.Interop.Common hinzugefügt .dll' und 'DRIVE: \ Programme \ Autodesk \ AutoCAD 2015 \ Autodesk.AutoCAD.Interop.dll'. UND alles funktioniert jetzt. !!!! –

+0

Meine IDE hat immer Referenzen mit falscher Version hinzugefügt, also habe ich mich entschieden, ein neues Projekt zu erstellen und die ganzen Codes in ein neues Projekt zu kopieren, und alles funktioniert !!!!! –

Verwandte Themen