algorithmic modeling for Rhino
Hi all,
I am working on a plugin that I want to run some code before saving the grasshopper file. Is there a way to override the save command in grasshopper? If not, is there a way to change the shortcut key, binding Crtl-S with some other custom function?
Thanks,
Alan
Tags:
Hi Alan,
there is no event associated with save operations in general, so you cannot do stuff before a save. It might technically be possible to replace the Save menu item with some custom menu item, but the menu merely invokes the logic elsewhere and there's no way to hack that.
May I ask what sort of thing you want to accomplish before a save? And do you also want to do that before every autosave?
David,
I implement a file lock in the plugin and need to unlock the file before saving. I do not need it for autosave. Replacing the menu item sounds like a solution.
Thanks,
Alan
Well the saving of the file happens in several stages:
So if your plugin is locking and unlocking the *.gh file, then you can do it at any time prior to step 5.
If you want to replace the Save item, you'll need to wait until the Grasshopper.Instances.DocumentEditor is constructed, then iterate over its controls until you find one that's of type MenuStrip. Once you have this main menu, find the File item, then find the Save item and register your events.
I just remembered that you'll have problems replacing it with another one because the shortcut logic is special and hard-coded. If you replace the Save item with another item then Grasshopper will not recognize it as ashortcuttable menu item, which will definitely mess with the Preferences UI and may also mess with the actual shortcut handling.
David,
After I replace the menu item, the shortcut actually works. Crtl-S points to the new save item. It also shows up correctly in the Preferences>Interface>Shortcuts, although it is greyed out.
One thing I fail to override is the GH_MultiDocSave(), which pops up when closing the file with unsave changes. It does not seems like I can do anything about it.
Alan
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by