Setting settings via Python

Hello everyone!
I’m working on a menu item that would allow me to push “default settings” fro RV to users in the studio. So far i’ve managed to set things with

commands.writeSettings("Caching", "lookAheadCacheSizeNew", 10.0

But it gets overridden as soon as you close RV. Also in setting panel it is still showing old settings value.

How do i “commit” this change?

Thank you

Hi, yes RV saves the preferences on close per default, I don’t think there is anything that can be done against this.

I think writeSettings is not meant to overwrite default preferences but rather define your own settings for custom functionality.

However I think it’s possible to still use this.



What I would recommend is following:
Do something like a “restore default preferences on RV close”.

there is an event called after-preferences-write that is called when RV is closing and the final preferences were saved.

So your menu command could do something like:

from rv import commands

def restore_default_settings_on_close(event=None):
    """Restore default settings on RV close menu command.""" 
    my_mode_name = "default"  # Replace with your mode name (needs to stay active)
    preference_write_event = "after-preferences-write"

    # Binding to push default settings on RV close (preference write)
    commands.bind(my_mode_name, "global", preference_write_event, push_default_settings)

def push_default_settings():
    """Push default settings to user preference file."""
    commands.writeSettings("Caching", "lookAheadCacheSizeNew", 10.0)
    # and so on

Untested, but I think something like this could work.

Cheers, Mirco

hey Micro, thank you very much! I will try this approach

RV must be forced to save your modifications to the user preferences file.

It vanishes on close because write Settings by itself just modifies the session.

As suggested by Micro, the cleanest method is to hook into after-preferences-write and attach a function that rewrites your “default” values at the exact moment that RV commits the preferences.

In essence, you are using RV’s save mechanism to make sure that your settings are overwritten each time it shuts down.