myDiagram.isModified

When are you trying to set it to false?

As long as a transaction is ongoing or an undo has been done, .isModified will be true. When the transaction is completed or it is fully redone, .isModified will automatically become false.