샘플 코드
/*
objIds    : 블럭이 explode되고나서 생성되는 entity의 object id들
pBlkRef  : block reference 
bErase  : 블럭을 지울것인가 말것인가?
*/
bool explodeBlockReference(AcDbObjectIdArray& objIds,AcDbBlockReference *pBlkRef,const bool bErase)
{
	assert(pBlkRef && "pBlkRef is NULL");
	bool bRet=false;
	if(pBlkRef)
	{
		CString rLayer=pBlkRef->layer();
		AcDbVoidPtrArray entitySet;
		// explode the block, this will return a load of pre-transfromed entities for our perusal
		USES_OKEYS;
		try
		{
			ARXOK(pBlkRef->explode(entitySet));
		}
		catch(const char* ex)
		{
			ARXERROR(ex); return bRet;
		}
		if(true == bErase) pBlkRef->erase();
		pBlkRef->close();
		AcDbDatabase *pDb=acdbHostApplicationServices()->workingDatabase();
		AcDbBlockTable *pBT;
		pDb->getSymbolTable(pBT, AcDb::kForRead);
		AcDbBlockTableRecord *pBTR;
		pBT->getAt(ACDB_MODEL_SPACE, pBTR, AcDb::kForWrite);
		pBT->close();
		// loop round getting each entity
		for (long i=0l; i<entitySet.length(); i++)
		{
			// get a pointer to the entity object
			AcDbEntity *pNewEnt = (AcDbEntity *)entitySet.at (i); // if you don't add it to the database, clean it up
			pBTR->appendAcDbEntity(pNewEnt);
			pNewEnt->setLayer(rLayer);
			pNewEnt->setColorIndex(256);
			objIds.append(pNewEnt->objectId());
			pNewEnt->close();
		}
		pBTR->close();
		bRet = true;
	}
	else acutPrintf("Selected entity is not an INSERT.");
	return bRet;
}
 
댓글
댓글 쓰기