//Возвращает указатель на документ sDocName если он открыт, или 0 - если документа нет
AcApDocument* GetDocument( const CString &sDocName )
{
AcApDocumentIterator* iter = acDocManager->newAcApDocumentIterator();
AcApDocument* pTmpDoc = 0;
for( ; !iter->done(); iter->step() ) {
if( !_stricmp( sDocName, iter->document()->fileName() ) ) {
pTmpDoc = iter->document();
break;
}
}
delete iter;
return pTmpDoc;
}//GetDocument
Acad::ErrorStatus addToModelSpace(AcDbEntity* ent, AcDbObjectId& objectId, AcDbDatabase *pDb)
{
SmartAcDb<AcDbBlockTable> blockTable;
if(!pDb) pDb = acdbHostApplicationServices()->workingDatabase();
Acad::ErrorStatus es = pDb->getSymbolTable(blockTable, AcDb::kForRead);
if(es!=Acad::eOk) return es;
SmartAcDb<AcDbBlockTableRecord> blockTableRecord;
es=blockTable->getAt(ACDB_MODEL_SPACE, blockTableRecord, AcDb::kForWrite);
if(es!=Acad::eOk) return es;
es=blockTableRecord->appendAcDbEntity(objectId, ent);
if(es!=Acad::eOk) return es;
ent->close();
ent = 0;
return es;
}//addToModelSpace
Acad::ErrorStatus addLine( const CString& sFileName ) // sFileName - путь к файлу
{
AcApDocument* pDoc = GetDocument( sFileName );
if( pDoc == NULL ) return Acad::eOk;
acDocManager->lockDocument(pDoc, AcAp::kWrite);
acdbHostApplicationServices()->setWorkingDatabase( pDoc->database() );
AcDbPolyline* pLine;
pLine = new AcDbPolyline;
pLine->addVertexAt( pLine->numVerts(), AcGePoint2d( 50, 50 ) );
pLine->addVertexAt( pLine->numVerts(), AcGePoint2d( 100, 50 ) );
AcDbObjectId objId;
Acad::ErrorStatus es = cmnAcadDB::addToModelSpace( pLine, objId );
acDocManager->unlockDocument(pDoc);
return es;
}//addLine