Developer Guide

The Revitron package is a Revit API wrapper written in Python to help you developing clean and powerful Revit plugins in pyRevit. The package consists of a minimal main module and collection of specific submodules covering certain topics of the Revit API.

Concept

Basically this package is designed to be a generic Revit API toolbox. It doesn’t focus on a single topic, but tries to combine multiple wrapper classes instead to enable you to create plugins using just one single base library. However, there are two topics that are in the main focus of many pyRevit plugins — working with elements and filtering.

Note

Check out the cheat sheet to get you started quickly with the most common tools.

Working with Elements

Revitron elements wrap standard Revit elements and expose additional convenience methods in order to make working with the API a bit less cumbersome:

import revitron
_element = revitron.Element(element)

Alternatively to the default constructor it is also possible to create element instances by using the following shorthand function:

from revitron import _
_element = _(element)

In both cases _element is a proper Revitron element. This comes in handy in many situations where a quick access to an element is needed. The following example demonstrates how it is possible to set a parameter value, even though the parameter itself doesn’t exist yet:

from revitron import _
_(element).set('ParameterName', value)

In that one line we just set a parameter value and also created the parameter if neccessary. In order to get a parameter value of a given element we can use:

from revitron import _
comment = _(element).get('Comments')

You can find the documentation of more available element methods in the revitron.element reference.

Using Filters

Besides element properties, filtering is another core functionality of this package. Working with FiteredElementCollector instances can be quite complex and difficult to debug. Revitron provides a Filter that implements a powerful tool to also filter the database by parameter values using human readable one-liner:

import revitron
filter = revitron.Filter
ids = filter().byStringEquals('param', 'value').noTypes().getElementIds()

Revitron Module

The main Revitron module contains only some global module properties as well as the magic _() function. Specific classes are located in the submodules listed below.

DOC

The currently active document.

UIDOC

The active UI document.

APP

A shortcut for accessing the application object of the active document.

ACTIVE_VIEW

The active view element.

DB

A shortcut for Autodesk.Revit.DB.

LIB_DIR

The path to the Revitron library extension directory.

REVIT_VERSION

The version number string of the running Revit application.

Subpackages

Submodules