Multiple Hooks On/off

2 parts:

  1. how would one make a hook be able to turn on/off.

i created a script that works just as intended. It is saved in this folder path. When i start up Revit, the script is up and running. However, I’d like to be able to turn it have it turn on/off.

image

This is the first hook i created that did not use a pushbutton and I guess it is intended to run in the background.

  1. If i wanted to create more hooks, what would be the right folder structure. I can’t have multiple “hooks” folders since file explorer won’t let me.

Thanks in advance.

I think pyrevit may only register a single UpdaterId thats hard coded. You might be able to prefix the name like xxxx_doc-updater.py to get around the naming issue. It works that way with script.py and config.py so it worth a shot I guess but it may not be possible.

If you are planning on using multiple/complex updaters I highly recommend using C# instead. I’ve run into a few strange bugs and limitations, but its fine for learning and simple tasks.

but either way you need to get the UpdaterId and use this method to enable and this method to disable.

You can create ribbon buttons with on/off image to indicate the status when you enable/disable the updaters. I have not done this myself using pyrevit updater, only using C#.

Here’s a head start with the toggle image for the button. The PostCommand in my example is executing an external command in a dll to enable/disable, but you should be able to do in python as well.

def __selfinit__(script_cmp, ui_button_cmp, __rvt__):
    on_icon = script_cmp.get_bundle_file('on.png')
    off_icon = script_cmp.get_bundle_file('off.png')

def toggle_state():
    new_state = not script.get_envvar(*env_variable*)
    script.set_envvar(*env_variable*, new_state)
    script.toggle_icon(new_state)
    uiapp.PostCommand(UI.RevitCommandId.LookupCommandId("*CommandId*"))  

if __name__ == '__main__':
    toggle_state()

2024-09-23_07-22-27

2 Likes

Ooh nice. I was trying to find something like that but did not see it the pyrevit shortcuts:
https://pyrevit1.readthedocs.io/en/latest/commandbutton.html

do you know where in the pyRevit docs i could find out more about this?

The other I came across was a maybe using a json file to read true/false but in the doc-updater.

All the links related to pyrevit are centralized here

The main documentation being on notion.
Look for ‘bundles’ in that documentation and you will find plenty.

Thank you for sharing the link. I am finding plenty to play around with.