Jump to content
underscoreus

Houdini Python hou.setPreferance (or if easier, hscript)

Recommended Posts

Hello all,
I am looking for a way to set a specific preference in Houdini with python. The preference I am looking to set is named "Auto Save Method" in the UI. I've tried to use the hou.getPreferanceNames() to get a list of all the pref name variables I can set but this does not appear in there.

I have had a dig through the preference files stored inside the Houdini folder and have found a parameter inside the hcommon.pref file that would seem to match the setting I am looking to change, however, if I were to edit this text file whilst Houdini is running, would that update the setting or would it require a restart of Houdini? And is it even a good idea to be editing these .pref files whilst Houdini is running?

Here is a link to the help file for the parameter I am looking to change, sorry I don't have a picture: https://www.sidefx.com/docs/houdini/ref/windows/mainprefs.html#persistence (Look for the heading "Auto Save Method", this is the setting I am looking to change)

You'll have to forgive me if this is very basic stuff, I am kinda new to Python in Houdini and am trying to make tools to learn more.

Thanks for the read!

Edited by underscoreus

Share this post


Link to post
Share on other sites
6 hours ago, DonRomano said:

Hey, there you go :


import hou
hou.appendSessionModuleSource('''hou.hscript("autosave on")''')

https://forums.odforce.net/topic/22589-default-autosave/

 

Cheers,

Hey Don,
That's just to enable autosave, for that you can run just hou.hscript("autosave on"). What I am looking for is changing the mode of autosave with python. It's listed as "Auto save method" on the website. Sorry for the unclarity, I really wish I had a picture of the UI to I could mark it but I forgot to take one before I left my workstation.

Thanks for the reply!

Edited by underscoreus
more info

Share this post


Link to post
Share on other sites

Quick update, here's a picture of the setting I am looking to change for clarity's sake. It's set to the setting I want right now manually by clicking the radio button. I do also believe this preference can be changed by editing the hcommon.pref file in the houdini install directory and if I can't find a better solution to change this I think I will go for that. Just a little skeptical about directly editing .pref files with python while houdini is running. But hey! If anyone's got any comment on that idea as well I'd love to hear about it! Horrible idea to edit those pref files on the fly or basically just emulating what houdini is already doing under the hood when clicking buttons in the ui to change it?

Image of the preferance UI with the marked field being the one I want to edit

Thanks for the read!

Share this post


Link to post
Share on other sites

I was curious about this so I remote sessioned into Houdini...cause I’m at work at the moment.

I used the Python Shell so I haven’t had a chance to test out a shelf tool or startup script version but it should work nonetheless.

In the shell, running hou.getPreferenceNames() returns, among all the prefs, 2 autosave related preferences. There is a third one but it’s not immediately related to the problem at hand.

1: “general.autosaveinterval.val”

This corresponds to the Auto Save Every X Minutes where X is the current value.

2: “general.autosaveinc.val”

This corresponds to the Auto Save Method

This is the one you’re looking for.

To change preferences use hou.setPreferences(name, value) where name corresponds to the preference name and value to the value you desire.

The values for Auto Save Method are as follows:

’0’ : Overwrite File

’1’ : Increment Filename

’2’ : Make Numbered Backup

Let’s say that by default, my unsaved scene starts with the setting at Overwrite File and I want to change it to Make Numbered Backup.

In the shell or shelf tool or wherever, I would just run the following:

hou.setPreference(“general.autosaveinc.val”, “2”)

If successful, the method will return True. Otherwise it will return False.

Make sure that both the name and the value arguments you pass to it are strings, as in, in quotations or you may error out.

Edited by JXS
  • Like 1

Share this post


Link to post
Share on other sites

As a follow up, I created a simple shelf tool which implements the method I mentioned above.

Here's a proof-of-concept:

ezgif-6-2fd5e74cee93.gif.302afb03cc722c9bd7f87b0decba19aa.gif

 

  • Like 1

Share this post


Link to post
Share on other sites
On 2020-02-18 at 7:40 PM, JXS said:

As a follow up, I created a simple shelf tool which implements the method I mentioned above.

Here's a proof-of-concept:

ezgif-6-2fd5e74cee93.gif.302afb03cc722c9bd7f87b0decba19aa.gif

 

Sorry I'm a little late to reply. Thank you so much for that! Been scratching my head on and off for the last two weeks trying to google-fu my way to that answer. :lol:
Maybe it has been staring me in the face all the time but I just thought that "autosaveinc" always meant the increment of time between auto-saves instead of the actual auto-save method. Maybe I was just too hellbent of finding a "autosavemethod.val" preference.

Edited by underscoreus

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×