void Test_Trans() {
AcDbObjectId id;
AcDbObject *pObj1 = nullptr, *pObj2 = nullptr;
Acad::ErrorStatus es;
// создать объект AcDbLine с фиксированными координатами начала и конца
AcDbDatabase *pCurDb = acdbHostApplicationServices()->workingDatabase();
AcDbBlockTable *pBlockTable = nullptr;
pCurDb->getSymbolTable(pBlockTable, AcDb::kForRead);
AcDbBlockTableRecord *pModelSpace = nullptr;
pBlockTable->getAt(ACDB_MODEL_SPACE, pModelSpace, AcDb::kForWrite);
pBlockTable->close();
AcGePoint3d startPt(0.0, 0.0, 0.0), endPt(2000.0, 1000.0, 0.0);
AcDbLine *pLine = new AcDbLine(startPt, endPt);
pModelSpace->appendAcDbEntity(id, pLine);
pLine->close();
pModelSpace->close();
// открытие объекта через транзакции
AcTransaction *pTrans1 = actrTransactionManager->startTransaction();
es = pTrans1->getObject(pObj1, id, AcDb::kForWrite, false);
if (es != Acad::eOk)
acutPrintf(L"pTrans1->getObject() ErrorStatus = %d\n", (int)es);
AcTransaction *pTrans2 = actrTransactionManager->startTransaction();
es = pTrans2->getObject(pObj2, id, AcDb::kForNotify, false);
if (es != Acad::eOk)
acutPrintf(L"pTrans2->getObject() ErrorStatus = %d\n", (int)es);
actrTransactionManager->endTransaction();
actrTransactionManager->endTransaction();
AcDbEntity *pEnt = NULL;
// первая попытка прибить объект
es = acdbOpenObject(pEnt, id, AcDb::OpenMode::kForWrite);
if (pEnt && es == Acad::eOk) {
pEnt->erase(Adesk::kTrue);
pEnt->close();
}
else {
acutPrintf(L"ErrorStatus = %d\n", (int)es);
if (pObj1 && id.isResident()) {
bool needFix = false;
if (pObj1->isReadEnabled()) {
acutPrintf(L"--- Read enabled\n");
needFix = true;
}
if (pObj1->isWriteEnabled()) {
acutPrintf(L"--- Write enabled\n");
needFix = true;
}
if (pObj1->isNotifyEnabled()) {
acutPrintf(L"--- Notify enabled\n");
needFix = true;
}
if (needFix)
pObj1->close();
// вторая попытка прибить объект
es = acdbOpenObject(pEnt, id, AcDb::OpenMode::kForWrite);
if (pEnt && es == Acad::eOk) {
pEnt->erase(Adesk::kTrue);
pEnt->close();
}
else
acutPrintf(L"ErrorStatus = %d\n", (int)es);
}
}
}