PyRevit – Part 2- Attempting basic coding, little success
After looking at all the tutorial videos and doing the basic exploring features of setting up a Ribbon tab from tutorial code it is time to try and do something.
I crashed and burned trying to adapt some code for selection and colouring and realised I was over reaching a bit. So I need to dial back my expectations and start some code that can do some basic things.
Revit Python Wrapper (RPW) in Interactive Python Shell -So far no go
One thing I tried to do was to get RPW (Revit Python Wrapper) running inside of the Interactive Python Shell (IPS) inside of Revit. I failed and couldn’t get that going. Wrapper classes make the interaction with API objects less repetitive, and more consistent with Python’s conventions. What this means to me is its more pythonic scripting, and as it is already incorporated inside PyRevit, I wanted to be able to run the wrapper classes inside of IPS, so that the code was similar for PyRevit and IPS. So a work in progress
- Speed up the tedious stuff and enjoy designing and documentation more
- Works in all versions of Revit
- Information to PROVE your increased speed
Code & tutorials
After following on with the tutorials from PyRevit I wanted to try and do a few things. I found I had a lot of difficulty. I didn’t know the Revit API classes so got confused with using a method, being returned something and not knowing how to manage that item.
With a lot of tutorials, they start at the basics and then there are no intermediate courses, so I flounder. All I can do is look at something that is similar to what I want and see if I can twist it to my needs.
I found the pyRevit documentation dispersed. What is shown in the video’s is not current. A lot of links lead you to https://pyrevit.readthedocs.io/en/latest/ but in fact the documentation is at https://pyrevit1.readthedocs.io/en/latest/
Then jumping to the RPW thats another lot of documentation, and the coding is slightly different.
Looking on Github for all of the great code that has been shared by a lot of generous people is overwhelming. A lot of them are very advanced coders and confident in the environment, but its way above my paygrade, some is pyrevit, some RPW and some use more simple calling of setup codes.
I like the tutorial by Dan Boghean that he did in Bild 2019. That gave me an insight on where I was having a few basic problems that I need to try and get my head around, and they are:
- Display intformation to screen, so when you have done something you can check what has been returned and if it’s what you expected. So print( WHAT I WANT TO SEE) is the way for this.
- A selection “PICK OBJECT” or “PICK OBJECTS” or “PICK RECTANGLE”. So select something and put it into a variable or list to then process.
- An input box , so if you have a variable, say a wall Height, you can give it another height to reset to.
- A results dialogue pop up box
End comment
I got sidetracked by a current project and didn’t get too far down the track with this, a bit frustrating as I didn’t make too many inroads.
I really want to make a couple of basic scripts, maybe just change linetypes, so I can have some basic workable code. A bit like my preliminary exploration of LISP in AutoCAD. I seem to hit the wall all the time. I’ll need to go back and restart the tutorials again.
Ideas of simple things to do. Every time I think I’m only trying to ask Revit for something simple, it ends up being a lot more complex and I don’t achieve my goal. I put it down, reflect and then I try something else, but I’m not getting the coding gains to date to make me build on simple success. I’m getting bogged down in the Revit API code, that just hits me like a big hammer.