现在把读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()); }
|