Is there any way to create a hook that reacts to a specific family type being placed? I would like to trigger a dialog box upon creation of a new level in the model, but am not seeing any way to do this with command-exec.
to trigger on level creation, try to put these in your hooks folder and reload:
- command-exec[ID_OBJECTS_LEVEL].py file:
# pylint: skip-file
import os.path as op
from pyrevit import EXEC_PARAMS
from pyrevit import script
args = EXEC_PARAMS.event_args
output = script.get_output()
output.print_image(
op.join(op.dirname(__file__), op.basename(__file__).replace('.py', '.gif'))
)
# do stuff
- the gif command-exec[ID_OBJECTS_LEVEL].gif
ha ha. very funny - but really, can you please help me find the right direction to look in? I’ve never worked with hooks before and am a little lost coming from Dynamo world. I don’t want to override the default behavior of the place level command ID, only use it’s execution to trigger a GUI window with a few options on what to do next. I see there is a before-exec, but not a post-exec hook listed in the hooks page on Notion.
can you expand on what you are trying to achieve?
in pseudo code maybe?
Sure - I haven’t actually coded any of this yet, but I would like for a GUI window to pop up after a new level is added to the model. GUI would have a selection box of options on which plan view types to create on the new level - floor plan, reflected ceiling plan, demo plan, etc. GUI box is easy, and I’m familiar enough with view creation in Python to handle that bit - it’s just the actual event trigger I am lost on. Something like this (definitely pseudo-code):
# On event hook for level created...
if level_created:
# Options GUI
items = ['Floor Plan', 'Demo Plan', 'RCP']
selected_options = forms.SelectFromList.show(items, button_name='Select View Types')
if selected_options:
#Create views, apply view templates, etc.
Nice one @Jean-Marc ! My question, not about the gif but about the “family placement”. It is possible to catch the family by is name for example? Or like the topic of the post before the placement? I look in the API and maybe Application.DocumentChanged event can do the job (once the instance will be placed). Thanks!
Say not to sound pretentious but if that is what you want to do, why… wouldn’t you be better of just creating a button that can do this for a selected level? Not bother with the response to a revit button being pressed?
Though I am very curious if it is possible to react to specific buttons, I get the feeling that you’re over-engineering this.
Now if you really want to respond to a level being created, you could also try a creating an updater.
You could see it as a hook, but you can configure it to respond to more specific events.
Did you ever find a solution that worked for this?