• 将当前图纸中选中的实体克隆生成块到当前图纸 将选中的实体生成块后克隆到其他图纸


     1 AcDbObjectId CreatBlockForAcdbobjectidarr(AcDbObjectIdArray ptarr,AcGePoint3d pt, CString sName)
     2 {
     3     //创建一个块参照在当前数据库中
     4     AcDbBlockTable *pBlkTab=NULL;
     5     acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTab, AcDb::kForWrite);
     6     AcDbBlockTableRecord *pBlkTabRcd;
     7     pBlkTabRcd = new AcDbBlockTableRecord();
     8     pBlkTabRcd->setName(sName);
     9     AcDbObjectId blockId;
    10     pBlkTab->add(blockId, pBlkTabRcd);
    11     pBlkTabRcd->setOrigin(pt);//设置块的插入点 
    12     pBlkTab->close();
    13     pBlkTabRcd->close();//关闭后获得这个块的id 
    14 
    15     AcDbIdMapping         adimIdMap;
    16     AcApDocument* pDoc = acDocManager->curDocument();
    17     acDocManager->lockDocument(pDoc, AcAp::kWrite);//锁定当前文档
    18     acdbHostApplicationServices()->workingDatabase()->deepCloneObjects(ptarr, blockId, adimIdMap);//克隆当前选中的实体到块中
    19     acDocManager->unlockDocument(pDoc);//解锁文档
    20     
    21     return blockId;
    22 }
    23 
    24 bool CreatOtherDwgBlockForAcdbobjectidarr(const TCHAR *fileName, const TCHAR *blkDefName, AcDbObjectId Tid)
    25 {
    26     // 使用_SH_DENYNO参数打开图形(只读打开),允许其它用户读写该文件
    27     AcDbDatabase* pSourceDwg = new AcDbDatabase(false);
    28     Acad::ErrorStatus es = pSourceDwg->readDwgFile(fileName, _SH_DENYNO);
    29     if (es != Acad::eOk)
    30     {
    31         delete pSourceDwg;
    32         pSourceDwg = NULL;
    33 
    34         acutPrintf(TEXT("
    读入dwg图形错误, 图形名称: %s"), fileName);
    35         return false;
    36     }
    37     // 打开外部图形数据库的块表,寻找给定名称的块表记录
    38     AcDbBlockTable* pBlkTable = NULL;
    39     es = pSourceDwg->getBlockTable(pBlkTable, AcDb::kForWrite);
    40     AcDbObjectId idTemp=AcDbObjectId::kNull;
    41     pBlkTable->getAt(blkDefName, idTemp);
    42     if (idTemp!=AcDbObjectId::kNull)
    43     {
    44         acutPrintf(_T("
    外部图库文件中已有指定名称的块"));
    45         pBlkTable->close();
    46         delete pSourceDwg;
    47         pSourceDwg = NULL;
    48         return false;
    49     }
    50     AcDbObjectId blockId;
    51     AcDbBlockTableRecord *pTempRec = new AcDbBlockTableRecord;
    52     pTempRec->setName(blkDefName);
    53     pBlkTable->add(blockId, pTempRec);
    54     pBlkTable->close();
    55     pTempRec->close();
    56     AcDbIdMapping         adimIdMap;
    57     AcApDocument* pDoc = acDocManager->curDocument();
    58     acDocManager->lockDocument(pDoc, AcAp::kWrite);//锁定当前文档
    59     AcDbObjectIdArray ptarr;
    60     ptarr.append(Tid);
    61     acdbHostApplicationServices()->workingDatabase()->wblockCloneObjects(ptarr, blockId, adimIdMap, AcDb::kDrcReplace);
    62     acDocManager->unlockDocument(pDoc);//解锁文档
    63     pSourceDwg->saveAs(fileName);
    64     delete pSourceDwg;
    65     pSourceDwg = NULL;
    66 }
    View Code
  • 相关阅读:
    设置了透明以后,会有严重残影
    “真正的工作不是说的天花乱坠”,Torvalds 说, “而是在于细节”(Torvalds 认为成功的项目都是99%的汗水和1%的创新)
    iOS和Android使用MQTT协议实现消息推送和即时通讯(替代XMPP,已经有TMS MQTT)
    avalonjs1.5 入门教程
    Grunt 之 Connect
    性能
    JQUERY省、市、县城市联动选择
    Meteor全栈开发平台
    微型工作流引擎设计
    微型工作流引擎-功能设计
  • 原文地址:https://www.cnblogs.com/xzh1993/p/5749571.html
Copyright © 2020-2023  润新知