|
[code]AcDbObjectId importBlockToCurDWGDatabase(const ACHAR *pBlockName, const ACHAR *pFileName)
{
Acad::ErrorStatus es=Acad::eOk;
AcDbObjectId idImported; // ID нашего нового блока
AcDbDatabase* pWorkDatabase = acdbHostApplicationServices()->workingDatabase();
AcAxDocLock docLock(pWorkDatabase);
AcDbDatabase* pBlockDatabase = new AcDbDatabase(false,true);
es = pBlockDatabase->readDwgFile(pFileName);
if(es!=Acad::eOk){delete pBlockDatabase;return NULL;}
try
{
AcDbBlockTable* pBlockTable;
es=pBlockDatabase->getSymbolTable(pBlockTable,AcDb::kForRead);
if(es!=Acad::eOk){delete pBlockDatabase;return NULL;}
AcDbObjectId idInsRecord;
es=pBlockTable->getAt(pBlockName,idInsRecord);
pBlockTable->close();
if(es!=Acad::eOk){delete pBlockDatabase;return NULL;} // нет такого блока
AcDbDatabase* pTempDB;
es=pBlockDatabase->wblock(pTempDB,idInsRecord);
if(es!=Acad::eOk){delete pBlockDatabase;return NULL;} // не скопировался блок в пустую базу
es=pWorkDatabase->insert(idImported,pBlockName,pTempDB);
delete pTempDB;
if(es!=Acad::eOk){delete pBlockDatabase;return NULL;} // не вставилась пустая база с блоком в нашу текущую базу
}catch(...){delete pBlockDatabase;return NULL;}
delete pBlockDatabase;
return idImported;
}
void drawSign(CString blockName, CString blockFilePath, double scale)
{
AcDbObjectId newBlockTableId;
AcGePoint3d insPnt;
acdbHostApplicationServices()->enableMessageDisplay(false);
newBlockTableId = importBlockToCurDWGDatabase(blockName.GetString(),blockFilePath.GetString());
acdbHostApplicationServices()->enableMessageDisplay(true);
if (newBlockTableId.isNull())
{
acedAlert(_T("Данный блок не найден"));
return;
}
acedCommand(RTSTR,_T("_ucsicon"),RTSTR,_T("_off"),0); // значек СК
acedCommand (RTSTR, _T("_ucs"),RTSTR,_T("_v"),0);
AcDbDatabase* pWorkDatabase = acdbHostApplicationServices()->workingDatabase();
AcAxDocLock docLock(pWorkDatabase);
int osnap = acdbHostApplicationServices()->workingAppSysvars()->osmode();
acdbHostApplicationServices()->workingAppSysvars()->setOsmode(64 + 512);
if(acedGetPoint(NULL,_T("\nТочка вставки: "),asDblArray (insPnt))!=RTNORM)
{
acdbHostApplicationServices()->workingAppSysvars()->setOsmode(osnap);
acedCommand(RTSTR,_T("_ucs"),RTSTR,_T("_p"),0);
acedCommand(RTSTR,_T("_ucsicon"),RTSTR,_T("_on"),0);
return;
}
AcDbBlockReference *blockReference = new AcDbBlockReference(insPnt,newBlockTableId);
blockReference->setRotation(0.0);
blockReference->setNormal (AcGeVector3d (0.0, 0.0, 1.0)) ;
blockReference->setScaleFactors(AcGeScale3d(scale));
AcGeMatrix3d matUcs;
acedGetCurrentUCS(matUcs);
blockReference->transformBy(matUcs);
postToDb(blockReference); // запись экзкмпляра блока в БД чертежа
acdbHostApplicationServices()->workingAppSysvars()->setOsmode(osnap);
acedCommand(RTSTR,_T("_ucs"),RTSTR,_T("_p"),0);
acedCommand(RTSTR,_T("_ucsicon"),RTSTR,_T("_on"),0);
acedPostCommandPrompt();
}
[/code] |
|