分享

AutoCAD .NET API基础(一) AutoCAD 对象层次结构(4)

 Jcstone 2012-09-09

AutoCAD .NET API基础(一) AutoCAD 对象层次结构(4)

分类: AutoCAD .NET API开发 338人阅读 评论(0) 收藏 举报

4The Graphical and Nongraphical Objects  图形对象和非图形对象

Graphical objects, also known as entities, are the visible objects (lines, circles, raster images, and so forth) that make up a drawing. Adding graphical objects to a drawing is done by referencing the correct block table record, and then using the AppendEntity method with the new object to append it to the drawing.

图形对象,又成为实体,是组成图形的可见对象(线、圆、光栅图像等等)。向当前图形添加图形对象的方法是,通过对正确的块表记录的引用,使用AppendEntity方法将要添加的新对象添加到图形中。

To modify or query objects, obtain a reference to the object from the appropriate block table record, and then use the methods or properties of the object itself. Each graphical object has methods that perform most of the same functionality as the AutoCAD editing commands such as Copy, Erase, Move, Mirror, and so forth.

要修改或查询对象,先从相应的块表记录里获得对该对象的引用,然后调用该对象自己的方法或属性。每个图形对象都拥有一些方法,这些方法实现了与大部分AutoCAD编辑命令相同的功能,像复制、删除、移动、镜像,等等。

These objects also have methods to retrieve the extended data (xdata), highlight and unhighlight, and set the properties from another entity. Most graphical objects have some properties in common with each other such as LayerId, LinetypeId, Color, and Handle. Each graphical object also has specific properties, such as Center, StartPoint, Radius, and FitTolerance.

这些对象还有一些方法,用于检索扩展数据(xdata)、亮显和取消亮显、从别的实体设置属性等。大多数图形对象都拥有一些彼此共有的属性,比如LayerIdLinetypeIdColorHandle等。另外每个图形对象还拥有自己特有的属性,比如CenterStartPointRadius,以及FitTolerance等。

Nongraphical objects are the invisible (informational) objects that are part of a drawing, such as Layers, Linetypes, Dimension styles, Table styles, and so forth. To create a new symbol table records, use the Add method on the owner table or use the SetAt method to add a dictionary to the named object dictionary. To modify or query these objects, use the methods or properties of the object itself. Each nongraphical object has methods and properties specific to its purpose; all have methods to retrieve extended data (xdata), and erase themselves.

非图形对象是图形中那部分不可见的(信息性质的)对象,像图层、线型、标注式样、表示样,等等。要新建一个符号表记录,调用该符号表的Add方法,或调用SetAt方法向命名对象字典添加一个字典。要修改或查询这些对象,调用这些对象自己的相应的方法或属性。每个非图形对象都拥有特定功能的方法和属性,所有非图形对象都拥有检索扩展数据、删除自己的方法。

 

5The Collection Objects   集合对象

AutoCAD groups most graphical and nongraphical objects into collections or container objects. Although collections contain different types of data, they can be processed using similar techniques. Each collection has a method for adding an object to or obtaining an item from a collection. Most collections use the Add or SetAt methods to add an object to a collection.

AutoCAD使用集合或容器对象对大部分图形对象和非图形对象进行了分组。尽管集合包含不同的数据类型,仍可用相似的技术对它们进行处理。每个集合都拥有把一个对象添加到集合里的方法和从集合里获取一个集合项的方法。大多数集合调用Add方法或SetAt方法将一个对象添加到集合里。

Most collections offer similar methods and properties to make them easy to use and learn. The Count property returns a zero-based count of the objects in a collection, while the Item function returns an object from a collection. Examples of collection members in the AutoCAD .NET API are:

大多数集合都提供类似的方法和属性,以便于使用和学习。Count属性返回集合里从0开始的对象计数,Item函数从集合里返回一个对象。AutoCAD .NET API中的集合成员举例如下:

