ObjectARX帮助文档的.net版本(第二章)
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align=center>第二章<FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> AutoCAD</FONT></SPAN>数据库入门<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1"> AutoCAD</FONT></SPAN>数据库中存储了组成<FONT face="Times New Roman">AutoCAD</FONT>图形的对象和实体。本章讨论数据库的关键元素:实体,符号表和命名对象字典。
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="mso-tab-count: 1"><FONT face="Times New Roman"> </FONT></SPAN>这一章也会介绍对象<FONT face="Times New Roman">ID</FONT>和打开数据库对象的接口。还会给出创建实体、层和组及向数据库加入对象的例子。
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align=center><FONT face="Times New Roman">AutoCAD</FONT>数据库概览
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1"> AutoCAD</FONT></SPAN>图形是存储在为数据库中的对象集合。数据库对象的基类是实体、符号表和字典。实体是<FONT face="Times New Roman">AutoCAD</FONT>图形中具有图形界面的一种特殊的数据库对象。直线、圆、文本、<FONT face="Times New Roman">solid</FONT>、面域、椭圆等就是实体。换句话说,实体就是用户可以在屏幕上看到并且可以操作的东西。
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="mso-tab-count: 1"><FONT face="Times New Roman"> </FONT></SPAN>符号表和字典是用来存储数据库对象的容器。这些容器对象把符号名(一个字符串)映射成一个数据库对象。每个<FONT face="Times New Roman">AutoCAD</FONT>数据库都包括一系列固定的符号表,每个符号表包括一种特定类型的符号表记录的实例。你不能在数据库中加入新的符号表。符号表的例子包括:层表(<FONT face="Times New Roman">LayerTable</FONT>,包含层表记录),块表(<FONT face="Times New Roman">BlockTable</FONT>,包括块表记录)。所有的<FONT face="Times New Roman">AutoCAD</FONT>实体都属于块表记录。
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="mso-tab-count: 1"><FONT face="Times New Roman"> </FONT></SPAN>字典提供了比符号表更通用的存储对象的容器。字典可以包含<FONT face="Times New Roman">DBObject</FONT>类(就是实体类的基类)或它的派生类的对象。当创建一个新的<FONT face="Times New Roman">AutoCAD</FONT>图形时,<FONT face="Times New Roman">AutoCAD</FONT>数据库会创建一个名为命名对象字典的字典。你可以在命名对象字典中创建新的字典,然后在创建的字典中加入新的数据库对象。
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="mso-tab-count: 1"><FONT face="Times New Roman"> </FONT></SPAN>下图展示了<FONT face="Times New Roman">AutoCAD</FONT>数据库中的主要元素。
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"> <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="mso-tab-count: 1"><FONT face="Times New Roman"> </FONT></SPAN>在<FONT face="Times New Roman">AutoCAD</FONT>编辑的过程中,你可以通过调用语句来获取当前图形所在的数据库:
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1"> </SPAN>Application.DocumentManager.MdiActiveDocument.Database<o:p></o:p></FONT>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">或者<FONT face="Times New Roman">HostApplicationServices.WorkingDatabase<o:p></o:p></FONT>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"> <o:p></o:p></FONT>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">多个数据库<o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="mso-tab-count: 1"><FONT face="Times New Roman"> </FONT></SPAN>在一个<FONT face="Times New Roman">AutoCAD</FONT>进程中可以载入多个数据库。进程中的每个对象都有一个句柄和对象<FONT face="Times New Roman">ID</FONT>。句柄唯一标识了一个数据库中的对象,对象<FONT face="Times New Roman">ID</FONT>唯一标识了所有数据库中的对象。对象<FONT face="Times New Roman">ID</FONT>只存在于一次编辑进程中,而句柄则和图形文件一起保存。和对象<FONT face="Times New Roman">ID</FONT>不同的是,当多个数据库被载入到<FONT face="Times New Roman">AutoCAD</FONT>进程中时,句柄不一定会唯一。<o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"> <o:p></o:p></FONT>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">获得对象<FONT face="Times New Roman">ID<o:p></o:p></FONT>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="mso-tab-count: 1"><FONT face="Times New Roman"> </FONT></SPAN>有了对象<FONT face="Times New Roman">ID</FONT>,你可以对实际的数据库对象进行操作。<o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="mso-tab-count: 1"><FONT face="Times New Roman"> </FONT></SPAN>你可以通过不同的方法来获得对象<FONT face="Times New Roman">ID</FONT>:<o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: -21pt; mso-list: l0 level1 lfo1; tab-stops: list 42.0pt">l<SPAN style="FONT: 7pt 'Times New Roman'"> </SPAN>创建一个对象并加入到数据库中。数据库会给加入的对象分配一个<FONT face="Times New Roman">ID</FONT>,你可以通过访问对象的<FONT face="Times New Roman">OjectID</FONT>属性来获得分配的<FONT face="Times New Roman">ID</FONT>。<o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: -21pt; mso-list: l0 level1 lfo1; tab-stops: list 42.0pt">l<SPAN style="FONT: 7pt 'Times New Roman'"> </SPAN>使用数据库接口来获得对象<FONT face="Times New Roman">ID</FONT>,这些对象都是在数据库创建的时候被自动创建的(例如九个固定的符号表和命名对象字典)。<o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: -21pt; mso-list: l0 level1 lfo1; tab-stops: list 42.0pt">l<SPAN style="FONT: 7pt 'Times New Roman'"> </SPAN>使用特定类的接口来获得对象<FONT face="Times New Roman">ID</FONT>。特定类(如符号表和字典)定义的对象会包含其它的对象。这些类提供了获得包含的对象的<FONT face="Times New Roman">ID</FONT>的接口。<o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: -21pt; mso-list: l0 level1 lfo1; tab-stops: list 42.0pt">l<SPAN style="FONT: 7pt 'Times New Roman'"> </SPAN>查询一个选择集。用户选择后,可以通过查询选择集来获取选中的对象<FONT face="Times New Roman">ID</FONT>列表。<o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt"><FONT face="Times New Roman"> <o:p></o:p></FONT>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt">基本的数据库对象<o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt">在<FONT face="Times New Roman">AutoCAD</FONT>中创建的对象都会被加入到适合它们的容器对象中。实体被加入到块表的记录中。符号表记录被加入到对应的符号表。实体和符号表之外的其它对象被加入到命名对象字典、被其它对象拥有的对象(其实这些对象最终还是被命名对象字典所拥有)或扩展的字典中。<o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt">数据库必须至少拥有以下的对象才可用:<o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: -21pt; mso-list: l1 level1 lfo2; tab-stops: list 42.0pt"><SPAN lang=EN-US style="FONT-FAMILY: Wingdings; mso-bidi-font-size: 10.5pt">l<SPAN style="FONT: 7pt 'Times New Roman'"> </SPAN></SPAN>包括块表、层表和线型表在内的九个符号表。块表最初包含三个记录:<FONT face="Times New Roman">MODEL_SPACE</FONT>,两个图纸空间记录(<FONT face="Times New Roman">PAPER_SPACE</FONT>,<FONT face="Times New Roman">PAPER_SPACE0</FONT>)。这三个块表记录表示模型空间和两个系统预定义的图纸空间布局。层表最初只包含一个记录<FONT face="Times New Roman">0</FONT>层。线型表最初只包含<SPAN lang=EN-US><FONT face="Times New Roman">CONTINUOUS</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">线型。</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: -21pt; mso-list: l1 level1 lfo2; tab-stops: list 42.0pt"><SPAN lang=EN-US style="FONT-FAMILY: Wingdings; mso-bidi-font-size: 10.5pt">l<SPAN style="FONT: 7pt 'Times New Roman'"> </SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">一个命名对象字典。当一个数据库创建后,这个字典就包含了以下四个数据库字典:组字典、多线样式字典、布局字典和打印样式命名字典。在多线样式字典中,<FONT face="Times New Roman">STANDARD</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">样式总是存在的。</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">当你给<FONT face="Times New Roman">Database</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类的构造函数的<FONT face="Times New Roman">buildDefaultDrawing</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">参数传递<FONT face="Times New Roman">true</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">时,上面介绍的这些对象会被自动创建。如果传递<FONT face="Times New Roman">false</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">,则会创建一个可以载入<FONT face="Times New Roman">DWG</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">或<FONT face="Times New Roman">DXF</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">文件的空数据库。<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt"><SPAN lang=EN-US><FONT face="Times New Roman"> <o:p></o:p></FONT></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt"><SPAN lang=EN-US><FONT face="Times New Roman"> <o:p></o:p></FONT></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在<FONT face="Times New Roman">AutoCAD</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中创建对象<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这一部分向大家介绍在<FONT face="Times New Roman">AutoCAD</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中创建直线、圆、层和组,并展示<FONT face="Times New Roman">AutoCAD</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是怎样把这些对象加入到数据库中的。首先,假定用户使用下列命令在模型空间中创建了一条直线:<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 21pt"><SPAN lang=EN-US style="COLOR: #006600"><FONT face="Times New Roman">line 4,2 10,7<o:p></o:p></FONT></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt">在数据库中,<FONT face="Times New Roman">AutoCAD</FONT>先创建了一个<FONT face="Times New Roman">Line</FONT>类的实例,然后把它存储在模型空间块表记录中,如下图所示:<o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt"><SPAN style="mso-tab-count: 1"><FONT face="Times New Roman"> </FONT><o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt">当你首次启动<FONT face="Times New Roman">AutoCAD</FONT>时,数据库处于缺省状态,实体被加入到模型空间,它是<FONT face="Times New Roman">AutoCAD</FONT>的主空间,被用于模型几何体和图形。图纸空间是用来支持“文档”几何体和图形的。生成实体的命令(<FONT face="Times New Roman">LINE</FONT>,对应于这个例子)把实体加入到当前的数据库中,并把它加入到模型空间块中。你可以查询实体所属的数据库和块。<o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt">接下来,假定用户用下面的命令创建了一个圆:<o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 21pt"><SPAN lang=EN-US style="COLOR: teal"><FONT face="Times New Roman">circle 9,3 2</FONT></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 21pt"><SPAN lang=EN-US style="COLOR: teal"><FONT face="Times New Roman"><o:p></o:p></FONT></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt">同样地,<FONT face="Times New Roman">AutoCAD</FONT>创建了对应实体(这次是<FONT face="Times New Roman">Circle</FONT>)的实例,然后把它加入到模型空间块表记录中。
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt"><o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt"><SPAN style="mso-field-code: 'SHAPE* MERGEFORMAT'; mso-field-lock: yes"><o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt">接下来,用户创建了一个新层:<o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 21pt"><SPAN lang=EN-US style="COLOR: green"><FONT face="Times New Roman">layer _make mylayer<o:p></o:p></FONT></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN lang=EN-US style="COLOR: green"><SPAN style="mso-tab-count: 1"> </SPAN>AutoCAD</FONT></SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">创建了一个新的层表记录来表示这个层,然后把这个记录加入到层表中。<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"> <o:p></o:p></FONT>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="mso-field-code: 'SHAPE* MERGEFORMAT'; mso-field-lock: yes"><o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">最后,用户把所有的实体组合在一起。<o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt"><SPAN lang=EN-US style="COLOR: green"><FONT face="Times New Roman">group 3,2 9,3<o:p></o:p></FONT></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: black"><FONT face="Times New Roman">AutoCAD</FONT></SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">创建一个新的组对象,然后把它加入到组字典中,组字典包含在命名对象字典中。这个新的组包括组成这个组的对象的<FONT face="Times New Roman">ID</FONT></SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: black"><SPAN style="mso-field-code: 'SHAPE* MERGEFORMAT'; mso-field-lock: yes"><o:p></o:p></SPAN></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: black"><FONT face="Times New Roman"><o:p></o:p></FONT></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: black"><FONT face="Times New Roman"><o:p></o:p></FONT></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: black"><FONT face="Times New Roman"><o:p></o:p></FONT></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: black"><FONT face="Times New Roman"><o:p></o:p></FONT></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: black"><FONT face="Times New Roman"><o:p></o:p></FONT></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: black"><FONT face="Times New Roman"><o:p></o:p></FONT></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: black"><FONT face="Times New Roman"><o:p></o:p></FONT></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: black"><FONT face="Times New Roman"> <o:p></o:p></FONT></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: black"><FONT face="Times New Roman"> <o:p></o:p></FONT></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: black"><FONT face="Times New Roman"> <o:p></o:p></FONT></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在<FONT face="Times New Roman">ObjectARX</FONT></SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中创建对象<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这部分的<FONT face="Times New Roman">ObjectARX</FONT></SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">代码示例向你演示如何创建一些<FONT face="Times New Roman">AutoCAD</FONT></SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">实体(直线和圆)、创建一个新层、改变直线的颜色、加入一个组到组字典中。<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: black"><FONT face="Times New Roman"> <o:p></o:p></FONT></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: black"><FONT face="Times New Roman"> <o:p></o:p></FONT></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">创建实体<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">下面的<SPAN lang=EN-US>CreateLine()函数创建一条直线并把它加入到模型空间块表记录中:</SPAN><SPAN lang=EN-US style="COLOR: black"><o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left>public <SPAN style="COLOR: blue">void CreateLine()<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left>{<o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> Point3d startPoint=new Point3d(4,2,0);<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> Point3d endPoint=new Point3d(10,7,0);<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> Lines line=new Lines(startPoint,endPoint);<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> Database db= Application.DocumentManager.MdiActiveDocument.Database;<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> ObjectId btID=db.BlockTableId;<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> BlockTable bt=(BlockTable)btID.Open(OpenMode.ForRead);<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> ObjectId btrID=bt;<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> BlockTableRecord btr=(BlockTableRecord)btrID.Open(OpenMode.ForWrite);<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> bt.Close();<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> btr.AppendEntity(line);<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> btr.Close();<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> line.Close();<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">}<o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">CreateLine()首先获取当前图形的块表,然后打开模型空间块表记录用于写入。关闭块表后,向块表记录中加入实体,最后关闭块表记录和实体。<o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">注意:当你使用完<SPAN lang=EN-US>ObjectARX对象后,你必须尽快地显式关闭它们。呵呵,就好像要大家节约用水一样,用完水以后要记得关上水龙头。不过你可能注意到在你编译这个程序的时候,Visual Studio.net提示你最好用transaction来代替Open()和Close()函数。使用transaction的好处是你不用再手动编写关闭ObjectARX对象的代码,因为系统已经自动帮你做好了(呵呵,这就好像可以自动关闭的水龙头)。<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">下面是使用<SPAN lang=EN-US>transaction的例子。<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left>public <SPAN style="COLOR: blue">void CreateLine()<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left>{<o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> Point3d startPoint=new Point3d(4,2,0);<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> Point3d endPoint=new Point3d(10,7,0);<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> Line line=new Line(startPoint,endPoint);<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> Database db= Application.DocumentManager.MdiActiveDocument.Database;<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> DBTransMan tm=db.TransactionManager;<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> using(Transaction trans=tm.StartTransaction())<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> {<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 2"> BlockTable bt=(BlockTable)tm.GetObject(db.BlockTableId,OpenMode::ForRead,true);<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 2"> BlockTableRecord</SPAN> <SPAN style="COLOR: black">btr=(BlockTableRecord) tm.GetObject(bt,OpenMode::ForWrite,true);<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 2"> btr</SPAN>.<SPAN style="COLOR: black">AppendEntity(line);<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 2"> tm.AddNewlyCreatedDBObject(line,true);<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 2"> trans.Commit();<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> }<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">}<o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">在以后的例子,我都会用<SPAN lang=EN-US>transaction来写相关的代码。<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">下面的<SPAN lang=EN-US>CreateCircle()函数创建一个圆并把它加入到模型空间块表记录中:<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left>public <SPAN style="COLOR: blue">void CreateCircle()<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left>{<o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> Point3d center=new Point3d(9.0,3.0,0.0);<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> Vector3d normal=new Vector3d(0.0,0.0,1.0);<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> Circle circle=new Circle(center,normal,2.0);<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> Database db= Application.DocumentManager.MdiActiveDocument.Database;<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> DBTransMan tm=db.TransactionManager;<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> using(Transaction trans=tm.StartTransaction())<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> {<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 2"> BlockTable bt=(BlockTable)tm.GetObject(db.BlockTableId,OpenMode::ForRead,true);<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 2"> BlockTableRecord</SPAN> <SPAN style="COLOR: black">btr=(BlockTableRecord) tm.GetObject(bt,OpenMode::ForWrite,true);<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 2"> btr</SPAN>.<SPAN style="COLOR: black">AppendEntity(circle);<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 2"> tm.AddNewlyCreatedDBObject(circle,true);<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 2"> trans.Commit();<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> }<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left> <o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">}<o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">下面的代码演示了如何从数据库中获得层表,创建一个新的层表记录,命名这个记录<SPAN lang=EN-US>(ASDK_MYLAYER)。层表记录最后被加入到层表中。<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left>public <SPAN style="COLOR: blue">void CreateNewLayer()<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left>{<o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> Database db= Application.DocumentManager.MdiActiveDocument.Database;<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> DBTransMan tm=db.TransactionManager;<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> using(Transaction trans=tm.StartTransaction())<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> {<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 2"> LayerTable lt=( LayerTable)tm.GetObject(db.LayerTableId,OpenMode::ForWrite,true);<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 2"> LayerTableRecord</SPAN> <SPAN style="COLOR: black">ltr=new LayerTableRecord();<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 2"> ltr.Name="ASDK_MYLAYER";<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> lt.Add(ltr);<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 2"> </SPAN>tm.<SPAN style="COLOR: black">AddNewlyCreatedDBObject(ltr,true);<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 2"> trans.Commit();<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> }<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">}<o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: black; mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"> <o:p></o:p></FONT></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: black; mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"> <o:p></o:p></FONT></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">打开</SPAN><SPAN lang=EN-US style="COLOR: black; mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">ObjectARX</FONT></SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">对象</SPAN><SPAN lang=EN-US style="COLOR: black; mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">这部分的代码向你讲述当你处理数据库驻留对象时,你必须遵守的打开和关闭对象的规则。这个规则会保证当需要访问对象时它们会在内存中,当不需要它们的时候则被记录到磁盘。在你修改一个对象之前,你必须像下面的例子一样打开它:</SPAN><SPAN lang=EN-US style="COLOR: black; mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN lang=EN-US style="COLOR: black; mso-bidi-font-size: 10.5pt">tm.GetObject(objId</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt">,OpenMode::ForWrite,true);<SPAN style="COLOR: black"><o:p></o:p></SPAN></SPAN></FONT>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: black; mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">OpenMode</FONT></SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">是一个枚举类型,它表示你打开对象是用来读</SPAN><SPAN lang=EN-US style="COLOR: black; mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">(ForRead)</FONT></SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">、写</SPAN><SPAN lang=EN-US style="COLOR: black; mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">(ForWrite)</FONT></SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">或通知</SPAN><SPAN lang=EN-US style="COLOR: black; mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">(ForNotify)</FONT></SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">。如果打开对象是用来写的话,那么你可以修改它。</SPAN><SPAN lang=EN-US style="COLOR: black; mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">一个新生成的对象实例被认为是打开用来写的。一个对象只有被加入到数据库后才能关闭。你可以在对象被加入到数据库之前自由地删除它。但如果对象已被加入到数据库后,你就不能直接删除它。你可以调用</SPAN><SPAN lang=EN-US style="COLOR: black; mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">DBObject</FONT></SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">的</SPAN><SPAN lang=EN-US style="COLOR: black; mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">Erase()</FONT></SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">函数来擦除它。被擦除的对象仍然会保留在数据库中直到数据库被销毁为止,但当</SPAN><SPAN lang=EN-US style="COLOR: black; mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">AutoCAD</FONT></SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">图形被保存时,它不会被保存。</SPAN><SPAN lang=EN-US style="COLOR: black; mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="COLOR: red; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">警告!</SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">如果直接删除</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">已加入到数据库中的对象,那么会导致</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">AutoCAD</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">终止。</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman"> <o:p></o:p></FONT></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">在组字典中加入一个组</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">下面的代码使用</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">CreateLine()</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">函数和</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">CreateCircle()</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">函数创建的直线和圆来创建一个组,然后把这个组加入到组字典中。直线和圆的</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face="Times New Roman">ID</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.5pt">被当作参数传递到函数中。请注意组字典是如何打开用于写、修改。</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left>public <SPAN style="COLOR: blue">void CreateGroup(ObjectIdCollection objIds,string groupName)<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left>{<o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> Group group=new Group(groupName,true);<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> group.Append(objIds);<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> Database db= Application.DocumentManager.MdiActiveDocument.Database;<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> DBTransMan tm=db.TransactionManager;<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> using(Transaction trans=tm.StartTransaction())<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> {<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 2"> DBDictionary groupDict =<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left>(<SPAN style="COLOR: black">DBDictionary)tm.GetObject(db.GroupDictionaryId,OpenMode::ForWrite,true);<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 2"> groupDict</SPAN>.<SPAN style="COLOR: black">SetAt(groupName,group);<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 2"> tm.AddNewlyCreatedDBObject(groupp,true);<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 2"> trans.Commit();<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 1"> }<o:p></o:p></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left> <o:p></o:p>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">}<SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN>
页:
[1]