天天看點

AutoCAD .NET API基礎(一) AutoCAD 對象層次結構(1)

Basics of the AutoCAD .NET API

AutoCAD .NET API基礎

To use the AutoCAD® .NET API effectively you should be familiar with the AutoCAD entities, objects, and features related to the tasks you want to automate. The greater your knowledge of an object's graphical and nongraphical properties, the easier it is for you to manipulate them through the AutoCAD .NET API. For information specific to the members (methods, functions or properties) of an object in the AutoCAD .NET API, see the AutoCAD .NET Reference Guide.

要想有效利用AutoCAD® .NET API程式設計接口,必須熟悉AutoCAD自動化任務相關的AutoCAD實體、對象和特性等。你對對象的圖形屬性和非圖形屬性知道的越多,使用AutoCAD® .NET API對他們進行操作就越容易。AutoCAD .NET API對象各成員(方法、函數、屬性等)的詳細資訊,請參見AutoCAD .NET參考指南。

Topics in this section:

本節内容:

·         Understand the AutoCAD Object Hierarchy 了解 AutoCAD 對象層次

·         Access the Object Hierarchy 通路對象層次

·         Collection Objects 集合對象

·         Understand Properties and Methods了解屬性和方法

·         Out-of-Process versus In-Process 程序外與程序内對比

·         Define Commands and AutoLISP Functions 定義指令和AutoLISP函數

Understand the AutoCAD Object Hierarchy

了解 AutoCAD 對象層次

An object is the main building block of the AutoCAD .NET API. Each exposed object represents a precise part of AutoCAD. There are many different types of objects in the AutoCAD .NET API. Some of the objects represented in the AutoCAD .NET API are:

對象是AutoCAD .NET API的主要構成塊。每個公開的對象都精确代表AutoCAD的一個部件。AutoCAD .NET API擁有許多不同類型的對象,例如:

·         Graphical objects such as lines, arcs, text, and dimensions直線、圓弧、文字和标注等圖形對象;

·         Style settings such as layers, linetypes, and dimension styles 圖層、線型、标注樣式等樣式設定對象;

·         Organizational structures such as layers, groups, and blocks圖層、組、塊等圖形組織結構對象;

·         The drawing display such as view and viewport 視圖、視口等圖形顯示對象;

·         Even the drawing and the AutoCAD application 乃至圖形和AutoCAD應用程式本身也是對象;

The objects are structured in a hierarchical fashion, with the AutoCAD Application object at the root. This hierarchical structure is often referred to as the Object Model. The following illustration shows the basic relationships between the Application object and an entity that is in a BlockTableRecord, such as Model space. There are many more objects in the AutoCAD .NET API that are not represented here.

所有對象以AutoCAD的Application對象為根對象,按層次結構方式組織,通常稱層次結構為對象模型。下圖所示表示了Application對象與BlockTableRecord模型空間内實體的基本關系。這裡隻列出了AutoCAD .NET API中的部分對象。

AutoCAD .NET API基礎(一) AutoCAD 對象層次結構(1)

1、The Application Object  Application對象

The Application object is the root object of the AutoCAD .NET API. From the Application object, you can access the main window as well as any open drawing. Once you have a drawing, you can then access the objects in the drawing. For information on working with open drawing files (documents) see  The Document Object.

Application對象是AutoCAD .NET API的根對象,從Application對象,可以通路AutoCAD主視窗,以及任何打開的圖形,并進而通路圖形裡的各個對象。有關處理打開圖形文檔的資訊,參見Document對象。

For example, the Application object has a DocumentManager property that returns the DocumentCollection object. This object provides access to the the drawings that are currently open in AutoCAD and allows you to create, save and open drawing files. Other properties of the Application object provide access to the application-specific data such as InfoCenter, the main window, and the status bar.The MainWindow property allows access to the application name, size, location, and visibility.

例如,Application對象有一個DocumentManager屬性,用來傳回DocumentCollection對象,該對象提供了通路目前打開的AutoCAD圖形的功能,并允許你建立、儲存、打開圖形檔案。Application對象的其他屬性提供了通路應用程式特有資料的功能,像資訊中心InfoCenter、主視窗、狀态欄等。MainWindow屬性允許通路應用程式的名稱、主視窗大小、位置及可見性等。

While most of the properties of the Application object allow access to objects in the AutoCAD .NET API, there are some that reference objects in the AutoCAD ActiveX® Automation. These properties include a COM version of the application object (AcadApplication), the menubar (MenuBar), loaded menugroups (MenuGroups), and preferences (Preferences).

Application對象的大多數屬性允許對AutoCAD .NET API裡的對象進行通路,同時也有一些屬性是對AutoCAD ActiveX® Automation裡的對象(COM對象)的引用,這些屬性包括應用程式對象的COM版本(AcadApplication)、菜單欄(MenuBar)、加載的菜單組(MenuGroups)、以及選項設定(Preferences)等。

AutoCAD .NET API基礎(一) AutoCAD 對象層次結構(1)

DocumentManager

Container for all the document objects (there is a document object for each drawing that is open). 所有文檔對象的容器(每個打開的圖形對應一個文檔對象)

DocumentWindowCollection

Container for all the document window objects (there is a document window object for each document object in the DocumentManager). 所有文檔視窗對象的容器(DocumentManager裡每個文檔對象有一個文檔視窗對象)

InfoCenter

Contains a reference to the InfoCenter toolbar. 包含對資訊中心工具欄的引用

MainWindow

Contains a reference to the application window object of AutoCAD. 包含對AutoCAD應用程式視窗對象的引用

MenuBar

Contains a reference to the MenuBar COM object for the menubar in AutoCAD. 包含對AutoCAD菜單欄對應的MenuBar COM對象的引用

MenuGroups

Contains a reference to the MenuGroups COM object which contains the customization group name for each loaded CUIx file. 包含對MenuGroups COM對象的引用,菜單組對象包含每個已加載CUIx檔案的自定義組名

Preferences

Contains a reference to the Preferences COM object which allows you to modify many of the settings in the Options dialog box. 包含對Preferences COM對象的引用,該對象允許你在選項(Options)對話框裡修改許多設定

Publisher

Contains a reference to the Publisher object which is used for publishing drawings.

包含對Publisher對象的引用,該對象用于釋出圖形

StatusBar

Contains a reference to the StatusBar object for the application window.

包含對應用程式視窗狀态欄對象(StatusBar對象)的引用

UserConfiguration

Contains a reference to the UserConfiguration object which allows you to work with user saved profiles.

包含對UserConfiguration對象的引用,該對象允許你處理使用者儲存的配置資訊

繼續閱讀