Well so the idea is that in order for python to do something, or interact with something. It needs to know about that thing.
In the example you provide for example the code is expecting to do something with an object called ‘uidoc’, but it doesn’t understand what this uidoc thing is. Because (as the error says) it has not been defined.
Now if you’re running this as a pyrevit script you are in luck. Because all you have to add to your script is
from pyrevit import uidoc
and that should do it.
This line tells python to look for the ‘uidoc’ in pyrevit’s code.
I do hope that you’re doing this in a pyrevit script, otherwise getting the uidoc is a bit more cumbersome ( but perfectly doable)
But I honestly don’t know how I would have known to use that just by reading this page. It goes more indepth into ‘class pyrevit._HostApplication’…but I don’t see mention of ‘HOST_APP’ anymore outside of the example at the top.
I guess what I’m getting at is I’m having a hard time understanding when to load what module based off of the documentation. Am I missing something or does it just come with time and referencing other scripts?
You are right Aaron, you will get it with time and experience. But here are a few pointers:
When searching in the code base you will get the definition of HOST_APP here
all the attached properties here in the _HostApplication Class object
The search and the symbol navigation have greatly improved in github in the past year or so. Use it.
Using the new and not yet publicized documentation, you will get there a bit quicker as well https://ein.sh/pyRevit/reference/pyrevit/
The search is much more performant and the auto documentation itself is grabbing every variable, class, property and definition of the pyrevit libraries, not only some of them randomly like the previous readthedocs one.
and obviously, reading the code of others script does help.
credits to @sanzoghenzo for the refactoring of the documentation process and the quick start forum post
There is plenty of samples, sources for learning. But my best advice is to start small and incrementally grow your scripts and skills. Don’t start with a pet project that is too big.