|
- AcDbObjectId createInsertForBlock (AcDbObjectId blockId, AcGePoint3d basePoint,
- AcGeScale3d scaleFactor, double rotationAng,
- AcGeVector3d vector, AcDbObjectId ownerRefId,
- AcDbObjectId blockRefLayId)
- {
- AcDbDatabase *pDB;
- AcDbBlockReference *pBlkRef;
- AcDbBlockTable *pBlockTable;
- AcDbBlockTableRecord *pBlockTableRecord;
- AcDbObjectId newEntId;
- AcDbBlockTableRecord *pBlockDef;
- AcDbBlockTableRecordIterator *pIterator;
- AcDbBlockReference *pOriginalRef;
- AcDbObjectIterator *pIterRef;
- AcDbEntity *pEnt;
- AcDbAttributeDefinition *pAttdef;
- pDB = acdbHostApplicationServices()->workingDatabase();
- pBlkRef = new AcDbBlockReference;
- pBlkRef->setBlockTableRecord(blockId);
- pBlkRef->setNormal(vector);
- pBlkRef->setPosition(basePoint);
- pBlkRef->setScaleFactors(scaleFactor);
- pBlkRef->setRotation(rotationAng);
- pBlkRef->setLayer(blockRefLayId, Adesk::kFalse);
- pDB->getBlockTable(pBlockTable, AcDb::kForRead);
- pBlockTable->getAt(ACDB采用MODEL采用SPACE, pBlockTableRecord,
- AcDb::kForWrite);
- pBlockTable->close();
- pBlockTableRecord->appendAcDbEntity(newEntId, pBlkRef);
- pBlockTableRecord->close();
- acdbOpenObject(pBlockDef, blockId, AcDb::kForRead);
- pBlockDef->newIterator(pIterator);
- //采用采用采用采用iterating original block ref for attributes
- acdbOpenObject(pOriginalRef,ownerRefId,AcDb::kForRead);
- pIterRef =pOriginalRef->attributeIterator ();
- pOriginalRef->close();
- for(pIterator->start(); !pIterator->done(); pIterator->step())
- {
- pIterator->getEntity(pEnt, AcDb::kForRead);
- pAttdef = AcDbAttributeDefinition::cast (pEnt);
- if (pAttdef != NULL && !pAttdef->isConstant())
- {
- //采用采用采用采用iteration of original block ref continues...
- AcDbObject *pObj;
- AcDbObjectId ida;
- AcDbAttribute *pAtt;
- AcDbObjectId attId;
- ida = pIterRef->objectId();
- acdbOpenObject(pObj, ida, AcDb::kForRead);
- pAtt = AcDbAttribute::cast(pObj->clone());
- pObj->close();
- pAtt->setTextString("XXX");
- pBlkRef->appendAttribute(attId, pAtt);
- pAtt->close();
- pIterRef->step();
- }
- pEnt->close();
- }
- delete pIterator;
- delete pIterRef;
- pBlockDef->close();
- pBlkRef->close();
- return newEntId;
- }
复制代码 |
|