添加扩展数据要有一个目标对象,你这里没有啊给你个例子
void
addXdata() { AcDbObject* pObj = selectObject(AcDb::kForRead);//选择一个对象,如一个圆什么的 if (!pObj) { acutPrintf("Error selecting object\n"); return; } //让用户输入application name 和要添加到xdata中的字符串 char appName[132], resString[200]; appName[0] = resString[0] = '\0'; acedGetString(NULL, "Enter application name: ", appName); acedGetString(NULL, "Enter string to be added: ", resString); struct resbuf *pRb, *pTemp; pRb = pObj->xData(appName); if (pRb != NULL) { // 如果 xdata 存在,就找到扩展数据的尾部 for (pTemp = pRb; pTemp->rbnext != NULL; pTemp = pTemp->rbnext) { ; } } else { // xdata 不存在,就注册 appName acdbRegApp(appName); pRb = acutNewRb(AcDb::kDxfRegAppName); pTemp = pRb; pTemp->resval.rstring = (char*) malloc(strlen(appName) + 1); strcpy(pTemp->resval.rstring, appName); } // 添加用户输入的字符串到xdata. pTemp->rbnext = acutNewRb(AcDb::kDxfXdAsciiString); pTemp = pTemp->rbnext; pTemp->resval.rstring = (char*) malloc(strlen(resString) + 1); strcpy(pTemp->resval.rstring, resString); pObj->upgradeOpen(); pObj->setXData(pRb); pObj->close(); acutRelRb(pRb); } |