|
ObjectARX 得到快参照名称、插入图块
//功能:得到快参照名称
CString GetBlkName(AcDbEntity* pEnt);
CString CZzzBlock::GetBlkName(AcDbEntity* pEnt)
{
CString strBlkName;
AcDbBlockReference* pBlock = AcDbBlockReference::cast(pEnt);
AcDbObjectId idBlkDef = pBlock->blockTableRecord();
AcDbBlockTableRecordPointer pBlkTblRcd(idBlkDef, AcDb::kForRead);
if (Acad::eOk != pBlkTblRcd.openStatus())
return strBlkName;
TCHAR* szName = NULL;
pBlkTblRcd->getName(szName);
strBlkName = szName;
return strBlkName;
}
//功能: 插入图块
AcDbObjectId InsertBlock(LPCTSTR blockName, AcGePoint3d ptInsert, bool bExpolor = false);
AcDbObjectId CZzzBlock::InsertBlock(LPCTSTR blockName, AcGePoint3d ptInsert, bool bExpolor /*= false*/)
{
AcDbDatabase* pDb = acdbCurDwg();
AcDbBlockTable* pBlkTable;
AcDbObjectId blockId;
pDb->getBlockTable(pBlkTable, AcDb::kForRead);
if (pBlkTable->has(blockName))
{
pBlkTable->getAt(blockName, blockId);
//ads_point pt;
//int rc = acedGetPoint(NULL, _T("\n请选择插入点"),pt);
AcDbBlockReference* pBlkRef = new AcDbBlockReference(ptInsert, blockId);
//获得模型空间块表记录
AcDbBlockTable* pBlockTable;
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable, AcDb::kForRead);
AcDbBlockTableRecord* pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite);
pBlockTable->close();
pBlockTableRecord->appendAcDbEntity(blockId, pBlkRef);
pBlockTableRecord->close();
if (bExpolor)
{
pBlkRef->explodeToOwnerSpace();//插入图块时分解块。(必须在添加模型空间块表记录并关闭后再执行)
}
pBlkRef->close();
}
pBlkTable->close();
return blockId;
} |
|