Overview of Microsoft Visual Studio
Microsoft Visual Studio概述
Microsoft Visual Studio is an object-oriented programming environment that runs independently of AutoCAD. While Microsoft Visual Studio is external to AutoCAD and other applications, it is able to interact with applications that expose either a native .NET API or ActiveX/COM library.
Microsoft Visual Studio是不依賴AutoCAD運行的面向對象編程環(huán)境。雖然Microsoft Visual Studio是AutoCAD及其他應用程序的外部環(huán)境,但它能與那些公開了自己的本地.NET API或ActiveX/COM庫的應用程序進行交互。
Topics in this section本節(jié)主題
· Which Edition of Microsoft Visual Studio to Use 使用Visual Studio哪個版本
· Use COM Interoperability with .NET 使用COM與.NET交互操作
· Dependencies and Restrictions 依賴性及限制
Microsoft Visual Studio is available in multiple versions and editions. To use the .NET API for AutoCAD 2012, you need to use:
Microsoft Visual Studio有多個版本可用。要是開發(fā)AutoCAD 2012 .NET API項目,我們需要使用:
· Microsoft Visual Studio 2010
· Microsoft .NET Framework 4.0
Note Projects compiled with Microsoft Visual Studio 2008 with a target of Microsoft .NET Framework 3.5 should load into AutoCAD 2012 without a problem. Microsoft Visual Studio 2008 cannot be used to debug projects loaded in AutoCAD 2012; you must use Microsoft Visual Studio 2010 when debugging a project.
注意:由Microsoft Visual Studio 2008編譯的目標為Microsoft .NET Framework 3.5的項目可以加載到AutoCAD2012運行沒有問題。但Microsoft Visual Studio 2008不能用來調試AutoCAD 2012加載的項目,調試項目時必須使用Microsoft Visual Studio 2010。
If you are using AutoCAD 2010 or AutoCAD 2011, you should use:
如果使用的是AutoCAD 2010或AutoCAD 2011,則應選擇:
· Microsoft Visual Studio 2008 with Service Pack 1
· Microsoft .NET Framework 3.5 with Service Pack 1
If you are using AutoCAD 2007 through AutoCAD 2009, you should use:
如果使用的是AutoCAD 2007到AutoCAD 2009,則應選擇:
· Microsoft Visual Studio 2005
· Microsoft .NET Framework 2.0 or later (或2.0以上)
Microsoft Visual Studio is offered in two editions: for free and for pay. The free edition is known as Microsoft Visual Studio 2010 Express Edition, while the for pay editions vary by name and price due to the different development tools that are incorporated into them. Microsoft Visual Studio 2010 Professional Edition provides improved debugging over Microsoft Visual Studio 2010 Express Edition along with a number of other features. The most common edition of Microsoft Visual Studio used by developers is Microsoft Visual Studio 2010 Professional Edition.
Microsoft Visual Studio有兩種版本供選擇:免費版本和付費版本。免費版本眾所周知就是Microsoft Visual Studio 2010 Express版,付費版本的名稱和價格因整合的開發(fā)工具的不同而異。Microsoft Visual Studio 2010專業(yè)版提供了比Microsoft Visual Studio 2010 Express版改進了的調試性能及其他許多特性。開發(fā)人員最常用的Microsoft Visual Studio版本就是Microsoft Visual Studio 2010專業(yè)版。
Note While it is possible to use Microsoft Visual Studio Express with the AutoCAD .NET API, this guide assumes you are using one of the other versions such as Microsoft Visual Studio 2010 Professional Edition or Microsoft Visual Studio 2010 Premium Edition.
注意:可能有人使用Microsoft Visual Studio Express版進行AutoCAD .NET API開發(fā),但本指南假設你使用的是Microsoft Visual Studio 2010專業(yè)版或Microsoft Visual Studio 2010高級版。
There are four main advantages to using Microsoft Visual Studio:
使用Microsoft Visual Studio的四大優(yōu)勢:
· Robust and accessible development environment that has a modest learning curve. 強大易用的開發(fā)環(huán)境,輕松的學習過程;
· VBA and VB.NET syntax are similar, which makes it an ideal environment for existing VBA users. VBA和VB.NET語法相近,是現有VBA開發(fā)人員理想的環(huán)境;
· Visually intuitive and extensive dialog box creation tools. 直觀、豐富的對話框創(chuàng)建工具;
· Projects can be built as a standalone executable or DLL assembly which can then be loaded into AutoCAD for execution. 可以將項目生成為獨立的可執(zhí)行程序或DLL程序集,加載到AutoCAD執(zhí)行;
Note Unlike VBA projects, .NET applications do not suffer from performance degradation when loaded and run in 64-bit AutoCAD.
注意:不像VBA項目,.NET應用程序加載并運行在64位AutoCAD環(huán)境時性能不會下降。
For more information on the different editions of Microsoft Visual Studio, see http://www.microsoft.com/vstudio and http://www.microsoft.com/express.
更多關于Microsoft Visual Studio不同版本的信息,見http://www.microsoft.com/vstudio 及 http://www.microsoft.com/express。Please send us your comments about this page
Microsoft Visual Studio can utilize both native .NET and COM interfaces in the same project. By utilizing COM interop, you can migrate existing code that might have been written in Visual Basic 6 or VBA without having to completely rewrite it. To access AutoCAD automation objects from a project created in Microsoft Visual Studio, create references to the following files:
Microsoft Visual Studio可以在同一個項目中使用本地.NET和COM兩種接口,這樣我們就可以移植現有的那些用VB6或VBA寫的代碼而不必完全重寫。要想在Microsoft Visual Studio創(chuàng)建的項目中訪問AutoCAD自動化對象,需要建立對下列文件的引用:
· The AutoCAD 2012 type library, acax18enu.tlb, located at <drive>:\Program Files\Common Files\Autodesk Shared. AutoCAD 2012類庫文件acax18enu.tlb,位于C:\ Program Files\Common Files\Autodesk Shared;
· The AutoCAD/ObjectDBX Common 18.0 type library, axdb18enu.tlb, located at <drive>:\Program Files\Common Files\Autodesk Shared. AutoCAD/ObjectDBX18.0通用類庫文件axdb18enu.tlb,位于C:\ Program Files\Common Files\Autodesk Shared;
Note The previous mentioned type libraries are also available as part of the ObjectARX SDK. For information on downloading and installing the ObjectARX SDK, see Components of the AutoCAD .NET API.
注意:前面提到的類庫文件還可以從ObjectARX SDK中得到。……
These references will make the following primary interop assemblies available:
對這些類庫的引用使得下列基本互操作程序集可用:
· Autodesk.AutoCAD.Interop.dll (for AutoCAD-specific typesAutoCAD專有類型)
· Autodesk.AutoCAD.Interop.Common.dll (for types shared by ObjectDBX? host applications ObjectDBX?宿主應用程序共享類型)
The interop assemblies are located in the global assembly cache; they map automation objects to their .NET counterparts.
互操作程序集位于全局程序集緩存;他們將自動化對象映射為.NET的對等對象。
After you reference the type libraries, you can declare AutoCAD-based variables in Microsoft Visual Studio, as in the following examples:
引用了這些類庫,我們就可以在Microsoft Visual Studio中聲明AutoCAD變量,像下面的例子:
VB.NET
Dim objAcApp As Autodesk.AutoCAD.Interop.AcadApplication
Dim objLine As Autodesk.AutoCAD.Interop.Common.AcadLine
C#
Autodesk.AutoCAD.Interop.AcadApplication objAcApp;
Autodesk.AutoCAD.Interop.Common.AcadLine objLine;
Utilizing the interop assemblies can make the transitioning your VBA projects over to VB.NET much easier. However, in order to take full advantage of everything that .NET and the AutoCAD .NET API have to offer, you will need to rewrite your existing VBA code.
應用互操作程序集使得將VBA項目轉換為VB.NET項目更容易。不過,為了充分利用.NET和AutoCAD .NET API提供的全部功能,還是要重寫現有VBA代碼。
Create and Reference the AutoCAD Application 創(chuàng)建并引用AutoCAD應用程序
AutoCAD 2012 .NET applications can utilize the same type library (acax18enu.tlb) as AutoCAD automation projects. The type library is located in <drive>:\Program Files\Common Files\Autodesk Shared.
AutoCAD 2012 .NET應用程序可以和AutoCAD自動化項目一樣利用相同的類庫(acax18enu.tlb)。該類庫位于c:\Program Files\Common Files\Autodesk Shared。
AutoCAD 2012 .NET applications also use the same version-dependent ProgID for the CreateObject, GetObject, and GetInterfaceObject functions. For example, CreateObject ("AutoCAD.Application.18") allows you to create an instance of AutoCAD and get an object that represents the new instance of the application.
AutoCAD 2012 .NET應用程序的CreateObject、GetObject和GetInterfaceObject函數也使用同樣的依賴版本的ProgID值。例如,CreateObject("AutoCAD.Application.18")允許我們創(chuàng)建一個AutoCAD的實例,并獲取代表應用程序新示例的對象。
Unlike ActiveX Automation, there are fewer issues with library conflicts when other applications are installed, reinstalled, or uninstalled. The reason for fewer compatibility issues is that the .NET Framework is a standardized platform. However, you can still run into dependency issues. To avoid dependency issues with the .NET Framework, be sure to use the same or an earlier version of the .NET Framework with your VB.NET or C# project that AutoCAD 2012 uses. For information on which version of the .NET Framework you should be referencing, see Which Edition of Microsoft Visual Studio to Use.
不像ActiveX Automation,在其他程序安裝、重裝及卸載時很少出現庫沖突的情形。很少出現兼容問題的原因在于.NET Framework是一個標準化的平臺。不過,還是會遇到依賴性問題。要避免.NET Framework依賴性問題,應確保使用與AutoCAD2012所用.NET Framework相同或更早的版本來開發(fā)VB.NET或C#項目。更多信息見使用Microsoft Visual Studio哪個版本。
聯(lián)系客服