////添加扩展数据====================== static void TESTaddxdatacmd(){ ads_name en; ads_point pt; ////选择要添加扩展数据的对象 if(acedEntSel(_T("\n选择要添加扩展数据的实体"),en,pt) != RTNORM){ return; } AcDbObjectId entId; Acad::ErrorStatus es = acdbGetObjectId(entId,en); ////扩展数据的内容 struct resbuf* pRb; ////注册应用程序名称 acdbRegApp(_T("XData")); CString strAppName(_T("XData"));; CString str(_T("hello")); ////创建结果缓冲区链表 pRb = acutBuildList(AcDb::kDxfRegAppName,strAppName, AcDb::kDxfXdAsciiString,str, AcDb::kDxfXdInteger32,2, AcDb::kDxfXdReal,3.14, AcDb::kDxfXdWorldXCoord,pt, RTNONE); ////为选择的实体添加扩展数据 AcDbEntity* pEnt; acdbOpenAcDbEntity(pEnt,entId,AcDb::kForWrite); struct resbuf* pTemp; pTemp = pEnt->xData(_T("XData")); if(pTemp != NULL){////如果已经包含扩展数据,不再重复添加 acutRelRb(pTemp); acutPrintf(_T("它已经包含了扩展数据")); } else{ pEnt->setXData(pRb); acutPrintf(_T("\n扩展数据已赋值")); } pEnt->close(); acutRelRb(pRb); } //查看扩展数据================== static void TESTviewxdatacmd(){ ////提示用户选择要查看的扩展数据对象 ads_name en; ads_point pt; if(acedEntSel(_T("\n选择要查看的扩展数据实体"),en,pt) != RTNORM){ return; } AcDbObjectId entId; Acad::ErrorStatus es = acdbGetObjectId(entId,en); ////打开图形对象,查看是否包含扩展数据 AcDbEntity* pEnt; acdbOpenAcDbEntity(pEnt,entId,AcDb::kForRead); struct resbuf* pRb; pRb = pEnt->xData(_T("XData")); pEnt->close(); if(pRb != NULL){ ////在命令行显示所有的扩展数据 struct resbuf* pTemp; pTemp = pRb; ////首先要跳过应用程序名称 pTemp = pTemp->rbnext; acutPrintf(_T("\n字符串类型的扩展数据是:%s"),pTemp->resval.rstring); pTemp = pTemp->rbnext; acutPrintf(_T("\n整数类型的扩展数据是:%d"),pTemp->resval.rint); pTemp = pTemp->rbnext; acutPrintf(_T("\n实数类型的扩展数据是:%.2f"),pTemp->resval.rreal); pTemp = pTemp->rbnext; acutPrintf(_T("\n点坐标类型的扩展数据是:%.2f,%.2f,%.2f"),pTemp->resval.rpoint[X],pTemp->resval.rpoint[Y],pTemp->resval.rpoint[Z]); acutRelRb(pRb); } else{ acutPrintf(_T("\n该实体不包含任何的扩展数据")); } } //添加扩展字典====================== static void TESTaddrcdcmd(){ ads_name en; ads_point pt; if(acedEntSel(_T("\n选择要添加扩展记录的实体"),en,pt) != RTNORM){ return; } AcDbObjectId entId;////要添加扩展记录实体ID Acad::ErrorStatus es = acdbGetObjectId(entId,en); AcDbXrecord* pXrec = new AcDbXrecord;//= new AcDbxRecord; AcDbObject* pObj; AcDbObjectId dictObjId,xRecObjId; AcDbDictionary* pDict; ////要在扩展记录中保存的字符串 struct resbuf* pRb; /////向实体中添加扩展字典 acdbOpenObject(pObj,entId,AcDb::kForWrite); pObj->createExtensionDictionary(); dictObjId = pObj->extensionDictionary(); pObj->close(); ////向扩展字典中添加一条记录 acdbOpenObject(pDict,dictObjId,AcDb::kForWrite); pDict->setAt(_T("XRecord"),pXrec,xRecObjId); pDict->close(); ////设置扩展记录的内容 pRb = acutBuildList(AcDb::kDxfText,_T("\n直线"), AcDb::kDxfInt32,12, AcDb::kDxfReal,3.14, AcDb::kDxfXCoord,pt, RTNONE); pXrec->setFromRbChain(*pRb); pXrec->close(); acutRelRb(pRb); } //查看扩展字典============== static void TESTviewrcdcmd(){ ////提示用户选择要查看扩展记录的图形对象 ads_name en; ads_point pt; if(acedEntSel(_T("\n选择要查看扩展记录的实体"),en,pt) != RTNORM) return; AcDbObjectId entId; Acad::ErrorStatus es = acdbGetObjectId(entId,en); ////打开图形对象,获得实体扩展字典的OBJID AcDbEntity* pEnt; acdbOpenAcDbEntity(pEnt,entId,AcDb::kForRead); AcDbObjectId dictObjId = pEnt->extensionDictionary(); pEnt->close(); ////查看实体是否包含扩展字典 if(dictObjId == AcDbObjectId::kNull){ acutPrintf(_T("\n所选择的实体不包含扩展字典")); return; } ////打开扩展字典,获得与关键字'XRECORD'关联的扩展记录 AcDbDictionary* pDict; AcDbXrecord* pXrec; acdbOpenObject(pDict,dictObjId,AcDb::kForRead); pDict->getAt(_T("XRecord"),(AcDbObject* &)pXrec,AcDb::kForRead); pDict->close(); ////获得扩展记录的数据链表并关闭扩展数据对象 struct resbuf* pRb; pXrec->rbChain(&pRb); pXrec->close(); if(pRb != NULL){ ////在命令行显示所有的扩展数据 struct resbuf* pTemp; pTemp = pRb; acutPrintf(_T("\n字符串类型的扩展数据是:%s"),pTemp->resval.rstring); pTemp = pTemp->rbnext; acutPrintf(_T("\n整数类型的扩展数据是:%d"),pTemp->resval.rint); pTemp = pTemp->rbnext; acutPrintf(_T("\n实数类型的扩展数据是:%.2f"),pTemp->resval.rreal); pTemp = pTemp->rbnext; acutPrintf(_T("\n点坐标类型的扩展数据是:%.2f,%.2f,%.2f"),pTemp->resval.rpoint[X],pTemp->resval.rpoint[Y],pTemp->resval.rpoint[Z]); acutRelRb(pRb); } else{ acutPrintf(_T("\n没有找到它的扩展数据")); } }