以下示例显示了 theroutine,它创建一个新数据库,获取模型空间块表记录,并创建两个添加到模型空间的圆。它使用函数来保存绘图。第二个例程在保存的图形中读取,打开模型空间块表记录,并循环访问它,打印它所包含的实体的类名。createDwg()AcDbDatabase::saveAs()readDwg() 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,1), AcGeVector3d(0,0,1), 1.0), *pCir2 = new AcDbCircle(AcGePoint3d(4,4,4), AcGeVector3d(0,0,1), 2.0); pBtblRcd->appendAcDbEntity(pCir1); pCir1->close(); pBtblRcd->appendAcDbEntity(pCir2); pCir2->close(); pBtblRcd->close(); // AcDbDatabase::saveAs() doesnotautomatically // append a DWG file extension, so it // must be specified. // pDb->saveAs(_T("c:\\test1.dwg")); delete pDb; } void readDwg() { // Set constructor parameter to kFalse so that the // 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. // if(Acad::eOk != pDb->readDwgFile(_T("c:\\test1.dwg"))) return; // 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; } |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-1-8 19:46
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.