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
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.
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! 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
Added it to my list
Okay so this is where the implementation is going:
hooks/doc-updater.py
as a hook script that gets tied to and internal pyRevit IUpdater
handlerExample
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)
Wow, that looks great! Is this available to pull from GitHub?
See feature/updaterhook
. Still chaging to keep pulling the recent changes. Feel free to send PRs if you also have ideas for improvements
@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
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 I followed @Jean-Marc’s post and some of your videos, I’m not sure what I’m doing wrong 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! I’m wrapping up my code and will test and report back here. Thanks again for all your help!