找回密码
 立即注册

QQ登录

只需一步,快速开始

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

[每日一码] 从块定义创建一个INSERT

[复制链接]

0

主题

0

回帖

28

积分

管理员

积分
28
发表于 2024-3-14 20:26:45 | 显示全部楼层 |阅读模式
  1. AcDbObjectId createInsertForBlock (AcDbObjectId blockId, AcGePoint3d basePoint,
  2.                    AcGeScale3d scaleFactor, double rotationAng,
  3.                    AcGeVector3d vector, AcDbObjectId ownerRefId,
  4.                    AcDbObjectId blockRefLayId)
  5. {
  6.     AcDbDatabase *pDB;
  7.     AcDbBlockReference *pBlkRef;
  8.     AcDbBlockTable *pBlockTable;
  9.     AcDbBlockTableRecord *pBlockTableRecord;
  10.     AcDbObjectId newEntId;
  11.     AcDbBlockTableRecord *pBlockDef;
  12.     AcDbBlockTableRecordIterator *pIterator;
  13.     AcDbBlockReference *pOriginalRef;
  14.     AcDbObjectIterator *pIterRef;   
  15.     AcDbEntity *pEnt;
  16.     AcDbAttributeDefinition *pAttdef;
  17.     pDB = acdbHostApplicationServices()->workingDatabase();
  18.     pBlkRef = new AcDbBlockReference;   
  19.     pBlkRef->setBlockTableRecord(blockId);
  20.     pBlkRef->setNormal(vector);
  21.     pBlkRef->setPosition(basePoint);
  22.     pBlkRef->setScaleFactors(scaleFactor);
  23.     pBlkRef->setRotation(rotationAng);
  24.     pBlkRef->setLayer(blockRefLayId, Adesk::kFalse);
  25.     pDB->getBlockTable(pBlockTable, AcDb::kForRead);
  26.     pBlockTable->getAt(ACDB采用MODEL采用SPACE, pBlockTableRecord,
  27. AcDb::kForWrite);
  28.     pBlockTable->close();     
  29.     pBlockTableRecord->appendAcDbEntity(newEntId, pBlkRef);
  30.     pBlockTableRecord->close();
  31.     acdbOpenObject(pBlockDef, blockId, AcDb::kForRead);
  32.     pBlockDef->newIterator(pIterator);   
  33.     //采用采用采用采用iterating original block ref for attributes
  34.     acdbOpenObject(pOriginalRef,ownerRefId,AcDb::kForRead);
  35.     pIterRef =pOriginalRef->attributeIterator ();   
  36.     pOriginalRef->close();
  37.     for(pIterator->start(); !pIterator->done(); pIterator->step())
  38.     {
  39.         pIterator->getEntity(pEnt, AcDb::kForRead);
  40.         pAttdef = AcDbAttributeDefinition::cast (pEnt);
  41.         if (pAttdef != NULL && !pAttdef->isConstant())
  42.         {   
  43.             //采用采用采用采用iteration of original block ref continues...
  44.             AcDbObject *pObj;
  45.             AcDbObjectId ida;
  46.             AcDbAttribute *pAtt;
  47.             AcDbObjectId attId;
  48.             ida = pIterRef->objectId();
  49.             acdbOpenObject(pObj, ida, AcDb::kForRead);
  50.             pAtt = AcDbAttribute::cast(pObj->clone());
  51.             pObj->close();
  52.             pAtt->setTextString("XXX");
  53.             pBlkRef->appendAttribute(attId, pAtt);
  54.             pAtt->close();
  55.             pIterRef->step();
  56.         }
  57.         pEnt->close();
  58.     }
  59.     delete pIterator;   
  60.     delete pIterRef;
  61.     pBlockDef->close();
  62.     pBlkRef->close();
  63.     return newEntId;
  64. }
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-12-29 05:17 , Processed in 0.152462 second(s), 22 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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