·         Layer table record in the Layers symbol table 图层符号表中的图层表记录;

·         Layout in the ACAD_LAYOUT dictionary  ACAD_LAYOUT字典中的布局;

·         Document in the DocumentCollection 文档集合中的文档;

·         Attributes in a block reference 块参考中的属性;

 

 

6Non-Native Graphical and Nongraphical Objects非本地的图形对象和非图形对象

The AutoCAD .NET API is a cross implementation of ObjectARX and ActiveX Automation. While you can access ActiveX Automation from ObjectARX, .NET API makes working with the two rather seamless. As you work with objects using the native .NET API, you can access the equivalent COM object from a property. In some cases, the COM object is the only way to access an AutoCAD feature programmatically. Some examples of properties that expose COM objects through the .NET API are, Preferences, Menubar, MenuGroups, AcadObject and AcadApplication.

AutoCAD .NET API编程接口是ObjectARXActiveX Automation两种编程接口交叉实现的。当然你可以从ObjectARX访问ActiveX Automation,但通过.NET API,你可以几乎无缝的使用这两种编程技术。正像你使用本地.NET API处理对象一样,你可以从属性访问相同的COM对象。有些情况下,使用COM对象是编程访问AutoCAD功能的唯一途径。COM对象通过.NET API公开的属性的例子如:PreferencesMenubarMenuGroupsAcadObjectAcadApplication等。

Note: When working with COM objects, you will want to make sure you reference the AutoCAD 2011 type library. For information on COM Interop, see Use COM Interoperability with .NET.

注意:当与COM对象打交道时,请确认你引用了AutoCAD2011的类型库。关于COM互操作的信息,见Use COM Interoperability with .NEThttp://docs./ACD/2011/ENU/filesMDG/WS73099cc142f48755-5c83e7b1120018de8c0-23ce.htm)(尚未翻译)。

The Preferences property of the Application object provides access to a set of COM objects, each corresponding to a tab in the Options dialog box. Together, these objects provide access to all the registry-stored settings in the Options dialog box. You can also set and modify options (and system variables that are not part of the Options dialog box) with the SetSystemVariable and GetSystemVariable methods of the Application object. For more information about using the Preferences object, see the ActiveX and VBA Developer’s Guide.

Application对象的Preferences属性用来访问一组COM对象,其中的每个COM对象对应选项对话框里的一个选项页,这些对象一起用来访问选项对话框里全部的注册表存储的选项设置。你可以使用Application对象的SetSystemVariable方法GetSystemVariable方法来设置和修改选项(当然也可以设置和修改哪些不在选项对话框里的系统变量)。使用Preferences对象的更多信息,见ActiveXVBA开发指南。

Accessing COM objects is useful if you are working with existing code that might have been originally developed for VB or VBA, or even when working with a third-party library that might work with the AutoCAD ActiveX Automation library with the .NET API. Like the Preferences object, you can also access utilities which translate coordinates or define a new point based on an angle and distance using the Utility object which can be accessed from the AcadApplication COM object which is the equivalent of the Application object in the .NET API.

当你与最初可能是用VBVBA开发的代码打交道时,或者当你与那些使用了AutoCAD ActiveX Automation库和AutoCAD .NET API的第三方库打交道时,访问COM对象技术很有用。像Preferences对象那样,你还可以使用Utility对象的诸如转换坐标、基于角和距离定义新点等实用功能,Utility对象可通过COM对象AcadApplication访问,同等地,也可以通过.NET API中的Application对象访问。

Note: When working with both the AutoCAD .NET API and ActiveX Automation, and you create custom functions that might need to return an object, it is recommended to return an ObjectId instead of the object itself. For information on Object Ids, see Work with ObjectIds.

注意:当使用了AutoCAD .NET APIActiveX Automation两种技术时,如果你创建的自定义函数需要返回一个对象,建议返回ObjectId而不是对象本身,见使用ObjectIds

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多