I’m trying to follow the PyRevit tutorial.
In the first example he tries to show how to collect all elements of the wall category from within the Interactive Revit Python Shell. I have already configured the RPS startup script to be the file this file he offers in the course: https://gist.github.com/eirannejad/4e275166bf2015f4f844bb1d087ca4d6
For some reason though, I get this error. Please see image attached:
thank you brother.
had the exact same issue.
i would like to understand why this happened? is it possible that the init script got somehow corrupted and it didn’t read the imports?
Thanks. Ya just use this init script with RPS and then use the DB namespace to access all DB types like DB.FilteredElementCollector
Generally importing all types into your local script namespace is a bad idea and takes execution time and also creates name conflicts. e.g. from Autodesk.Revit.DB import * is bad
I find that Dynamo is a better debugging platform for pyRevit Python than the python shell.
Just put the declarations in your Dyanmo python template and run the script in Dynamo for testing. When you have everything working - just copy/paste it all out to a *.py file and away you go.
Note that I’ve referenced both Dynamo and pyRevit so I can use either (Dynamo is a bit of a pain because it needs to be initialized first)
sys.path.append('C:\Program Files\pyRevit-Master\pyrevitlib')
sys.path.append('C:\Program Files\Autodesk\Revit 2020\AddIns\DynamoForRevit')
#Use this for pyRevit. Ok to use inside Dynamo as well if pyRevit is referenced.
#doc = __revit__.ActiveUIDocument.Document
#app = __revit__.Application
#uidoc = __revit__.ActiveUIDocument
#uiapp = __revit__.CurrentUIApplication
#Dynamo - I'll use this if the end product is going to be a dyn rather than a py.
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = uiapp.ActiveUIDocument