Bool cmaindlg: newdwg ()
{
ACAD: errorstatus st;
Acapdocument * pdoc = acdocmanager-> curdocument ();
St = acdocmanager-> lockdocument (pdoc );
If (st! = ACAD: Eok)
{
Acutprintf ("failed to lock the document ");
Return false;
}
Static char pdata [] = "Acad. DWT ";
St = acdocmanager-> appcontextnewdocument (const char *) pdata); // create a DWG
If (st! = ACAD: Eok)
{
Acutprintf ("failed to create document ");
Return false;
}
Acdocmanager-> unlockdocument (pdoc );
Return true;
}
Or set up in the background
Void
CreateDwg ()
{
AcDbDatabase * pDb = new AcDbDatabase ();
AcDbBlockTable * pBtbl;
PDb-> getSymbolTable (pBtbl, AcDb: kForRead );
AcDbBlockTableRecord * pBtblRcd;
PBtbl-> getAt (ACDB_MODEL_SPACE, pBtblRcd,
AcDb: kForWrite );
PBtbl-> close ();
AcDbCircle * pCir1 = new AcDbCircle (AcGePoint3d (1, 1 ),
AcGeVector3d (0, 0, 1 ),
1.0 ),
* PCir2 = new AcDbCircle (AcGePoint3d (4, 4 ),
AcGeVector3d (0, 0, 1 ),
2.0 );
PBtblRcd-> appendAcDbEntity (pCir1 );
PCir1-> close ();
PBtblRcd-> appendAcDbEntity (pCir2 );
PCir2-> close ();
PBtblRcd-> close ();
// AcDbDatabase: saveAs () does NOT automatically
// Append a DWG file extension, so it
// Must be specified.
//
PDb-> saveAs ("c: // test1.dwg ");
Delete pDb;
}
Void
ReadDwg ()
{
// Set constructor parameter to kFalse so that
// Database will be constructed empty. This way only
// What is read in will be in the database.
//
Acdbdatabase * PDB = new acdbdatabase (adesk: kfalse );
// The acdbdatabase: readdwgfile () function
// Automatically appends a DWG extension if it is not
// Specified in the filename parameter.
//
PDB-> readdwgfile ("test1.dwg ");
// Open the model space block table record.
//
Acdbblocktable * pblktbl;
PDB-> getsymboltable (pblktbl, ACDB: kforread );
Acdbblocktablerecord * pblktblrcd;
Pblktbl-> getat (acdb_model_space, pblktblrcd,
ACDB: kforread );
PBlkTbl-> close ();
AcDbBlockTableRecordIterator * pBlkTblRcdItr;
PBlkTblRcd-> newIterator (pBlkTblRcdItr );
AcDbEntity * pEnt;
For (pBlkTblRcdItr-> start ();! PBlkTblRcdItr-> done ();
PBlkTblRcdItr-> step ())
{
PBlkTblRcdItr-> getEntity (pEnt,
AcDb: kForRead );
AcutPrintf ("classname: % s/n ",
(PEnt-> isA ()-> name ());
PEnt-> close ();
}
Pblktblrcd-> close ();
Delete pblktblrcditr;
Delete PDB;
}