找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 136|回复: 0

[每日一码] 克隆一个块定义(AcDbBlockTableRecord)

[复制链接]

0

主题

0

回帖

28

积分

管理员

积分
28
发表于 2024-3-14 20:26:23 | 显示全部楼层 |阅读模式
  1. AcDbObjectId cloneBlockRecord(AcDbObjectId from, char *to)
  2. {
  3.     AcDbBlockTable *pBlockTable;
  4.     AcDbBlockTableRecord *pBlockTableRecord;
  5.     AcGePoint3d tempOrigin;
  6.     AcDbObjectIdArray arrayId;
  7.     AcDbBlockTableRecordIterator *pIter;
  8.     AcDbObjectId objId, tableId, blockTargetId;
  9.     AcDbDatabase *pDB;
  10.     AcDbIdMapping idMap;
  11.     char buffer[21];
  12.     pDB = acdbHostApplicationServices()->workingDatabase();
  13.     acdbOpenAcDbObject ((AcDbObject *&)pBlockTableRecord, from,
  14. AcDb::kForRead);
  15.     tempOrigin = pBlockTableRecord->origin();   
  16.     pBlockTableRecord->newIterator(pIter);
  17.     while (!pIter->done())
  18.     {
  19.         pIter->getEntityId(objId);
  20.         arrayId.append(objId);
  21.         pIter->step();
  22.     }
  23.     delete pIter ;
  24.     tableId = pBlockTableRecord->ownerId();
  25.     pBlockTableRecord->close();
  26.     pDB->getBlockTable(pBlockTable, AcDb::kForRead);
  27.     strcpy(buffer, to);
  28.     if(pBlockTable->has(buffer))
  29.     {
  30.         for (int i = 0; i < 255; i++)
  31.         {
  32.             sprintf(buffer, "%s%d", to, i);
  33.             if(!pBlockTable->has(buffer))
  34.             {
  35.                 break;
  36.             }
  37.         }
  38.     }
  39.     pBlockTable->upgradeOpen ();
  40.     pBlockTableRecord = new AcDbBlockTableRecord;
  41.     pBlockTableRecord->setName(buffer);
  42.     pBlockTableRecord->setOrigin(tempOrigin);
  43.     pBlockTable->add(blockTargetId, pBlockTableRecord);
  44.     pBlockTableRecord->close();
  45.     pBlockTable->close();
  46.     pDB->deepCloneObjects(arrayId, blockTargetId, idMap);
  47.     return blockTargetId;
  48. }
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|膜结构网

GMT+8, 2024-12-29 04:46 , Processed in 0.131941 second(s), 23 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表