Hoping all of you are doing good today!, I am looking for a way to show a warning message when a user intend to change a view template settings.
Is it possible to hook the command ID_APPLY_VIEW_TEMPLATE when it is executed from the view properties button?.
-At the moment my hook code is working only when the command is executed from the view tab:
-But, when I execute the same from the view properties button, the hook code does nothing:
This is the hook code I am using (thanks to @Jean-Marc):
import os
from pyrevit import EXEC_PARAMS
from pyrevit import forms
doc = __revit__.ActiveUIDocument.Document
ans = forms.alert("WARNING!\n\n"
"Do you really want to modify this view template?",
options=["Continue",
"Cancel"],
title="Apply View Template",
footer="HDS Hooks")
if ans == "Continue":
try:
from hooksScripts import hooksLogger
hooksLogger("Apply view template", doc)
except:
pass
elif ans == "Cancel":
EXEC_PARAMS.event_args.Cancel = True
else:
EXEC_PARAMS.event_args.Cancel = True
It would be that the Command ID is not the same when we use from the View tab and from the view properties?, Thanks in advance and greetings from Mexico City.
you may want to check your journal files right after editing the view template from the properties panel to check if there is a system postable command available to map as a hook
Hi @Jean-Marc thanks for your answer, I have checked the journal file but it seems there is no system postable command to do this mapping. I assume that it is not possible using hooks without it, is it right?, this is the fragment of the txt where my actions relative to view template appears.
Yep, that is what I thought too.
A different path would be to use iupdater / event listener initiated at startup.
Not really my cup of tea. But there are a few forum posts about it.
@Nicholas.Miles, sorry for including you here for this, Do you think using iupdater can be a solution for this issue, I have no experience using iupdater, this works saving the code in a folder like the hooks?
Sorry again and thanks in advance!
@Gil_Granados No I don’t think an iupdater would be able to elegantly solve this problem.
I did a quick test and an iupdater does not get notified when you apply view templates from the ribbon button, but that may be because of the parameter I was watching. An iupdater simply watches for changes to an element so it may be possible to make an iupdater work if you can find the relevant parameters on the view that will always change if you apply a template from the ribbon or properties panel. But an iupdater does not have the ability to “cancel” the change. You would have to cache the previous view template / parameters and manually change them back if you canceled the change from the dialog window.
When I tesed it, the iupdater got notified when you changed the view template from the properties panel, but you get notified after the template has been applied (after you click ok/apply from the view template menu).