workingdatabase 获取指针失败
通过com 读取Excel 数据,根据数据在cad画图。1.读取Excel数据,成功。2.添加图块成功 3.添加图层失败,在workingdatabase 获取指针失败。先是锁定文档,添加图层,再解除锁定。没有报错。在第3步,先锁定文档,再获取workingdatabase指针失败。提示access violation reading .请各位大佬不吝赐教
现在把读excle 注释掉,先添加图层,再添加图块,调试进入获取workingdatabase2失败,db=00000000000000000,static void addlayerblock() // 添加图层{ ErrorStatus es; AcDbDatabase *db = NULL; acDocManager->lockDocument(acDocManager->curDocument()); AcDbLayerTable *playerTable = NULL; if (!(db = acdbHostApplicationServices()->workingDatabase())) { acutPrintf(L"获取workingdata1失败");delete db; return; } if (Acad::eOk != (es = db->getSymbolTable(playerTable, AcDb::kForWrite))) { acutPrintf(L"获取workingdata1失败"); return; } if (!(playerTable->has(L"轮廓线"))) { AcDbLayerTableRecord *playerTableR = new AcDbLayerTableRecord; playerTableR->setName(L"轮廓线"); AcCmColor col; col.setColorIndex(255); playerTableR->setColor(col); playerTable->add(playerTableR); playerTableR->close(); } playerTable->close(); delete db; acDocManager->unlockDocument(acDocManager->curDocument());}static void makeBlock()// 添加图块{ ErrorStatus es; AcDbDatabase *db = NULL; acDocManager->lockDocument(acDocManager->mdiActiveDocument()); AcGeVector3d nrm(0, 0, 1); AcDbBlockTable *blockt = NULL; if (!(db = acdbHostApplicationServices()->workingDatabase())) { acutPrintf(L"获取workingdata2失败"); return; } if (Acad::eOk != (es = db->getBlockTable(playerTable, AcDb::kForWrite))) { acutPrintf(L"获取getBlockTable失败"); return; } if (!(blockt->has(L"mM2"))) //添加M2螺纹孔 { AcDbBlockTableRecord *ptblR = new AcDbBlockTableRecord; ptblR->setName(L"mM2"); AcDbObjectId pid; blockt->add(pid, ptblR); AcGePoint3d ce(1.25, 0, 0); AcGePoint3d p(0, 0, 0); AcGePoint3d p0(2.5, 0, 0); AcDbLine *pl1 = new AcDbLine(p, p0); pl1->setLayer(L"中心线"); ptblR->appendAcDbEntity(pid, pl1); ptblR->setOrigin(ce); pl1->close(); ptblR->close(); } blockt->close(); acDocManager->unlockDocument(acDocManager->curDocument());}
直接写
AcDbDatabase* db = acdbHostApplicationServices()->workingDatabase();
非要
AcDbDatabase *db = NULL;
....
if (!(db = acdbHostApplicationServices()->workingDatabase()))
{
acutPrintf(L"获取workingdata2失败");
return;
}
自己给自己难受!
gzxl 发表于 2022-2-18 16:16
直接写
AcDbDatabase* db = acdbHostApplicationServices()->workingDatabase();
非要
改成您这种方法,db依然是0,空指针,我查到非模态对话框,获取空指针,改进后使用了锁定文档,但是好像不管用啊 QQ群:630401507 自己收个尾,在用com 读取Excel时候,选取了多文档模式,导致锁存文档的混乱问题 本帖最后由 2499569249 于 2022-3-14 18:35 编辑
gzxl 发表于 2022-2-18 16:16
直接写
AcDbDatabase* db = acdbHostApplicationServices()->workingDatabase();
非要
您好 可以把里程标注的插件发我试用下吗 我的邮箱:
页:
[1]