// 使用常规的Open/Close机制 static void UpdateEntity2( const AcDbObjectId& objId ) { AcDbEntity* pEnt; if( Acad::eOk != acdbOpenObject( pEnt, objId, AcDb::kForWrite ) ) return; pEnt->recordGraphicsModified( true ); // 标签图元状态已修改,需要更新图形 pEnt->close(); }
// 使用事务 static void UpdateEntity1( const AcDbObjectId& objId ) { AcTransaction* pTrans = actrTransactionManager->startTransaction(); if( pTrans == 0 ) return; AcDbObject* pObj; if( Acad::eOk != pTrans->getObject( pObj, objId, AcDb::kForWrite ) ) // 打开图元失败 { actrTransactionManager->abortTransaction(); return; } AcDbEntity* pEnt = AcDbEntity::cast( pObj ); if( pEnt == 0 ) { actrTransactionManager->abortTransaction(); return; } pEnt->recordGraphicsModified( true ); // 标签图元状态已修改,需要更新图形 actrTransactionManager->endTransaction(); }