[求助]求助一个关于扩展数据的问题
<P>怎么样把以前添加的AUTOCAD扩展数据更新成新的或删除</P><P>下面是网上找到的清除扩展数据的代码,我看不懂</P>
<P></P>
<P>void delXdata()<BR>{<BR> ads_name eNam;<BR> <BR> ads_point pt;<BR> <BR> int ret = acedEntSel ("\nselect an object:", eNam, pt); <BR> <BR> if ( ret!= RTNORM) <BR> { <BR> return; <BR> }<BR> <BR> AcDbObjectId ObjId;<BR> <BR> acdbGetObjectId(ObjId, eNam);<BR> <BR> AcDbEntity *pEnt;<BR><BR> acdbOpenAcDbEntity(pEnt, ObjId, AcDb::kForWrite);<BR><BR> resbuf *xdata = pEnt->xData(NULL);<BR><BR> if (xdata)<BR> {<BR> xdata->rbnext = NULL;<BR> <BR> pEnt->setXData(xdata);<BR> <BR> acutRelRb(xdata);<BR> }<BR> <BR> pEnt->close();<BR>}</P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 2"> public void delXdata()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 2"> {<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 3"> ads_name eNam;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 3"> ads_point pt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 3"> int ret = acedEntSel ("\nselect an object:", eNam, pt); //</SPAN>点选获得一个实体<SPAN lang=EN-US><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 3"> if ( ret!= RTNORM) <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 3"> { <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 4"> return; <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 3"> }<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 3"> AcDbObjectId ObjId;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 3"> acdbGetObjectId(ObjId, eNam); //</SPAN>获得实体的<SPAN lang=EN-US>ID<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 3"> AcDbEntity *pEnt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><o:p> </o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 3"> acdbOpenAcDbEntity(pEnt, ObjId, AcDb::kForWrite); //</SPAN>通过<SPAN lang=EN-US>ObjectID打开实体来编辑<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><o:p> </o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 3"> resbuf *xdata = pEnt->xData(NULL); //</SPAN>获取实体的扩展数据结果缓冲区链表<SPAN lang=EN-US><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><o:p> </o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 3"> if (xdata) //</SPAN>如果该扩展数据结果缓冲区链表不为空<SPAN lang=EN-US><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 3"> {<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 4"> xdata->rbnext = NULL; //</SPAN>将该结果缓冲区链表的后续指针置为空<SPAN lang=EN-US><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 4"> pEnt->setXData(xdata); //</SPAN>将该实体的扩展数据设为置为空了的结果缓冲区<SPAN lang=EN-US><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 4"> acutRelRb(xdata); //</SPAN>释放链表<SPAN lang=EN-US><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 3"> }<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-tab-count: 3"> pEnt->close();<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="mso-tab-count: 2"> }</SPAN></P> <P><FONT face=宋体>本想发贴咨询一下在</FONT>AutoCAD 2007.NET API<FONT face=宋体>中,用</FONT>C<FONT face=宋体>#中如何给实体设置</FONT>XData<FONT face=宋体>扩展属性,现就此贴延续一下了,希望能把</FONT>XData<FONT face=宋体>彻底弄清楚。<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">在<FONT face="Times New Roman">VC60</FONT>下的<FONT face="Times New Roman">XData</FONT>的添加方法,<FONT face="Times New Roman">Autodesk</FONT>公司的示例文档中有很好的代码:</P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman">void </FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman">addXdata() </FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman">{</FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> AcDbObject* pObj = selectObject(AcDb::kForRead);</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> if (!pObj) {</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> acutPrintf("Error selecting object\n");</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> return;</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> }</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><o:p><FONT face="Times New Roman"> </FONT></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="mso-spacerun: yes"><FONT face="Times New Roman"> </FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> // Get the application name and string to be added to</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> // xdata.</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> //</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> char appName, resString;</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> appName = resString = '\0';</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><o:p><FONT face="Times New Roman"> </FONT></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> acedGetString(NULL, "Enter application name: ",</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> appName);</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> acedGetString(NULL, "Enter string to be added: ",</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> resString);</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><o:p><FONT face="Times New Roman"> </FONT></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> </FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> struct resbuf *pRb, *pTemp;</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="mso-spacerun: yes"><FONT face="Times New Roman"> </FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> pRb = pObj->xData(appName);</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><o:p><FONT face="Times New Roman"> </FONT></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> if (pRb != NULL) {</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><o:p><FONT face="Times New Roman"> </FONT></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> // If xdata is present, then walk to the</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> // end of the list.</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> //</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> for (pTemp = pRb; pTemp->rbnext != NULL;</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> pTemp = pTemp->rbnext)</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> { ; }</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> } else {</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-outline-level: 1"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> // If xdata is not present, register the application</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> // and add appName to the first resbuf in the list.</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-outline-level: 1"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> // Notice that there is no -3 group as there is in</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> // AutoLISP. This is ONLY the xdata so</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> // the -3 xdata-start marker isn't needed.</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> // </FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> acdbRegApp(appName);</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><o:p><FONT face="Times New Roman"> </FONT></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> pRb = acutNewRb(AcDb::kDxfRegAppName);</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> pTemp = pRb;</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> pTemp->resval.rstring</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> = (char*) malloc(strlen(appName) + 1);</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> strcpy(pTemp->resval.rstring, appName);</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> }</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><o:p><FONT face="Times New Roman"> </FONT></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> // Add user-specified string to the xdata.</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> //</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> pTemp->rbnext = acutNewRb(AcDb::kDxfXdAsciiString);</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> pTemp = pTemp->rbnext;</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> pTemp->resval.rstring</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> = (char*) malloc(strlen(resString) + 1);</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> strcpy(pTemp->resval.rstring, resString);</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><o:p><FONT face="Times New Roman"> </FONT></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> // The following code shows the use of upgradeOpen()</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> // to change the entity from read to write.</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> //</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> pObj->upgradeOpen();</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> pObj->setXData(pRb);</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="mso-spacerun: yes"><FONT face="Times New Roman"> </FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> pObj->close();</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes"> acutRelRb(pRb);</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face="Times New Roman">}</FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">问题是在<FONT face="Times New Roman">AutoCAD 2007.NET API</FONT>下:<o:p></o:p></P>
<P><FONT face=宋体>网上现有的只是关于</FONT>Xrecord<FONT face=宋体>的示例代码,如下:<o:p></o:p></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left>public <SPAN style="COLOR: teal">ObjectId createXrecord(string name,string salary,string division)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left>{<o:p></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> Database db = HostApplicationServices.WorkingDatabase;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> Transaction trans = db.TransactionManager.StartTransaction();<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> try<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> {<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> BlockTable bt = (BlockTable)MyT.GetObject(db.BlockTableId, OpenMode.ForWrite, false);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> BlockTableRecord br = (BlockTableRecord)MyT.GetObject(bt, OpenMode.ForWrite, false); <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> //Create the custom per-employee data<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> Xrecord xRec = new Xrecord();<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> //We want to add //Name//, //Salary// and //Division// information.<SPAN style="mso-spacerun: yes"> Here is how:<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> xRec.Data = new ResultBuffer( <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> new TypedValue((int)DxfCode.Text, name), <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> new TypedValue((int)DxfCode.Real, salary), <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> new TypedValue((int)DxfCode.Text, division));<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><o:p> </o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> //Next, we need to add this data to the //Extension Dictionary// of the employee.<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> br.CreateExtensionDictionary();<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> DBDictionary brExtDict = (DBDictionary)trans.GetObject(br.ExtensionDictionary, OpenMode.ForWrite, false);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> brExtDict.SetAt("EmployeeData", xRec); //Set our XRecord in the dictionary at //EmployeeData//.<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> trans.AddNewlyCreatedDBObject(xRec, true);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> return xRec.ObjectId;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> }<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> catch<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> {<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> return ObjectId.Null;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> } <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">}<o:p></o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><o:p> </o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">但为何添加<SPAN lang=EN-US>XData扩展数据就会报错eBadDxfSequence呢?<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left>public <SPAN style="COLOR: blue">void addXData(Entity ent,string name,string salary,string division)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> {<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> Database db = HostApplicationServices.WorkingDatabase;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> Transaction MyT = db.TransactionManager.StartTransaction();<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> try<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> {<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> BlockTable bt = (BlockTable)MyT.GetObject(db.BlockTableId, OpenMode.ForWrite, false);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> BlockTableRecord btr = (BlockTableRecord)MyT.GetObject(bt, OpenMode.ForWrite, false); <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> ent.XData = new ResultBuffer();<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> ent.XData = new ResultBuffer(<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> new TypedValue((int)DxfCode.Text, name),<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> new TypedValue((int)DxfCode.Real, salary),<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> new TypedValue((int)DxfCode.Text, division));<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> btr.AppendEntity(ent);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> MyT.AddNewlyCreatedDBObject(ent, true);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> }<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> catch<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> {<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> }<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="mso-spacerun: yes"> }<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><o:p> </o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">后来又试过如下方法: <SPAN lang=EN-US><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> Autodesk.AutoCAD.DatabaseServices.SymbolUtilityServices.IsRegAppAcadName("name");<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="mso-spacerun: yes"> pEnt.XData = new ResultBuffer(new TypedValue((int)DxfCode.ExtendedDataRegAppName,"name"));<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="mso-spacerun: yes"> pEnt.XData.Add(new TypedValue((int)DxfCode.ExtendedDataControlString, "this is a test!"));<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><o:p> </o:p></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">也报错……为<SPAN lang=EN-US>eRegappIdNotFound,应该是因为未注册应用程序名的原因,<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">求教全局函数<SPAN lang=EN-US>acdbRegApp(appName)在C#中的对应方法!!<o:p></o:p></SPAN></P> <pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> public void AddXData()<p></p></span></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> {<p></p></span></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;<p></p></span></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> ed.WriteMessage("</span><font face="宋体">添加扩充数据</font>XDATA\n");<p></p></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> PromptEntityOptions entOps = new PromptEntityOptions("</span><font face="宋体">选择要打开的对象</font>\n");<p></p></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> PromptEntityResult entRes;<p></p></span></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> entRes = ed.GetEntity(entOps);<p></p></span></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> if (entRes.Status != PromptStatus.OK)<p></p></span></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> {<p></p></span></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> ed.WriteMessage("</span><font face="宋体">选择对象失败,退出</font>");<p></p></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> return;<p></p></span></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> }<p></p></span></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> ObjectId objId = entRes.ObjectId;<p></p></span></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> Database db = HostApplicationServices.WorkingDatabase;<p></p></span></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> using (Transaction trans = db.TransactionManager.StartTransaction())<p></p></span></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> {<p></p></span></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> Entity ent = trans.GetObject(objId, OpenMode.ForWrite) as Entity ;<p></p></span></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> ent.ColorIndex = 1;<p></p></span></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><p> </p></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> RegAppTable appTbl = trans.GetObject(db.RegAppTableId, OpenMode.ForWrite) as RegAppTable ;<p></p></span></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> if (!appTbl.Has("MyAppName"))<p></p></span></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> {<p></p></span></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> RegAppTableRecord appTblRcd = new RegAppTableRecord();<p></p></span></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> appTblRcd.Name = "MyAppName";<p></p></span></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> appTbl.Add(appTblRcd);<p></p></span></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> trans.AddNewlyCreatedDBObject(appTblRcd, true);<p></p></span></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> }<p></p></span></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> ResultBuffer resBuf = new ResultBuffer();//new TypedValue(1001, "MyAppName"), new TypedValue(1000, "</span><font face="宋体">开发部门</font>"));<p></p></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><p> </p></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> resBuf.Add(new TypedValue(1001, "MyAppName"));//</span><font face="宋体">注册程序名称<p></p></font></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> resBuf.Add(new TypedValue(1000 , " Hongxian Qin"));//</span><font face="宋体">姓名<p></p></font></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> resBuf.Add(new TypedValue(1000 , " </span><font face="宋体">工程部</font>"));//<font face="宋体">部门<p></p></font></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> resBuf.Add(new TypedValue(1040, 2000.0));//</span><font face="宋体">薪水<p></p></font></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> ent.XData = resBuf;<p></p></span></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> trans.Commit();<p></p></span></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> }<p></p></span></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<p></p></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="mso-spacerun: yes;"> }<p></p></span></pre><pre style="BACKGROUND: #e6e6e6; tab-stops: 21.75pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><p> </p></pre> <p> <br/> public void GETXDATA()<br/> {<br/> Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;<br/> ed.WriteMessage("获取扩充数据XDATA\n");</p><p> PromptEntityOptions entOps = new PromptEntityOptions("选择要打开的对象");<br/> PromptEntityResult entRes = ed.GetEntity(pr);<br/> if (entRes.Status != PromptStatus.OK)<br/> {<br/> ed.WriteMessage("选择对象失败,退出");<br/> return;<br/> }<br/> Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;<br/> using (Transaction tr = db.TransactionManager.StartTransaction())<br/> {</p><p> Entity ent = (Entity)tr.GetObject(res.ObjectId, OpenMode.ForRead);<br/> ResultBuffer resBuf = ent.XData;<br/> if (rb != null)<br/> {<br/> //<br/> IEnumerator iter = resBuf.GetEnumerator();<br/> while (iter.MoveNext())<br/> {<br/> TypedValue tmpVal = (TypedValue)iter.Current;<br/> ed.WriteMessage(tmpVal.TypeCode.ToString() + ":");<br/> ed.WriteMessage(tmpVal.Value.ToString() + "\n");<br/> }<br/> }<br/> }<br/> }</p>
页:
[1]