What OpticStudio version are you using? In 20.3.2 (my version), I cannot adjust it through the API. You can access TheApplication.Preferences.General, but for me, Undo is not exposed.
If you use Standalone mode, you could use the code of Example 26 of ZOSAPI help:
But I guess that does not work for extension mode (as the application is already up and running). Unless Undo is exposed in newer versions of the API, you will have to set it manually to None before connecting.