This forum is a fantastic place to connect, learn, and troubleshoot together. To ensure that we make the most of this community, let’s go over some guidelines that will make seeking and offering help much smoother:
- Search First: Before posting a new question, take a moment to search the forum. Someone might have already encountered a similar issue and found a solution.
- Provide Details: When asking for help, be sure to include your code and configuration settings. Generic descriptions or error messages aren’t enough for us to pinpoint the problem accurately.
- Use Code Blocks: When sharing code snippets or file contents, wrap them in triple backticks (```) to maintain formatting and readability.
- Mark Solutions: If someone provides a solution that solves your problem, please mark their message as the solution. This helps others quickly identify what worked.
Let’s keep the collaborative spirit alive by following these simple guidelines. Happy coding and problem-solving!
For those seeking resources to enhance their pyRevit skills, here are some valuable sources to explore:
- Developer Docs
- pyrevitlib Documentation - Note that not everything is documented here yet - we’re working on it!
- Official Readme
- Learn Revit API and ErikFrits YouTube Channel
- PyRevit YouTube Channel for more advanced content
- Danny Bentley YouTube Channel with excellent foundational material
- @Jean-Marc 2022 Lab in the handout section
- Revit Python Shell Samples
- Useful insights from Gavin Grump
- Refer to Revit API Docs or apidocs.co
- fresh from the press, @Erik Fritz presentation at the bim coordinator summit last week 7 steps - Revit API
Transitioning from .Net/C# to IronPython/CPython might feel tricky, but here are some tips to ease the process:
- You don’t need to declare variable types explicitly; just assign the value.
- Unlike in C#, you don’t need the
newkeyword when creating class instances.
- in C#, variables and method arguments are in
camelCase, while in Python, the preferred style is
snake_case. This is not an obligation, but helps make the code readable for everybody. Note that this applies to objcets created by you in your code, of course revi API objects needs to be accessed with the exact case you find in the reference.
- Python modules (files) should also be named in
- Most of the time, you can directly use Python lists without converting them to typed lists using
For those transitioning from Dynamo to pyRevit, here are some helpful resources:
Keep in mind:
- See the section below
- Note that the
UnwrapElementfunction is not needed in pyRevit, as you directly access Revit objects.
- Watch out for indentations! Dynamo script editor uses tabs, while common IDEs (vscode, pycharm and so on) converts tabs to spaces. And python likes to have the same type of whitespace, so make sure they are all of the same tyoe when copy-pasting
In case you missed them, here are some useful things provided by pyRevit’s Python package:
- No need to
import clror add references to the Revit API; many objects are already loaded by pyRevit and available to you, just import
- Access the current document easily with
pyrevit.revit.queryfunctions for element searching; the module provides easy access to
Here are some common issues to watch out for:
- CPython support is buggy. While we’re trying to update the compatibility layer (pythonnet) to the latest version before we can address pyrevitlib bugs.
- Python 2.x doesn’t handle UTF-8 script files by default, you need to place
# -*- coding: utf-8 -*-at the end of each file;
- python 3 defaults to UTF-8, so there’s no need for that line, but for pyRevit to recognize the python version to run, you have to use
- Metadata variables at the beginning of the script are deprecated in favour of bundle.yaml files - this is not an issue per se, but the problem arises when one uses both of them for the same script. To be on the safe, future-proof, side, just use bundle.yaml!
- If you want to share your extensions with others, prefer a versioning system such as git instead of putting your code on a shared cloud drive: client apps treat files and paths in an unpredictable manner, and can lead to pyrevit erroring out while trying to load the extension.
Don’t miss out on the convenience of these libraries:
- rpw - Revit Python Wrapper
Here are tools that could prove invaluable:
- IronPython Stubs for autocompletion in your favorite IDE
- Check out the PyCharm Guide
- Revit Lookup to inspect the revit database
- Revit Python Shell - although you can create an interactive console with a simple pyRevit script
from rpw.ui.forms import Console Console()
A few words of wisdom:
- If you find a tool similar to what you’re trying to achieve, ALT+Click on it and explore the code in the
script.pyfile to understand the solution.
- Break down your problem into smaller tasks and tackle them one by one. This approach can make complex tasks much more manageable.
Let’s learn and grow together! If you have questions or insights, don’t hesitate to share. Happy coding!
Note: Thanks to @sanzoghenzo for the heavy lifting