After looking through the Notion page on hook scripts, I’m uncertain which hook I might use if I wanted to update an electrical panel parameter every time the corresponding panel schedule is modified. I’m trying to update and store the breaker count with the panel data.
doc-changed. The event data will give you information about added, removed, and modified elements. If someone changes data in a schedule, they’re actually changing values of properties on Revit elements so you’d get a
doc-changed call with a list of modified elements. Use these methods on the
from pyrevit import EXEC_PARAMS args = EXEC_PARAMS.event_args args.GetAddedElementIds() args.GetDeletedElementIds() args.GetModifiedElementIds()
Edit: So I thought I had a working implementation below, but then I realized I forgot to include a transaction to update the parameter. Unfortunately I then discovered that the DocumentChanged Event is read-only and does not allow transactions. This makes a lot of sense, considering this script would lead to the DocumentChanged event getting called in an infinite loop. The API recommends using an IUpdater, but I’m not familiar with how that would be implemented, particularly in Python. Any tips would be greatly appreciated!
from pyrevit import revit, DB, forms, EXEC_PARAMS doc = revit.doc args = EXEC_PARAMS.event_args def get_circuit_count(elec_equip): return len(elec_equip.MEPModel.GetAssignedElectricalSystems()) elec_equip_filter = DB.ElementCategoryFilter( DB.BuiltInCategory.OST_ElectricalEquipment) modified_elec_equip_ids = args.GetModifiedElementIds(elec_equip_filter) for Id in modified_elec_equip_ids: elec_equip = doc.GetElement(Id) count = get_circuit_count(elec_equip) elec_equip.LookupParameter('CircuitCount').Set(count)
Any progress on this issue?
I need to change some parameters whenever a user moves an element. But the doc-changed hook doesn’t allow transactions…
Apologies - I got pulled onto billable work and have been unable to return to this. I recommend trying the two examples from this post: