#include "stdafx.h" #include "dbmain.h" #include "dbsymtb.h" #include "dbents.h" #include "gepnt3d.h" #include "gevec3d.h" #include "dbents.h" #include "accmd.h" #include "aced.h" #include "rxdlinkr.h" #include "rxobject.h" void createDb(); void createDb() { AcDbDatabase *pDb = new AcDbDatabase(); //打开表块 AcDbBlockTable *pBtbl; pDb->getSymbolTable(pBtbl,AcDb::kForRead); //打开模型空间快表记录 //并存入指针pBtblRcd指向的快表记录 //关闭快表 AcDbBlockTableRecord *pBtblRcd; pBtbl->getAt(ACDB_MODEL_SPACE,pBtblRcd,AcDb::kForWrite); pBtbl->close(); //创建并初始化一个圆对象和一条直线对象 AcDbCircle *pCircle=new AcDbCircle(AcGePoint3d(4,4,0),AcGeVector3d(0,0,1),1.0); AcDbLine *pLine= new AcDbLine(AcGePoint3d(3,3,0),AcGePoint3d(5,5,0)); //将新建的两个对象添加到快表记录中,然后关闭动态对象 pBtblRcd->appendAcDbEntity(pCircle); pCircle->close(); pBtblRcd->appendAcDbEntity(pLine); pLine->close(); //函数AcDbDatabase::saveAs()不能自动为文件制定扩展名,因此文件名参数必须包含扩展名 pDb->saveAs("test1.dwg"); //删除指针pDb指向的 动态数据库对象 delete pDb; acutPrintf("\n完成创建数据库,退出程序!"); } void readDb() { //向AcDbDatabase构造函数传递kFalse参数, //可以创建一个空的图形数据库 AcDbDatabase *pDb=new AcDbDatabase(Adesk::kFalse); //如果filename参数无扩展名,函数AcDbDatabase::readDwgFile() //可以自动添加“DWG”扩展名 if(pDb->readDwgFile("test1.dwg")!=Acad::eOk) { acutPrintf("\n不能打开指定文件,退出程序!"); return; } AcDbBlockTable *pBlkTbl; pDb->getSymbolTable(pBlkTbl,AcDb::kForRead); AcDbBlockTableRecord *pBlkTblRcd; pBlkTbl->getAt(ACDB_MODEL_SPACE,pBlkTblRcd,AcDb::kForWrite); pBlkTbl->close(); //创建迭代器,用于遍历包含在快表记录中的实体 AcDbBlockTableRecordIterator *pBlkTblRcdItr; pBlkTblRcd->newIterator(pBlkTblRcdItr); AcDbEntity *pEnt; //遍历快表记录包含的所有实体,显示他们的类名 for(pBlkTblRcdItr->start();!pBlkTblRcdItr->done();pBlkTblRcdItr->step()) { pBlkTblRcdItr->getEntity(pEnt,AcDb::kForRead); acutPrintf("类名:%s\n",(pEnt->isA())->name()); pEnt->close(); } //关闭快表记录 pBlkTblRcd->close(); //删除迭代器对象指针的数据库对象指针 delete pBlkTblRcdItr; delete pDb; acutPrintf("\n 完成读取数据库,退出程序!"); } //远程数据库操作函数
//读取数据库信息函数 void initApp() { acedRegCmds->addCommand("OPERATEDB_COMMANDS", "CREATEDB", "CREATEDB", ACRX_CMD_MODAL, createDb); acedRegCmds->addCommand("OPERATEDB_COMMANDS", "READDB", "READDB", ACRX_CMD_MODAL, readDb); } void unloadApp() { acedRegCmds->removeGroup("OPERATEDB_COMMANDS"); acedRegCmds->removeGroup("LongTransaction_COMMANDS"); } //应用程序主函数 extern "C" AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode msg,void *pkt) { switch(msg) { case AcRx::kInitAppMsg: acrxDynamicLinker->unlockApplication(pkt); acrxDynamicLinker->registerAppMDIAware(pkt); initApp(); break; case AcRx::kUnloadAppMsg: unloadApp(); } return AcRx::kRetOK; } |