IUpdater Interface / Dynamic Model Updater

Hello everyone! :wave: I created a tool that determines the width and length of all rooms in a project and am looking into how I can convert it from something that needs to be manually updated from time to time via a pushbutton on the UI to something that runs automatically in the background like these examples:

Is it as simple as converting one of those examples into python and then putting it into an Extension Startup Script? :thinking:
I can post my code for the pushbutton if necessary but I’m still in the conceptual stage for this auto-dynamic model updater. Thanks in advance for any assistance! :grin:

1 Like

Have you looked at pyRevit hooks? https://www.notion.so/Create-Your-First-Hook-0214eee855fc43cead1e6f30f586a04e

You might be able to tie this to a Revit event, so it gets executed every time the event is fired by Revit

Thanks for your reply! Yes, I originally wrote my room update script as a doc-changed hook but I wasn’t sure how I could piggy-back on the previous transaction. I would like to avoid creating a new Revit Transaction. Is there a way to make it so certain transactions do not show up in the Undo/Redo history? I thought the IUpdater interface might be a good way to go because this Revit help page described pretty much what I would like to achieve:

Dynamic model update offers the ability for a Revit API application to modify the Revit model as a reaction to changes happening in the model when those changes are about to be committed at the end of a transaction.

1 Like

Uh okay. Makes sense now. What if we add a iupdater hook to pyRevit as well to make this super easy?


That would be super amazing! :sparkles: I think there are lots of use cases for the IUpdater Interface that would justify getting it set up in pyRevit. The hardest part for me has been translating the C# examples to python and how scripts interact with each other. Having it as a hook would be very nice :sunglasses:

1 Like

Added it to my list :smiley:


Okay so this is where the implementation is going:

  • You can add hooks/doc-updater.py as a hook script that gets tied to and internal pyRevit IUpdater handler
  • On every element change, pyRevit will run your hook and will pass the UpdaterData as arguments

This hook script sets the wall heights to 5 on model changes

from pyrevit import EXEC_PARAMS
from pyrevit import revit, DB

doc = EXEC_PARAMS.event_args.GetDocument()

for wall in revit.query.get_elements_by_class(DB.Wall, doc=doc):
    p = wall.LookupParameter("Unconnected Height")


Wow, that looks great! Is this available to pull from GitHub?

1 Like

See feature/updaterhook. Still chaging to keep pulling the recent changes. Feel free to send PRs if you also have ideas for improvements :slight_smile:

@scartmell Did you get a chance to check this out?

@eirannejad I’ve noticed that you are using ChangeTypeAny on all elements, and I’m afraid there is a high chance of infinite loop which will make Revit to disable the updater. Meanwhile I’m surprised that it still works as it is seen on the gif, and it doesn’t break. What is the trick?

btw the thing that you implemented the updater in pyRevit made me code my own ExternalApp that makes a Generic Annotation into a “Free” spot elevation, which can be placed enywhere on a section for instance, and still reports back its exact elevation in a label. So thanks for the inspiration :wink:

1 Like

Hey @eirannejad sorry for my delay! I set up the pyrevit CLI and used it to clone the feature/updaterhook branch and then attached it to revit but it won’t open :pensive: I followed @Jean-Marc’s post and some of your videos, I’m not sure what I’m doing wrong :sob: I can post the error message if that helps!

Run pyrevit env and share the report please

Okay! Here’s what I got:

PS C:\Program Files\pyRevit CLI> pyrevit env
==> Registered Clones (full git repos)
dev | Branch: "feature/updaterhook" | Version: "4.8.4:e6adb6f" | Path: "C:\Users\sdc\AppData\Roaming\pyRevit\pyRevit\dev"
==> Registered Clones (deployed from archive/image)
==> Attachments
dev | Product: "2020.2.3" | Engine: 2710 | Path: "C:\Users\sdc\AppData\Roaming\pyRevit\pyRevit\dev" | Manifest: "C:\ProgramData\Autodesk\Revit\Addins\2020\pyRevit.addin"
dev | Product: "2018.3.3 Security Fix" | Engine: 2710 | Path: "C:\Users\sdc\AppData\Roaming\pyRevit\pyRevit\dev" | Manifest: "C:\ProgramData\Autodesk\Revit\Addins\2018\pyRevit.addin"
==> Installed Extensions
CGD | Type: Unknown | Repo: "" | Installed: "C:\Users\sdc\Documents\CGD.extension"
==> Default Extension Search Path
==> Extension Search Paths
==> Extension Sources - Default
==> Extension Sources - Additional
==> Installed Revits
2020.2.3 | Version: | Build: 20200826_1250(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2020\"
2018.3.3 Security Fix | Version: | Build: 20190510_1515(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2018\"
==> Running Revit Instances
==> User Environment
Microsoft Windows 10 [Version 10.0.18363]
Executing User: CGD\SDC
Active User: CGD\SDC
Admin Access: Yes
%APPDATA%: "C:\Users\sdc\AppData\Roaming"
Latest Installed .Net Framework: 4.8
No .Net Target Packs are installed.
No .Ne-Core Target Packs are installed.
pyRevit CLI

Okay seems to be the full clone dev is properly attached to 2020 and 2018. Let’s run a pyrevit caches clear --all and see if it loads

Thanks for troubleshooting this with me! I ran that command, it seemed to work fine, but I still get an error when opening revit:

Okay you need to rebuild the binaries since you are on the develop branch so you have the latest. Do you have visual studio installed?

I don’t have any specific plans for the “ChangeTypeAny” potential issue. Unless we can come up with a system to specify some sort of element filtering for the doc-updater hook. I’m open to ideas

I don’t have Visual Studio installed. I know there are a few types… Is Visual Studio Code okay?

Vscode is no good. Download this file and extract the contents in to the pyRevit bin/ directory. It will overwrite existing DLLs