以下是一个快速示例
-
- typedef AcDbObjectPointer AcDbBlockReferencePointer;
- static void ArxBlockSamp_doit(void)
- {
- TCHAR blockName[134]; // alloc space for our blockname
- AcDbObjectId btrId = AcDbObjectId::kNull ; // create a null ID
- AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase();
- if(acedGetString(0,_T("\nEnter a Block Name: "),blockName) != RTNORM)
- {
- acdbFail( _T("@acedGetString"));
- return;
- }
- //call helper to get the ID of block
- if(getBlockTableRecordId(blockName,btrId,pDb) != eOk)
- {
- acdbFail( _T("@getBlockRecordId"));
- return;
- }
- // smart pointer to block
- AcDbBlockTableRecordPointer pBlockTableRecordPointer(btrId,AcDb::kForWrite);
- if(pBlockTableRecordPointer.openStatus() != eOk)
- {
- acdbFail( _T("@pBlockTableRecordPointer.openStatus"));
- return;
- }
- // a pointer to a new AcDbAttributeDefinition, I use a normal pointer
- // here because I want to use the ctor & I want to use it later
- AcDbAttributeDefinition *pAttributeDefinition =
- new AcDbAttributeDefinition(pBlockTableRecordPointer->origin(),
- _T("Text"), _T("Tag"), _T("Prompt"));
- // add the new AcDbAttributeDefinition to block
- if(pBlockTableRecordPointer->appendAcDbEntity(pAttributeDefinition) != eOk)
- {
- delete pAttributeDefinition;
- acdbFail( _T("@pBlockTableRecordPointer->appendAcDbEntity"));
- return;
- }
- pAttributeDefinition->downgradeOpen(); // make sure its readonly
- AcDbObjectIdArray blockReferenceIds; // array to hold BlockReferenceIds
- pBlockTableRecordPointer->getBlockReferenceIds(blockReferenceIds);
- // helper to update BlockReferences
- updateBlockReferences(blockReferenceIds, pAttributeDefinition );
- pAttributeDefinition->close(); // clean up;
- acutPrintf(_T("Ok!"));
- }
- static void updateBlockReferences(const AcDbObjectIdArray &blockReferenceIds,
- AcDbAttributeDefinition *pAttributeDefinition)
- {
- for(int i = 0 ; i blockTransform();
- AcDbAttribute *pAttribute =
- new AcDbAttribute(pAttributeDefinition->position().transformBy(mat),
- pAttributeDefinition->textStringConst(),
- pAttributeDefinition->tagConst());
- if(pBlockReferencePointer->appendAttribute(pAttribute)!= eOk)
- {
- delete pAttribute;
- continue;
- }
- pAttribute->close();
- }
- }
- static Acad::ErrorStatus getBlockTableRecordId(LPCTSTR name, AcDbObjectId &btrId,
- AcDbDatabase *pDb)
- {
- Acad::ErrorStatus stat = eOk;
- AcDbBlockTablePointer pBlocktable(pDb->blockTableId(), AcDb::kForRead);
- stat = pBlocktable.openStatus();
- if(stat != eOk)
- return stat;
- if(pBlocktable->has(name))
- return pBlocktable->getAt(name,btrId);
- else
- return Acad::eNotInDatabase;
- }
|