其中filePath是外部图纸的保存地址,这是对于使用ZWCAD来编写时,需要在创建数据库之前,提供一个服务,具体代码如下面:
ZcDbDatabase * getDataByDwg(CString filePath)
{
//提供服务
class ZcDbHostApplicationServicesEx : public ZcDbHostApplicationServices
{
public:
ZcDbHostApplicationServicesEx(){};
virtual Zcad::ErrorStatus findFile(ZTCHAR * pcFullPathOut,
int nBufferLength,
const ZTCHAR * pcFilename,
ZcDbDatabase * pDb = NULL,
ZcDbHostApplicationServices::FindFileHint hint = kDefault){return Zcad::eOk;}
};
Zcad::ErrorStatus es;
ZcDbHostApplicationServicesEx *pdbsvr = new ZcDbHostApplicationServicesEx;
zcdbSetHostApplicationServices(pdbsvr);
//定义一个数据库对象
ZcDbDatabase *pDb = NULL;
pDb = new ZcDbDatabase(ZSoft::kFalse);
Zcad::ErrorStatus es = pDb->readDwgFile(filePath);
if (Zcad::eOk != es)
{
zcutPrintf(filePath + _T("
在当前文件中不存在!"));
delete pDb;
pDb = NULL;
return NULL;
}
return pDb;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
对于autocad的话,就不需要提供服务,可以直接创建数据库,然后通过readDwgFile来获得外部图纸的数据库,代码如下:
AcDbDatabase * getDataByDwg(CString filePath)
{
//定义一个数据库对象
AcDbDatabase *pDb = NULL;
pDb = new AcDbDatabase(Adesk::kFalse);
Acad::ErrorStatus es = pDb->readDwgFile(filePath);
if (Acad::eOk != es)
{
acutPrintf(filePath + _T("
在当前文件中不存在!"));
delete pDb;
pDb = NULL;
return NULL;
}
return pDb;
}