码迷,mamicode.com
首页 > 数据库 > 详细

使用wblockCloneObjects从后台读取dwg文件复制实体到当前数据库

时间:2019-04-27 00:49:05      阅读:358      评论:0      收藏:0      [点我收藏+]

标签:cti   空间   jid   base   错误码   ase   object   epc   %s   

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文件复制实体到当前数据库

标签:cti   空间   jid   base   错误码   ase   object   epc   %s   

原文地址:https://www.cnblogs.com/edata/p/10777134.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!