ObjectARX使用事务简单示例

		AcDbDatabase *pDb = acDocManager->mdiActiveDocument()->database();
		
		if (!pDb)
		{
			acutPrintf(_T("\nNullDabase!"));
			return;
		}
		AcTransaction *pTrans = actrTransactionManager->startTransaction();
		if (!pTrans)
		{
			acutPrintf(_T("\nNullTransaction!"));
			return;
		}		
		AcDbObject *pObj = NULL;
		Acad::ErrorStatus es= pTrans->getObject(pObj,pDb->blockTableId(),AcDb::kForRead);
		if (Acad::eOk != es || !pObj)
		{
			acutPrintf(_T("\nGetObject Error= %s !"),es);
			actrTransactionManager->abortTransaction();
			return;
		}
		AcDbBlockTable *pBlkTbl = AcDbBlockTable::cast(pObj);
		if (!pBlkTbl)
		{
			acutPrintf(_T("\nCast Error= %s !"),es);
			actrTransactionManager->abortTransaction();
			return;
		}
		AcDbObjectId msObjId;
		es = pBlkTbl->getAt(ACDB_MODEL_SPACE,msObjId);
		if (Acad::eOk != es)
		{
			acutPrintf(_T("\nGetObjId Error= %s !"),es);
			actrTransactionManager->abortTransaction();
			return;
		}
		es = pTrans->getObject(pObj,msObjId,AcDb::kForWrite);
		if (Acad::eOk != es || !pObj)
		{
			acutPrintf(_T("\nGetObject Error= %s !"),es);
			actrTransactionManager->abortTransaction();
			return;
		}
		AcDbBlockTableRecord *pTblRcd=AcDbBlockTableRecord::cast(pObj);
		if (!pTblRcd)
		{
			acutPrintf(_T("\nCast Error= %s !"),es);
			actrTransactionManager->abortTransaction();
			return;
		}
		AcDbLine *pLine = new AcDbLine(AcGePoint3d(0,0,0),AcGePoint3d(500,0,0));
		pLine->setColorIndex(1);
		pTblRcd->appendAcDbEntity(pLine);
		actrTransactionManager->addNewlyCreatedDBRObject(pLine,true);
		actrTransactionManager->endTransaction();
posted @ 2021-10-05 13:34  edata  阅读(45)  评论(0编辑  收藏  举报