使用wblockCloneObjects从后台读取dwg文件复制实体到当前数据库
Posted edata
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用wblockCloneObjects从后台读取dwg文件复制实体到当前数据库相关的知识,希望对你有一定的参考价值。
AcDbDatabase *pNewDb=new AcDbDatabase(Adesk::kFalse); if (pNewDb == NULL) { return; } Acad::ErrorStatus es= pNewDb->readDwgFile(_T("D:\\123.dwg")); if (Acad::eOk != es || NULL == pNewDb) { acutPrintf(_T("\n打开dwg文件失败,错误码:%s"),acadErrorStatusText(es)); return; } AcDbObjectIdArray objIdArray; AcDbBlockTable *pBlkTbl=NULL; es= pNewDb->getBlockTable(pBlkTbl,AcDb::kForRead); if (Acad::eOk != es || NULL == pBlkTbl) { acutPrintf(_T("\n获取源数据库块表失败,错误码:%s"),acadErrorStatusText(es)); delete pNewDb; pNewDb=NULL; return; } AcDbBlockTableRecord *pMsBlkRcd=NULL; es= pBlkTbl->getAt(ACDB_MODEL_SPACE,pMsBlkRcd,AcDb::kForRead); pBlkTbl->close(); if (Acad::eOk != es || NULL == pMsBlkRcd) { acutPrintf(_T("\n获取源数据库模型空间块表记录失败,错误码:%s"),acadErrorStatusText(es)); delete pNewDb; pNewDb=NULL; return; } //遍历源数据库模型空间块记录中的实体 AcDbBlockTableRecordIterator *pIter=NULL; pMsBlkRcd->newIterator(pIter); pMsBlkRcd->close(); AcDbObjectId objId; for (pIter->start();!pIter->done();pIter->step()) { pIter->getEntityId(objId); objIdArray.append(objId); } delete pIter; //检查objectId if (objIdArray.isEmpty()) { acutPrintf(_T("\n克隆失败,源数据库的模型空间没有实体!")); delete pNewDb; pNewDb=NULL; return; } AcDbIdMapping idMap; AcDbDatabase *pDb= acdbHostApplicationServices()->workingDatabase(); //获取当前数据库的空间ID AcDbObjectId mSpaceId= pDb->currentSpaceId(); //写块克隆 忽略重定义模式 es = pNewDb->wblockCloneObjects(objIdArray,mSpaceId,idMap,AcDb::kDrcIgnore); if (Acad::eOk != es) { acutPrintf(_T("\ndeepCloneObjects失败错误码:%s"),acadErrorStatusText(es)); delete pNewDb; pNewDb=NULL; return; } //删除临时数据库 delete pNewDb; pNewDb=NULL; AcDbIdPair IdPair; AcDbObjectIdArray arrID2; //获取克隆后的和原id匹配的对象的objectid,克隆idmap是全部的id映射,包括一些附带的数据 for (int i=0;i<objIdArray.length();i++) { IdPair.setKey(objIdArray[i]); if (idMap.compute(IdPair)) { arrID2.append(IdPair.value()); } } if (!arrID2.isEmpty()) { acutPrintf(_T("\n复制:%d个对象成功!"),arrID2.length()); } #define Randmod(x) rand()%x //亮显选择集 ads_name ss,ent; acedSSAdd(NULL,NULL,ss); for (int i=0;i<arrID2.length();i++) { AcDbEntityPointer pEnt(arrID2[i],AcDb::kForWrite); if (Acad::eOk == pEnt.openStatus()) { pEnt->setColorIndex(Randmod(11)); } acdbGetAdsName(ent,arrID2[i]); acedSSAdd(ent,ss,ss); } Adesk::Int32 nLength; acedSSLength(ss,&nLength); if (nLength>0) { acedSSSetFirst(ss,NULL); } //acedCommand(RTSTR,_T("_.select"),RTPICKS,ss,RTSTR,_T(""),RTNONE); acedSSFree(ss);
以上是关于使用wblockCloneObjects从后台读取dwg文件复制实体到当前数据库的主要内容,如果未能解决你的问题,请参考以下文章
CoreData从后台线程读取数据仍然阻塞UI界面的原因及解决
仅当终端应用程序在后台打开时,使用 pyserial 从串行端口读取才有效