[ARX]版主、高手进来
关于添加扩展数据时,遇到一个大问题,运行addXData() 时打印出:ERROR: could not set Data :eRegappIdNotFound ,没能把数据添加,怎么办呢?(If any of the regappNames in xdata are not in the APPID table, then Acad::eRegappIdNotFound is returned <BR>说明我们注册appName不成功 ?acdbRegApp(appName);可能不成功,它返回的是一个数字,-5001 )
//--------------<BR>void addXData() <BR>{<BR> Acad::ErrorStatus es;<BR> struct resbuf *pRb, *pTemp;<BR> AcDbSymbolTable * appTable;
char * appName="Test";
char * resString="abcdefgffff";
AcDbDatabase *pDb=acdbHostApplicationServices()->workingDatabase();
pDb->getRegAppTable(appTable,AcDb::kForWrite);
pRb = appTable->xData(appName);
if (pRb == NULL)<BR> {<BR> acdbRegApp(appName);<BR> pRb = acutNewRb(AcDb::kDxfRegAppName);
pTemp = pRb;<BR> pTemp->resval.rstring = (char*) malloc(strlen(appName) + 1);<BR> strcpy(pTemp->resval.rstring, appName);<BR> <BR> }<BR> else<BR> {<BR> for (pTemp = pRb; pTemp->rbnext != NULL;<BR> pTemp = pTemp->rbnext)<BR> { ; }<BR> <BR> acutPrintf("pRb != NULL\n"); <BR> }<BR> <BR> pTemp->rbnext = acutNewRb(AcDb::kDxfXdAsciiString);<BR> pTemp = pTemp->rbnext;<BR> pTemp->resval.rstring<BR> = (char*) malloc(strlen(resString) + 1);<BR> strcpy(pTemp->resval.rstring, resString);
appTable->upgradeOpen();
<BR> es=appTable->setXData(pRb);<BR> acutPrintf(_T("\n ERROR: could not set Data (%s)\n"),acadErrorStatusText(es)); <BR> <BR> appTable->close();
acutRelRb(pRb);
acutPrintf("add data is ok\n");<BR> <BR>}
//------------------------------------------------- 添加扩展数据要有一个目标对象,你这里没有啊给你个例子
void
<A name="" nid="55"></A><PRE class=prog_in_0>addXdata() </PRE><A name="" nid="56"></A><PRE class=prog_in_0>{</PRE><A name="" nid="57"></A><PRE class=prog_in_0> AcDbObject* pObj = selectObject(AcDb::kForRead);//选择一个对象,如一个圆什么的</PRE><A name="" nid="58"></A><PRE class=prog_in_0> if (!pObj) {</PRE><A name="" nid="59"></A><PRE class=prog_in_0> acutPrintf("Error selecting object\n");</PRE><A name="" nid="60"></A><PRE class=prog_in_0> return;</PRE><A name="" nid="61"></A><PRE class=prog_in_0> }</PRE><A name="" nid="62"></A><PRE class=prog_in_0> //让用户输入application name 和要添加到xdata中的字符串</PRE><A name="" nid="65"></A><PRE class=prog_in_0> char appName, resString;</PRE><A name="" nid="67"></A><PRE class=prog_in_0> appName = resString = '\0';</PRE><A name="" nid="68"></A><PRE class=prog_in_0> acedGetString(NULL, "Enter application name: ",</PRE><A name="" nid="69"></A><PRE class=prog_in_0> appName);</PRE><A name="" nid="70"></A><PRE class=prog_in_0> acedGetString(NULL, "Enter string to be added: ",</PRE><A name="" nid="71"></A><PRE class=prog_in_0> resString);</PRE><A name="" nid="72"></A><PRE class=prog_in_0> </PRE><A name="" nid="73"></A><PRE class=prog_in_0> structresbuf*pRb, *pTemp;</PRE><A name="" nid="74"></A><PRE class=prog_in_0> </PRE><A name="" nid="75"></A><PRE class=prog_in_0> pRb = pObj-><FONT style="BACKGROUND-COLOR: #0a246a" color=#ffffff>xData</FONT>(appName);</PRE><A name="" nid="76"></A><PRE class=prog_in_0> if (pRb != NULL) {</PRE><A name="" nid="77"></A><PRE class=prog_in_0> // 如果 <FONT style="BACKGROUND-COLOR: #0a246a" color=#ffffff>xdata</FONT> 存在,就找到扩展数据的尾部</PRE><A name="" nid="80"></A><PRE class=prog_in_0> for (pTemp = pRb; pTemp->rbnext != NULL;</PRE><A name="" nid="81"></A><PRE class=prog_in_0> pTemp = pTemp->rbnext)</PRE><A name="" nid="82"></A><PRE class=prog_in_0> { ; }</PRE><A name="" nid="83"></A><PRE class=prog_in_0> } else {</PRE><A name="" nid="84"></A><PRE class=prog_in_0> // <FONT style="BACKGROUND-COLOR: #0a246a" color=#ffffff>xdata</FONT> 不存在,就注册 appName<A name="" nid="89"></A> </PRE><PRE class=prog_in_0> acdbRegApp(appName);</PRE><A name="" nid="91"></A><PRE class=prog_in_0> pRb = acutNewRb(AcDb::kDxfRegAppName);</PRE><A name="" nid="92"></A><PRE class=prog_in_0> pTemp = pRb;</PRE><A name="" nid="93"></A><PRE class=prog_in_0> pTemp->resval.rstring</PRE><A name="" nid="94"></A><PRE class=prog_in_0> = (char*) malloc(strlen(appName) + 1);</PRE><A name="" nid="95"></A><PRE class=prog_in_0> strcpy(pTemp->resval.rstring, appName);</PRE><A name="" nid="96"></A><PRE class=prog_in_0> }</PRE><A name="" nid="97"></A><PRE class=prog_in_0></PRE><A name="" nid="98"></A><PRE class=prog_in_0> // 添加用户输入的字符串到<FONT style="BACKGROUND-COLOR: #0a246a" color=#ffffff>xdata</FONT>.</PRE><PRE class=prog_in_0><A name="" nid="100"></A> pTemp->rbnext = acutNewRb(AcDb::kDxfXdAsciiString);</PRE><A name="" nid="101"></A><PRE class=prog_in_0> pTemp = pTemp->rbnext;</PRE><A name="" nid="102"></A><PRE class=prog_in_0> pTemp->resval.rstring</PRE><A name="" nid="103"></A><PRE class=prog_in_0> = (char*) malloc(strlen(resString) + 1);</PRE><A name="" nid="104"></A><PRE class=prog_in_0> strcpy(pTemp->resval.rstring, resString);</PRE><A name="" nid="105"></A><PRE class=prog_in_0></PRE><PRE class=prog_in_0> pObj->upgradeOpen();</PRE><A name="" nid="110"></A><PRE class=prog_in_0> pObj->setXData(pRb);</PRE><A name="" nid="111"></A><PRE class=prog_in_0> </PRE><A name="" nid="112"></A><PRE class=prog_in_0> pObj->close();</PRE><A name="" nid="113"></A><PRE class=prog_in_0> acutRelRb(pRb);</PRE><A name="" nid="114"></A><PRE class=prog_in_end_0>}</PRE> 谢谢<A name=36619><FONT color=#000066><B>warmrain</B></FONT></A>!添加扩展数据要有一个目标对象,我的目标是appTable啊, appTable->xData是存在的函数啊。
页:
[1]