<?xml encoding=”UTF-8″>By Balaji Ramamoorthy
Dynamic blocks from a drawing can be wblocked to a new drawing, as an authoring element. This helps archive the dynamic blocks and reuse them when required. The new drawing can be inserted to get the dynamic block into any other drawing. In AutoCAD UI, an authoring element can be created by using the WBLOCK command and selecting a dynamic block from the list of available ones from the current drawing. The same can also be done using code as shown in the following code snippet :
<span>// Wblock a dynamic block as an AuthoringElement</span><span> </span>
Acad::ErrorStatus es;
AcApDocument *pActiveDoc
= acDocManager->mdiActiveDocument();
AcDbDatabase *pCurDb = pActiveDoc->database();
AcDbBlockTable* pCurentDwgBlockTable;
es = pCurDb->getBlockTable(
pCurentDwgBlockTable, kForRead);
<span>if</span><span> ( es == eOk) </span>
<span>{</span>
AcDbBlockTableRecord* pRecord;
<span>// Assuming "Test" dynamic block</span><span> </span>
<span>// being present in the current drawing</span><span> </span>
es = pCurentDwgBlockTable->getAt(
ACRX_T(<span>"Test"</span><span> ), </span>
pRecord,
kForRead, <span>false</span><span> );</span>
<span>if</span><span> (es != eOk) </span>
<span>{</span>
pCurentDwgBlockTable->close();
<span>return</span><span> ;</span>
<span>}</span>
AcDbObjectId btrId = pRecord->objectId();
pRecord->close();
pCurentDwgBlockTable->close();
<span>// Create the destination database</span><span> </span>
AcDbDatabase *pNewDb = NULL;
es = pCurDb->wblock(pNewDb, btrId);
<span>if</span><span> (es == Acad::eOk)</span>
<span>{</span>
es = pNewDb->saveAs(
_T(<span>"D://Temp//TestBlock.dwg"</span><span> ));</span>
<span>delete</span><span> pNewDb;</span>
<span>}</span>
<span>}</span>

Leave a Reply