IUpdater Interface / Dynamic Model Updater

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

Example
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")
    p.Set(5)

2 Likes

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
C:\Users\sdc\AppData\Roaming\pyRevit\Extensions
==> Extension Search Paths
C:\Users\sdc\Documents
==> Extension Sources - Default
https://github.com/eirannejad/pyRevit/raw/master/extensions/extensions.json
==> Extension Sources - Additional
==> Installed Revits
2020.2.3 | Version: 20.2.30.42 | Build: 20200826_1250(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2020\"
2018.3.3 Security Fix | Version: 18.3.3.18 | 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 4.8.4.0

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

That seemed to do the trick! :mage: I’m wrapping up my code and will test and report back here. Thanks again for all your help! :+1:

1 Like

I hate to take up your time like this! :pleading_face: so sorry! I am getting a strange error :thinking:

This is how I’m hoping to use this updater by the way, nothing too complicated, right? It doesn’t find the exact width and length of rooms that are off-axis or funny shapes, but for a majority of rooms it should work.

from pyrevit import EXEC_PARAMS
from pyrevit import revit, DB

def round_to_nearest_inch(n):
    return round(n * 12) / 12

doc = EXEC_PARAMS.event_args.GetDocument()

for room in revit.query.get_elements_by_class(DB.Room, doc=doc):
    w = room.LookupParameter("Width")
    l = room.LookupParameter("Length")

    rBoundingBox = room.get_BoundingBox( None )
    
    width = rBoundingBox.Max.X - rBoundingBox.Min.X
    length = rBoundingBox.Max.Y - rBoundingBox.Min.Y
    
    w.Set(round_to_nearest_inch(width))
    l.Set(round_to_nearest_inch(length))

Yeah the script looks good. I gotta debug and see why the import pyrevit fails on detecting the running app. Will do that this weekend.

Any progress?
I’m also into the IUpdater implementation and it seems that “doc-updater” is detected but I also got the error that NoneType object has no attribute 'VersionNumber". So it is not detecting the application?

1 Like

It’s been a couple of years, any updates on this?