Abort save if beforescenesave.py fails

   3142   3   0
User Avatar
Member
3 posts
Joined: Oct. 2014
Offline
Is there a way to abort Houdini saving the scene if something in my beforescenesave.py script fails?

At the moment any errors I raise don't abort the actual save, I see them being raised in the output to the terminal. I would like to perform some validation on the scene before it's saved and if it is successful go ahead with the save, otherwise abort.

I'm trying the following in my beforescenesave.py:

from myModule import validate_scene

if not validate_scene(kwargs['file']):
    kwargs['success'] = False
    raise RuntimeError('Failed validation')

Thanks in advanced.
User Avatar
Member
183 posts
Joined: Nov. 2008
Offline
No, I don't think it's possible. Similar to OnDelete event in HDA, you cant catch the event, do something with it, but the node deletion is inevitable.
Aleksei Rusev
Sr. Graphics Tools Engineer @ Nvidia
User Avatar
Member
3 posts
Joined: Oct. 2014
Offline
Ah that's a shame.

For anyone that may have had the same issue my work around is to override Houdini's default Save with a custom Save.

- Remove save using
<removeItem id="h.save"/>
in MainMenuCommon.xml
- Add custom save in MainMenuCommon.xml
<scriptItem id="h.custom_save"> ...
- override the Ctrl+S hotkey in the HotkeyOverrides file
h.custom_save   Save    "Validate and save current file"    Ctrl+S

Now I can validate and save my scene if validation passes in the script I pass to the custom save menu item.
User Avatar
Member
201 posts
Joined: July 2005
Offline
H16.0.736
Somewhat related …

if I'm using the HSITE environment variable and I save beforescenesave.py & afterscenesave.py in $HSITE/houdini16.0/scripts, should they work? I'm not seeing anything happen. To clarify, this is what I have in the afterscenesave.py file:

if kwargs["success"] and not kwargs["autosave"]:
print "after save"
Edited by rdms - Oct. 12, 2017 12:08:48
Cheers,
Rob
Digital Supervisor | Stargate Studios Toronto
  • Quick Links