|
[code]void AsdkGetBlockName()
{
// Let the user select an INSERT (Block reference).
ads_name ename;
ads_point pt;
if (RTNORM != acedEntSel(L"\nSelect INSERT: ",
ename,
pt))
return;
AcDbObjectId objId;
AcDbEntity *pEnt;
AcDbBlockReference *pInsert;
Acad::ErrorStatus es;
// Test the entity type.
acdbGetObjectId(objId, ename);
if (Acad::eOk != (es = acdbOpenAcDbEntity(pEnt,
objId,
AcDb::kForRead)))
{
acutPrintf(L"\nCannot access selected entity.\n");
return;
}
pInsert = AcDbBlockReference::cast(pEnt);
if (!pInsert)
{
acutPrintf(L"\nSelected entity is not an INSERT.\n");
pEnt->close();
return;
}
// Get the objectID of the block definition.
AcDbObjectId blockDefId = pInsert->blockTableRecord();
// Close the selected INSERT.
pInsert->close();
// Open the block definition.
AcDbBlockTableRecord *pBlkRecord;
if (Acad::eOk != (es = acdbOpenObject(pBlkRecord,
blockDefId,
AcDb::kForRead)))
{
acutPrintf(L"\nCannot access block definition.\n");
return;
}
// Get the name of the block definition.
const TCHAR* pBlkName;
es = pBlkRecord->getName(pBlkName);
pBlkRecord->close();
if ((Acad::eOk != es) || !pBlkName)
{
acutPrintf(L"\nCannot extract block definition name.\n");
return;
}
acutPrintf(L"\nName of block definition: '%s'\n", pBlkName);
}[/code] |
|