Autosave 456.py

   3906   2   2
User Avatar
Member
2 posts
Joined: July 2017
Offline
Hi guys,

Trying to get this python script I came across to work in H17.

# Ask about turning on Autosave
# but only if running interactive Houdini session!

set fullver = `run(“version -n”)`
set app = `arg($fullver,0)`

if(`strcmp($app,“hscript”)` < 0 && `strcmp($app,“rscript”)` < 0 && `strcmp($app,“hbatch”)` < 0)
set turnOn = `run(“message -b Yes,No -d 0 Turn on Autosave?”)`

if($turnOn == 0)
autosave on
endif
endif


Console is giving me a syntax error on startup.
Error running Python code:
SyntaxError: ('invalid syntax', ('DUsers/Chris Angelius/Documents/houdini17.0/scripts/456.py', 4, 11, ‘set fullver = `run(\x93version -n\x94)`\n’))
User Avatar
Member
2 posts
Joined: July 2017
Offline
It's been pointed out that the above snippet is actually hscript and not python but even changing the script to a .cmd file which should allow hscript to be run at launch doesn't actually work.

I'm now using
import hou
hou.appendSessionModuleSource('''hou.hscript("autosave on")''')

which defaults autosave to on but would prefer to have the option of enabling it via a popup dialogue at the start of each session.

If anyone has any idea how to code that it would be appreciated.
User Avatar
Member
183 posts
Joined: Nov. 2008
Offline
$HOME/scripts/456.py
if hou.isUIAvailable():
import hdefereval
def _ask():
if hou.ui.displayMessage("Turn on autosave? ", buttons=("No", "Yes")) == 1:
hou.hscript("autosave on")
else:
hou.hscript("autosave off")
hdefereval.execute_deferred(_ask)
Edited by Stalkerx777 - Jan. 26, 2019 19:50:12
Aleksei Rusev
Sr. Graphics Tools Engineer @ Nvidia
  • Quick Links