Revitron is a Revit API wrapper written in Python. It helps you to develop clean and powerful Revit plugins in pyRevit.
Revitron is a Revit API wrapper written in Python that can help you to develop clean and powerful pyRevit extensions. Check out the developer guide for more information or use the cheat sheet to get started quickly.
There are three options for installing Revitron and the Revitron UI — using the pyRevit UI, using the pyRevit CLI or installing the full bundle.
Important
Note that in order to use the Revitron package manager or the bundle installer, Git must be installed on your computer.
To use the Revit UI to install this extensions, open the pyRevit tab, click on pyRevit > Extensions to open the extensions manager and follow these instructions.
In case you want to use the command line to install Revitron and the Revitron UI, use the following command:
pyrevit extend lib revitron https://github.com/revitron/revitron.git
pyrevit extend ui revitron https://github.com/revitron/revitron-ui.git
There is also a bundle installer available that will install pyRevit including the Revitron and the Revitron UI packages.
Right-click here
to download the Revitron installer. Make sure it keeps the .bat
extension.
Move the install.bat
to the directory, where you want to install pyRevit.
Double-click the install.bat
file to start the installation and wait until it has finished.
Start Revit.
In order to be able to run the revitron command from anywhere it has to be added to your path environment variable. You can do that manually or by running the following commands once:
cd path\to\revitron.lib
cli\setup
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.
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.
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.
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()
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.
The currently active document.
The active UI document.
A shortcut for accessing the application object of the active document.
The active view element.
A shortcut for Autodesk.Revit.DB
.
The path to the Revitron library extension directory.
The version number string of the running Revit application.
The revitron.analyze
module helps you to automate analysing the health and status of a model and to extract
several types of data and statistics in order to simplifiy BIM quality control. Extracted data is stored
as snapshots in a SQLite database to be consumed by other applications or dashboards.
Bases: object
The DataProviderResult
object handles the execution of a data provider by creating a unified results object
containing the provider name, the resulting value and its data type.
Inits a new provider class instances and runs the provider’s run()
method
in order to populate the value property.
providerClass (string) – The class name for the data provider that has to be used
providerName (string) – A descriptive name to generate the storage field
providerConfig (dict) – The configuration that is passed to the data provider
The data type that is used to store the value.
The data type
string
The name that is used to create a storage field.
The field name
string
The resulting value.
The value that is returned by the provider’s run()
method
mixed
Bases: object
The ModelAnalyzer
class applies a configured set of data providers on a model
and creates snapshots with the extracted statistics in a given SQLite database.
This submodule provides an synchronizer class for mirroring hsitory data to Directus.
Classes:
|
This synchronizer class mirrors sync meta data that is tracked by the Revitron History into a Directus database. |
Bases: object
This synchronizer class mirrors sync meta data that is tracked by the Revitron History into a Directus database.
Methods:
|
Init the synchronizer. |
|
Fetch sync meta data from the history SQLite file and push it to the Directus database. |
This submodule is a collection of data providers that are used to extract information from a given Revit model.
Classes:
|
The abstract data provider. |
|
This data provider returns the accumulated area of a set of elements after applying all filters that are defined in the provider configuration. |
|
This data provider returns the count of filtered elements after applying all filters that are defined in the provider configuration. |
|
This data provider returns the accumulated length of a set of elements after applying all filters that are defined in the provider configuration. |
|
This data provider returns the accumulated area of a set of elements after applying all filters that are defined in the provider configuration. |
|
This data provider returns the number of warnings in a model. |
Bases: object
The abstract data provider. A data provider must implement a run()
method
that actually defines the extracted data.
Methods:
|
Init a new data provider with a given configuration. |
|
The abstract method for data extraction. |
Attributes:
The data type property defines the data type of the provided data in the database. |
|
The value type property defines the type of the provided data in the database, such as length, area, volume or count. |
Init a new data provider with a given configuration.
config (dict) – The data provider configuration
The data type property defines the data type of the provided data in the database.
The data type that is used for provided values in the database
string
The abstract method for data extraction. This method must be implemented by a data provider.
The value type property defines the type of the provided data in the database, such as length, area, volume or count.
The value type
string
Bases: AbstractDataProvider
This data provider returns the accumulated area of a set of elements after applying all filters that are defined in the provider configuration.
Methods:
|
Init a new data provider with a given configuration. |
|
Apply filters and accumulate the area of the filtered elements. |
Attributes:
The area data type is |
|
The value type is |
Init a new data provider with a given configuration.
config (dict) – The data provider configuration
The area data type is real
.
The data type
string
Apply filters and accumulate the area of the filtered elements.
The accumulated area
integer
The value type is area
.
The value type
string
Bases: AbstractDataProvider
This data provider returns the count of filtered elements after applying all filters that are defined in the provider configuration.
Methods:
|
Init a new data provider with a given configuration. |
|
Run the data provider and return the number of filtered elements. |
Attributes:
The data type property defines the data type of the provided data in the database. |
|
The value type for the counter is |
Init a new data provider with a given configuration.
config (dict) – The data provider configuration
The data type property defines the data type of the provided data in the database.
The data type that is used for provided values in the database
string
Run the data provider and return the number of filtered elements.
The number of filtered elements
integer
The value type for the counter is count
.
The value type
string
Bases: AbstractDataProvider
This data provider returns the accumulated length of a set of elements after applying all filters that are defined in the provider configuration.
Methods:
|
Init a new data provider with a given configuration. |
|
Apply filters and accumulate the length of the filtered elements. |
Attributes:
The length data type is |
|
The value type is |
Init a new data provider with a given configuration.
config (dict) – The data provider configuration
The length data type is real
.
The data type
string
Apply filters and accumulate the length of the filtered elements.
The accumulated length
integer
The value type is length
.
The value type
string
Bases: AbstractDataProvider
This data provider returns the accumulated area of a set of elements after applying all filters that are defined in the provider configuration.
Methods:
|
Init a new data provider with a given configuration. |
|
Apply filters and accumulate the volume of the filtered elements. |
Attributes:
The volume data type is |
|
The value type is |
Init a new data provider with a given configuration.
config (dict) – The data provider configuration
The volume data type is real
.
The data type
string
Apply filters and accumulate the volume of the filtered elements.
The accumulated area
integer
The value type is volume
.
The value type
string
Bases: AbstractDataProvider
This data provider returns the number of warnings in a model.
Methods:
|
Init a new data provider with a given configuration. |
|
Get the number of warnings. |
Attributes:
The data type property defines the data type of the provided data in the database. |
|
The value type is |
Init a new data provider with a given configuration.
config (dict) – The data provider configuration
The data type property defines the data type of the provided data in the database.
The data type that is used for provided values in the database
string
The value type is count
.
The value type
string
This submodule is a collection of storage drivers that can be used to store extracted model information in different types of formats such as SQLite, JSON or API based databases.
Classes:
|
The abstract storage driver is the base class for all storage driver classes. |
|
The DirectusAPI class provides the needed tools to interact with the Directus API. |
|
This storage driver handles storing snapshots to in Directus using the Directus API. |
|
This storage driver handles appending snapshots to JSON files. |
|
This storage driver handles the connection to the SQLite database as well as the actual creation of the snapshots. |
Bases: object
The abstract storage driver is the base class for all storage driver classes.
Methods:
|
Init a new storage driver instance with a givenm configuration. |
|
Add a new snapshot. |
Init a new storage driver instance with a givenm configuration.
config (dict) – The driver configuration
Add a new snapshot.
dataProviderResults (list) – The list of
revitron.analyze.DataProviderResult
objects
modelSize (float) – The local file’s size in bytes
Bases: object
The DirectusAPI class provides the needed tools to interact with the Directus API.
Methods:
|
Init a new API wrapper instance. |
Clear the Directus cache. |
|
Test whether a collection exists. |
|
Create the collection. |
|
|
Create a field in the collection. |
|
Get data from a given endpoint. |
Get the fields list of a collection. |
|
|
Post data to a given enpoint. |
Init a new API wrapper instance.
host (string) – The API URL
token (string) – The API token that is used for authentication
collection (string) – The collection name
Test whether a collection exists.
True if the collection exists
bool
Create a field in the collection.
name (string) – The field name
dataType (string) – The data type for the field
The response data
dict
Get data from a given endpoint.
endpoint (string) – The Directus API endpoint
log (bool, optional) – Enable logging. Defaults to True.
The reponse dictionary
dict
Bases: AbstractStorageDriver
This storage driver handles storing snapshots to in Directus using the Directus API.
Methods:
|
Init a new Directus storage driver instance with a givenm configuration. |
|
Send a POST request to the Directus API in order store a snapshot |
Init a new Directus storage driver instance with a givenm configuration.
config (dict) – The driver configuration
Send a POST request to the Directus API in order store a snapshot
dataProviderResults (list) – The list of
revitron.analyze.DataProviderResult
objects
modelSize (float) – The model size in bytes
Bases: AbstractStorageDriver
This storage driver handles appending snapshots to JSON files.
Methods:
|
Init a new storage driver instance with a givenm configuration. |
|
Add a new item to JSON file. |
Init a new storage driver instance with a givenm configuration.
config (dict) – The driver configuration
Add a new item to JSON file.
dataProviderResults (list) – The list of
revitron.analyze.DataProviderResult
objects
modelSize (float) – The local file’s size in bytes
Bases: AbstractStorageDriver
This storage driver handles the connection to the SQLite database as well as the actual creation of the snapshots.
Methods:
|
Init a new storage driver instance with a givenm configuration. |
|
Add a new row to the snapshots table. |
Init a new storage driver instance with a givenm configuration.
config (dict) – The driver configuration
Add a new row to the snapshots table.
dataProviderResults (list) – The list of
revitron.analyze.DataProviderResult
objects
modelSize (float) – The local file’s size in bytes
The revitron.ui
module provides a set of helpers for creating UI elements in pyRevit.
This submodule contains a collection of basic form elements.
Classes:
|
A simple checkbox component. |
|
A simple label component. |
A dropdown field. |
|
|
A text input field |
Bases: object
A simple checkbox component.
Methods:
|
A helper function that creates checkbox form element. |
A helper function that creates checkbox form element.
window (object) – The parent window object
containerName (string) – The name of the parent container
key (string) – The key that references the value in the window values dictionary
input (mixed) – The input value
title (string, optional) – The checkbox title. Defaults to the key.
Bases: object
A simple label component.
Methods:
|
A helper function that creates a label component. |
Bases: object
A dropdown field.
Methods:
|
Create a select dropdown in a specific container of a given window. |
Create a select dropdown in a specific container of a given window.
window (Window) – The Revitron Window object
containerName (string) – The name of the target container
key (string) – The key
options (dict|list) – The dict or list of options
input (dict|string) – The value for the field - a configuration dict where ‘key’ stores the value, or simply a string
title (string, optional) – An optional title. Defaults to None.
Bases: object
A text input field
Methods:
|
Create a text box in a specific container of a given window. |
Create a text box in a specific container of a given window.
window (Window) – The Revitron Window object
containerName (string) – The name of the target container
key (string) – The key
input (dict|string) – The value for the field - a configuration dict where ‘key’ stores the value, or simply a string
title (string, optional) – An optional title. Defaults to None.
The window
submodule contains classes for generating UI windows.
Classes:
|
An abstract base window class. |
|
A simple window. |
|
A window where the content is split into multiple custom tabs. |
Bases: FlexForm
An abstract base window class.
Methods:
|
Init a new window object. |
|
Close the window |
|
Get the container within the window by name. |
Bases: AbstractWindow
A simple window.
Methods:
|
Init a new simple window. |
|
Close the window |
|
Get the container within the window by name. |
Get the values of all form elements in the window and store them in the |
Init a new simple window.
title (string) – The window title
width (int, optional) – The window width. Defaults to 520.
height (int, optional) – The window height. Defaults to 620.
cancelButtonText (str, optional) – The cancel button text. Defaults to ‘Cancel’.
okButtonText (str, optional) – The OK button text. Defaults to ‘OK’.
Close the window
Get the container within the window by name.
name (name) – The container name
The container in the window
object
Bases: AbstractWindow
A window where the content is split into multiple custom tabs.
Methods:
|
Init a new tabbed window. |
|
Close the window |
|
Get the container within the window by name. |
Get the values of all form elements in the window and store them in the |
Init a new tabbed window.
title (string) – The window title
tabs (list) – The list of tab names
width (int, optional) – The window width. Defaults to 520.
height (int, optional) – The window height. Defaults to 620.
cancelButtonText (str, optional) – The cancel button text. Defaults to ‘Cancel’.
okButtonText (str, optional) – The OK button text. Defaults to ‘OK’.
Close the window
Get the container within the window by name.
name (name) – The container name
The container in the window
object
The boundingbox
submodule complements the Revit API bounding box methods
by a simple helper class for working with bounding box elements.
Classes:
|
A |
Bases: object
A BoundingBox
class instance is a wrapper element for Revit bounding box object.
Create a new instance as follows:
bbox = revitron.BoundingBox(element)
Or even:
bbox = _(element).getBbox()
Attributes:
The |
|
The |
Methods:
|
Inits a new BoundingBox instance for an element. |
|
Checks whether the bounding box contains another bounding box. |
Returns the center point of the bounding box. |
|
|
Checks whether a point is inside a bounding box. |
The Max
point of the bounding box.
A Revit XYZ object
object
The Min
point of the bounding box.
A Revit XYZ object
object
Inits a new BoundingBox instance for an element. In case the element has a scope box applied, the scope box’s bounding box is taken. In case the element has no scope box, but is a view plan, the crop box is used. The default Revit bounding box is used for all other elements.
element (object) – A Revit Element
Checks whether the bounding box contains another bounding box. Only in X and Y dimensions.
Example:
contains = _(element1).getBbox().containsXY(_(element2).getBbox())
bbox2 (object) – A bounding box object
True if the bounding box entirely contains bbox2
boolean
To simplify the interaction with Revit categories, the category
submodule provides the Category
and BuiltInCategory
classes in order
to access Revit category objects as well as builtin categories by name.
Classes:
|
A wrapper class for builtin category objects which can be instantiated by name. |
|
A wrapper class for category objects which can be instantiated by a category name. |
Bases: object
A wrapper class for builtin category objects which can be instantiated by name.
You can get the Revit BuitlInCategory class object by providing a name as follows:
bic = revitron.BuiltInCategory('OST_Walls').get()
For convenience reasons, it is also valid to skip the OST_
prefix and simply do:
bic = revitron.BuiltInCategory('Walls').get()
In case you only know the natural category name and want to get the BuiltInCategory instead,
you can also use that one. For example to get the OST_BeamAnalyticalTags
BuiltInCategory, you
can do simply:
bic = revitron.BuiltInCategory('Analytical Beam Tags').get()
A full list of category names can be found here.
Methods:
|
Get the BuiltInCategory by its name, its name without the |
|
Return the BuiltInCategory class. |
Get the BuiltInCategory by its name, its name without the OST_
prefix
or even its natural category name. A full list of category names can be found here.
Example:
bic = revitron.BuiltInCategory('OST_Walls').get()
bic = revitron.BuiltInCategory('Walls').get()
Use the natural name to get for example OST_BeamAnalyticalTags
:
bic = revitron.BuiltInCategory('Analytical Beam Tags').get()
name (name) – The name, the name without the OST_
prefix or even the
natural category name
Bases: object
A wrapper class for category objects which can be instantiated by a category name.
You can get the Revit Category class object by providing a name as follows:
category = revitron.Category('name').get()
Methods:
|
Init a new Category by name. |
|
Returns the category object. |
|
Returns the built-in category for a given category. |
The create
submodule and its Create
class contain helpful shorthand methods to create
Revit elements and families programatically. For example a centered room tag can be created as follows:
tag = revitron.Create.roomTag(self.element, self.getBboxCenter())
Note that some methods are also directly accessible in element classes such as Room
:
tag = _(room).tagCenter()
Classes:
|
A collection of shorthand methods to create Revit elements. |
Bases: object
A collection of shorthand methods to create Revit elements.
Methods:
|
Create a new linear grid line. |
|
Creates a new familiy document from a given template and saves it.add() |
|
Creates an extrusion within a given family document. |
|
Creates a new family instance. |
|
Creates a room tag for a given room element. |
|
Create a new 3D view. |
Create a new linear grid line.
start (object) – A Revit XYZ
element
end (object) – A Revit XYZ
element
name (string) – The grid name
A Revit grid element
object
Creates a new familiy document from a given template and saves it.add()
template (string) – The template name without the .rft
extension.
savePath (string) – The full path of the family file to be saved as.
A reference to the newly created family document.
object
Creates an extrusion within a given family document.
familyDoc (object) – A reference to a family document.
curveArrayArray (object) – A Revit API CurveArrArray
.
sketchPlane (object) – A Revit API SketchPlane
.
height (float, optional) – The extrusion height. Defaults to 10.0.
location (object, optional) – A Revit API XYZ
point object. Defaults to False.
isSolid (bool, optional) – Soild (True) or void (False). Defaults to True.
The extrusion element.
object
Creates a new family instance.
Example:
transaction = revitron.Transaction()
instance = revitron.Create.familyInstance(familySymbolId, location)
transaction.commit()
familySymbolId (object) – A Revit API family symbol ID.
location (object) – A Revit API XYZ
point.
structuralType (object, optional) – A Revit API structural type of False for NonStructural
. Defaults to False.
view (object, optional) – A Revit view, Defaults to None. Note that structuralType
and view
can not be used together.
The family instance.
object
Creates a room tag for a given room element.
room (object) – A Revit room element
location (object) – A Revit point object
typeId (ElementId, optional) – An optional Id of a tag type. Defaults to False.
viewId (ElementId, optional) – An optional Id of a view. Defaults to the currently active view.
The Revit RoomTag
element
object
The document
submodule contains classes to interact with the currently
active Revit document or store individual project configurations within a model.
Classes:
|
A basic wrapper class for Revit documents. |
The |
Bases: object
A basic wrapper class for Revit documents.
Basic examples are:
path = revitron.Document().getPath()
if revitron.Document().isFamily():
pass
In case you want to work with any other model than the active one, it is possible to change the context
to that model using the with
statement. Changing the context to another model will internally redefine
the revitron.DOC
property within the scope of that with
statement.
Therefore it is also possible to use a revitron.Filter
instance on any model by just using a filter within a
with
statement:
with revitron.Document(doc):
fltr = revitron.Filter().noTypes()
elements = fltr.getElements()
Methods:
Set |
|
|
Restore the original context. |
|
Inits a new Document instance. |
|
Returns a list of duplicate family instances. |
|
Returns a dictionary of all linked documents. |
|
Returns the path to the document. |
|
Checks whether the document is a family. |
|
Checks whether a document is open by passing its path. |
|
Synchronize the document. |
Set revitron.DOC
to the document of the current Document
class instance.
By default that will just be the active document and therefore revitron.DOC
stays unchanged.
Restore the original context.
execType (string) – The execution type
execValue (string) – The execution value
traceback (mixed) – The traceback
Inits a new Document instance.
doc (object, optional) – Any document instead of the active one. Defaults to None.
Returns a list of duplicate family instances. By default, the list contains always the younger more recently created duplicate instance.
Note
This method requires Revit 2018 or newer!
preferOlderElement (bool, optional) – Optionally return the list with the older instances. Defaults to False.
A list with duplicate instances, either the younger or the older ones.
list
Returns a dictionary of all linked documents. The key is the ID of the link and the value is the actual document object.
scope (mixed, optional) – List or view ID. Defaults to None.
A dictionary of all linked documents.
dict
Checks whether the document is a family.
True in case the document is a family
boolean
Bases: object
The DocumentConfigStorage
allows for easily storing project configuration items.
Getting configuration items:
config = revitron.DocumentConfigStorage().get('namespace.item')
The returned config
item can be a string, a number, a list or a dictionary.
It is also possible to define a default value in case the item is not defined in the storage:
from collections import defaultdict
config = revitron.DocumentConfigStorage().get('namespace.item', defaultdict())
Setting configuration items works as follows:
revitron.DocumentConfigStorage().set('namespace.item', value)
Methods:
|
Inits a new |
|
Returns storage entry for a given key. |
|
Updates or creates a config storage entry. |
Returns storage entry for a given key.
Example:
config = revitron.DocumentConfigStorage()
item = config.get('name')
key (string) – The key of the storage entry
default (mixed, optional) – An optional default value. Defaults to None.
The stored value
mixed
This submodule provides convenient wrappers for the interaction with elements.
Getting parameter values or other information can be quite complicated using the plain Revit API.
Methods like revitron.Element(element).get(parameter)
simplify that process.
Note
Note that there is also the _()
shortcut function available to be even more efficient
in getting properties of Revit elements. More here …
For example getting a parameter value or even a bounding box object works as follows:
form revitron import _
value = _(element).get('parameter')
boundingBox = _(element).getBbox()
Or setting parameter values:
_(element).set('parameter', value)
Classes:
|
A wrapper class for Revit elements. |
Bases: object
A wrapper class for Revit elements.
Example:
value = revitron.Element(element).get('parameter')
Or in short:
from revitron import _
value = _(element).get('parameter')
Methods:
|
Define default method to be returned on attribute errors. |
|
Inits a new element instance. |
|
Delete an element. |
|
Returns a parameter value. |
|
Returns a bounding box for the element. |
Returns the category name of the element. |
|
Returns the class name of the element. |
|
|
Returns a list of dependent elements. |
Returns the family name of the element. |
|
Returns the family name of the element. |
|
|
Returns a parameter value of the element type. |
Return the Revitron Geometry instance for this element. |
|
|
Returns a parameter object. |
|
Get possibly existing tags of an element. |
Checks whether an element is owned by another user. |
|
|
Checks whether an element is a type or not. |
|
Sets a parameter value. |
Attributes:
The actual Revit element. |
Define default method to be returned on attribute errors.
Since this is a generic element class that is extended by other more specialized classes such
as the Room
class, a default method along with an error message is returned when accidently
calling a special methods that only exists in one of the derived classes on an element of another class.
name (string) – The name of the called method
An empty method
method
Inits a new element instance.
element (object) – The Revit element or an element ID
The actual Revit element.
The Revit element object
object
Returns a parameter value.
Example:
value = _(element).get('name')
paramName (string) – The name of the parameter
The parameter value
mixed
Returns a bounding box for the element.
The bounding box or false on error
object
Returns the category name of the element.
The category name
string
Returns the class name of the element.
The class name
string
Returns a list of dependent elements.
filterClass (class, optional) – An optional class to filter the list of dependent elements by. Defaults to None.
The list with the dependent Revit elements.
list
Returns the family name of the element.
The family name
string
Returns the family name of the element.
The family name
string
Returns a parameter value of the element type.
Example:
value = _(element).getFromType('name')
paramName (string) – The name of the parameter
The parameter value
mixed
Return the Revitron Geometry instance for this element.
A Revitron Geometry object
object
Returns a parameter object.
paramName (string) – The name of the parameter
The parameter object
object
Get possibly existing tags of an element.
A list of Revit tag objects depending on the element class
list
Checks whether an element is owned by another user.
True if the element is not owned by another user.
boolean
Checks whether an element is a type or not.
True if element is a type.
bool
Sets a parameter value.
Example:
_(element).set('name', 'value', 'type')
Some possible parameter types are:
Text
Integer
Number
Length
Angle
Material
YesNo
MultilineText
FamilyType
You can find a list of all types here.
paramName (string) – The parameter name
value (mixed) – The value
paramType (string, optional) – The parameter type. Defaults to ‘Text’.
The element instance
object
This submodule contains helper classes to access and modify Microsoft Excel files. The following example demonstrates how to write data to table cells in a sheet created from a template:
book = revitron.ExcelWorkbook(xlsx)
sheet = book.newWorksheetFromTemplate('Template', 'Name')
sheet.setCell(5, 1, 'Value')
Classes:
|
A wrapper class for Excel workbooks. |
|
A wrapper class for modifying Excel worksheet cells. |
Bases: object
A wrapper class for Excel workbooks.
Methods:
|
Inits a new ExcelWorkbook instance. |
|
Closes and optionally saves a workbook file. |
|
Returns a Excel worksheet for a given name |
|
Creates a new worksheet as a copy from a given template. |
Inits a new ExcelWorkbook instance.
file (string) – The path to the xls file
Closes and optionally saves a workbook file.
save (bool, optional) – If True, the file is saved before closing. Defaults to True.
Bases: object
A wrapper class for modifying Excel worksheet cells.
Methods:
|
Inits a new ExcelWorksheet instance. |
|
Writes data to a cell of the current worksheet. |
The export
submodule hosts all classes related to sheet export such as DWG and PDF.
For example sending the currently active sheet to a PDF printer in the network works as follows:
exporter = revitron.PDFExporter(printerAddress, printerPath)
exporter.printSheet(revitron.ACTIVE_VIEW,
'A0',
'Landscape',
'C:/pdf',
'{Sheet Number}-{Sheet Title}')
Please check out the export tool of the Revitron UI extension to learn how to export a selection of sheets with a felxible configuration stored in a document.
Classes:
Export a schedule as CSV named by a file naming template. |
|
|
Export sheets as DWG named by a file naming template. |
|
Export sheets as PDF named by a file naming template. |
Bases: object
Export a schedule as CSV named by a file naming template.
Methods:
|
Inits a new CSVExporter instance. |
|
Exports a schedule. |
Exports a schedule.
schedule (object) – A Revit schedule
directory (string) – A custom output directory. Defaults to False.
template (string, optional) – A name template. Defaults to ‘{View Name}’.
delimiter (string, optional) – A csv delimiter. Defaults to ‘;’.
hasTitle (bool, optional) – Set True to export schedule title. Defaults to False.
The path of the exported CSV. False on error.
string
Bases: object
Export sheets as DWG named by a file naming template.
Methods:
|
Inits a new DWGExporter instance. |
|
Exports a sheet. |
Inits a new DWGExporter instance.
setupName (string) – The name of a stored export setup
Exports a sheet.
sheet (object) – A Revit sheet
directory (string) – The export directory
unit (object) – The export unit
template (string, optional) – A name template. Defaults to ‘{Sheet Number}-{Sheet Name}’.
The path of the exported PDF. False on error.
string
Bases: object
Export sheets as PDF named by a file naming template.
Methods:
|
Inits a new PDFExporter instance. |
|
Prints a sheet. |
|
Create a glob pattern to identify a printed PDF in the system output directory to be able to move it to its correct location and rename it according to the given template. |
Inits a new PDFExporter instance.
printer (string) – The printer network adress
output (string) – The printer output directory
Prints a sheet.
sheet (object) – A Revit sheet
size (string) – A size name like A0 or A4
orientation (string, optional) – The orientation, ‘Landscape’ or ‘Portrait’. Defaults to ‘Landscape’.
colorMode (string, optional) – The color setting for the printed sheets. Defaults to ‘Color’.
directory (string, optional) – A custom output directory. Defaults to False.
template (string, optional) – A name template. Defaults to ‘{Sheet Number}-{Sheet Name}’.
The path of the exported PDF. False on error.
string
Create a glob pattern to identify a printed PDF in the system output directory to be able to move it to its correct location and rename it according to the given template.
Please note that the PDF network printer has to be configured to save PDFs following the below naming scheme:
[Revit File] - Sheet - [Sheet Number] - [Sheet Name].pdf
For example:
Project1 - Sheet - A101 - Unnamed.pdf
sheet (object) – A Revit sheet objetc
The generated glob pattern
string
This submodule contains a wrapper class for external references within a Revit document.
Classes:
|
An external reference wrapper class. |
This is a helper submodule for handling errors and warnings occuring in transactions.
Classes:
|
This class implements the |
A basic failure handler. |
|
|
This class implements the |
|
This class implements the |
Bases: IFailuresPreprocessor
This class implements the IFailurePreprocessor
interface and can be used as a preprocessor
for rolling back on errors.
IFailuresPreprocessor (interface) – The Revit API IFailuresPreprocessor interface.
Methods:
|
Preprocess all failures and returns a ProceedWithRollBack result on error. |
Preprocess all failures and returns a ProceedWithRollBack result on error.
failuresAccessor (object) – The Revit API FailuresAccessor
object.
The FailureProcessingResult.ProceedWithRollBack
result on error or FailureProcessingResult.Continue
.
object
Bases: object
A basic failure handler.
Methods:
|
Preprocess failures by optionally suppressing all warnings and rolling back transactions on error. |
Preprocess failures by optionally suppressing all warnings and rolling back transactions on error.
failuresAccessor (object) – A Revit failure accessor object.
suppressWarnings (bool, optional) – Optionally suppress all warnings. Defaults to False.
rollbackOnError (bool, optional) – Optionally roll back on errors. Defaults to False.
A Revit FailureProcessingResult
object
Bases: IFailuresPreprocessor
This class implements the IFailurePreprocessor
interface and can be used as a preprocessor
for rolling back on errors and muting all warnings.
IFailuresPreprocessor (interface) – The Revit API IFailuresPreprocessor interface.
Methods:
|
Preprocess all failures and returns a ProceedWithRollBack result on error. |
Preprocess all failures and returns a ProceedWithRollBack result on error.
failuresAccessor (object) – The Revit API FailuresAccessor
object.
The FailureProcessingResult.ProceedWithRollBack
result on error or FailureProcessingResult.Continue
.
object
Bases: IFailuresPreprocessor
This class implements the IFailurePreprocessor
interface and can be used as a preprocessor
for muting all warnings.
IFailuresPreprocessor (interface) – The Revit API IFailuresPreprocessor interface.
Methods:
|
Preprocess all failures and deletes all warnings to suppress dialog boxes. |
The filter
submodule is one of the most essential one within the Revitron package.
Its main purpose is taking over the heavy lifting of filtering elements in the Revit database and
complementing the standard Revit API FilteredElementCollector
class with
the ability to filter collections by parameter values:
elements = (
revitron.Filter
.byStringEquals('param', 'value')
.noTypes()
.getElements()
)
Note that you can invert a filter by providing a the third argument for a string filter as follows:
elements = (
revitron.Filter
.byStringEquals('param', 'value', True)
.noTypes()
.getElements()
)
Note
In order to filter elements in another model instead of the active one, it is possible to change
the document context using the with
statement.
The document context can be changed as follows:
with revitron.Document(anyOtherDoc):
fltr = revitron.Filter().noTypes()
elements = fltr.getElements()
Classes:
|
A filter class based on the |
Bases: object
A filter class based on the FilteredElementCollector
class.
Methods:
|
Inits a new Filter instance. |
|
Filters the collection by a category name or a built-in category name. |
|
Filters the collection by class. |
|
Reduces the set of elements to the ones that are intersecting a given element. |
|
Filters the collection by parameter values equal to a given number. |
|
Filters the collection by parameter values greater than a given number. |
|
Filters the collection by parameter values greater than or equal to a given number. |
|
Filters the collection by parameter values smaller than a given number. |
|
Filters the collection by parameter values smaller than or equal to a given number. |
|
Filters the collection by testing whether a string contains at lease one ot the items in a CSV list. |
|
Filters a collection by a given regex. |
|
Filters the collection by a string at the beginning of a parameter value. |
|
Filters the collection by a string contained in a parameter. |
|
Filters the collection by testing whether a string contains at lease one ot the items in a CSV list. |
|
Filters the collection by a string at the end of a parameter. |
|
Filters the collection by a string that equals a parameter value. |
|
Filters the collection by testing whether a string equals at lease one ot the items in a CSV list. |
Get the collection as element IDs. |
|
Get the collection as elements. |
|
|
Removes all types from collection. |
Reduce to collection to types only. |
Inits a new Filter instance.
scope (Element ID or list of elements, optional) – The optional scope. It can be either a view Id or a list of elements. Defaults to None.
Filters the collection by a category name or a built-in category name.
Note that there are basically three valid types that can be used as the filter argument.
The first two use the name of a built-in category (with or without the OST_
prefix):
fltr = revitron.Filter().byCategory('Walls')
fltr = revitron.Filter().byCategory('OST_Walls')
The third type uses a natural
category name to find a corresponding built-in category to filter, here OST_BeamAnalyticalTags
:
fltr = revitron.Filter().byCategory('Analytical Beam Tags')
name (string) – A category or built-in category name
The Filter instance
object
Filters the collection by class.
Example:
fltr = revitron.Filter()
cls = Autodesk.Revit.DB.CurveElement
ids = fltr.byClass(cls).noTypes().getElementIds()
Alternatively it is also possible to use a class name as string instead:
fltr = revitron.Filter()
ids = fltr.byClass('CurveElement').noTypes().getElementIds()
cls (class) – A class or class name to filter the elements
The Filter instance
object
Reduces the set of elements to the ones that are intersecting a given element.
element (objetc) – A Revit element
The Filter instance
object
Filters the collection by parameter values equal to a given number.
Example:
fltr = revitron.Filter()
ids = fltr.byNumberIsEqual('Area', 5).noTypes().getElementIds()
paramName (string) – The parameter name
value (number) – The numeric value to compare to
invert (boolean) – Inverts the filter
The collector
object
Filters the collection by parameter values greater than a given number.
Example:
fltr = revitron.Filter()
ids = fltr.byNumberIsGreater('Area', 5).noTypes().getElementIds()
paramName (string) – The parameter name
value (number) – The numeric value to compare to
invert (boolean) – Inverts the filter
The collector
object
Filters the collection by parameter values greater than or equal to a given number.
Example:
fltr = revitron.Filter()
fltr = fltr.byNumberIsGreaterOrEqual('Area', 5).noTypes()
ids = fltr.getElementIds()
paramName (string) – The parameter name
value (number) – The numeric value to compare to
invert (boolean) – Inverts the filter
The collector
object
Filters the collection by parameter values smaller than a given number.
Example:
fltr = revitron.Filter()
ids = fltr.byNumberIsLess('Area', 5).noTypes().getElementIds()
paramName (string) – The parameter name
value (number) – The numeric value to compare to
invert (boolean) – Inverts the filter
The collector
object
Filters the collection by parameter values smaller than or equal to a given number.
Example:
fltr = revitron.Filter()
ids = fltr.byNumberIsLessOrEqual('Area', 5).noTypes().getElementIds()
paramName (string) – The parameter name
value (number) – The numeric value to compare to
invert (boolean) – Inverts the filter
The collector
object
Filters the collection by testing whether a string contains at lease one ot the items in a CSV list.
This method is the base method for the byStringContainsOneInCsv
and byStringEqualsOneInCsv
methods.
Note
that by setting invert
to True
, all elements that match one of the items will be
removed from the collection.
evaluatorName (method) – The filter method to be used to filter
paramName (string) – The name of the parameter
csv (string) – A comma separated list of items
invert (bool, optional) – Inverts the filter. Defaults to False.
The Filter instance
object
Filters a collection by a given regex.
paramName (string) – The name of the parameter to be matched.
regex (string) – The regex.
invert (bool, optional) – Inverts the filter. Defaults to False.
The Filter instance
object
Filters the collection by a string at the beginning of a parameter value.
Example:
fltr = revitron.Filter()
fltr = fltr.byStringBeginsWith('param', 'value').noTypes()
ids = fltr.getElementIds()
paramName (string) – The parameter name
value (string) – The searched string
invert (boolean) – Inverts the filter
The collector
object
Filters the collection by a string contained in a parameter.
Example:
fltr = revitron.Filter()
fltr = fltr.byStringContains('param', 'value').noTypes()
ids = fltr.getElementIds()
paramName (string) – The parameter name
value (string) – The searched string
invert (boolean) – Inverts the filter
The collector
object
Filters the collection by testing whether a string contains at lease one ot the items in a CSV list.
Note
that by setting invert
to True
, all elements that match one of the items will be
removed from the collection.
Example:
fltr = revitron.Filter()
fltr = fltr.byStringContainsOneInCsv('Family', 'some, words', False)
fltr = fltr.noTypes()
elements = fltr.getElements()
paramName (string) – The name of the parameter
csv (string) – A comma separated list of items
invert (bool, optional) – Inverts the filter. Defaults to False.
The Filter instance
object
Filters the collection by a string at the end of a parameter.
paramName (string) – The parameter name
value (string) – The searched string
invert (boolean) – Inverts the filter
The collector
object
Filters the collection by a string that equals a parameter value.
Example:
fltr = revitron.Filter()
ids = fltr.byStringEquals('param', 'value').noTypes().getElementIds()
paramName (string) – The parameter name
value (string) – The searched string
invert (boolean) – Inverts the filter
The collector
object
Filters the collection by testing whether a string equals at lease one ot the items in a CSV list.
Note
that by setting invert
to True
, all elements that match one of the items will be
removed from the collection.
Example:
fltr = revitron.Filter()
fltr = fltr.byStringEqualsOneInCsv('Family', 'some, words', False)
fltr = fltr.noTypes()
elements = fltr.getElements()
paramName (string) – The name of the parameter
csv (string) – A comma separated list of items
invert (bool, optional) – Inverts the filter. Defaults to False.
The Filter instance
object
Get the collection as element IDs.
The list of excluded element IDs
list
Get the collection as elements.
The list of excluded elements
list
The Geometry submodule and its Geometry
class contain useful helpers for handling
Revit element geometries. Note that it is possible to use the _()
shorthand to get
the geometry of an element as follows:
geometry = _(element).getGeometry()
The full syntax without using the shorthand can also be used:
geometry = revitron.Geometry(element)
Classes:
|
A collection of useful methods for handling Revit element geometries. |
The GeometryUtils class contains a collection of static utility methods for dealing with geometry related tasks. |
Bases: object
A collection of useful methods for handling Revit element geometries.
Methods:
|
Inits a new Geometry instance. |
|
Get a list of all curves by type of a given element. |
|
Get a list of all faces of a given element. |
Get a list of all solids of a given element. |
Inits a new Geometry instance.
element (object) – A Revit element
Get a list of all curves by type of a given element.
Note
Child classes of Autodesk.DB.Curve can be used.
curveType (str, optional) – The type of curve to return.
'Line'. (Defaults to) –
A list of curve objects
list
Bases: object
The GeometryUtils class contains a collection of static utility methods for dealing with geometry related tasks.
Methods:
|
Get the absolute angle between 0 and 360 degrees of a vector counter clockwise relative to the X-axis. |
|
Get the angle from a vector to a reference. |
|
Get a list of points from a given boundary that is usually returned by methods such as |
|
Check whether a given polygon that is planar to a horizontal surface contains a given point. |
Get the absolute angle between 0 and 360 degrees of a vector counter clockwise relative to the X-axis.
base (XYZ) – The base point that represents 0,0 of the coordinate system
endpoint (XYZ) – The endpoint of the line starting from the basepoint that represents the vector in question
The absolute angle between 0 and 360 degrees
float
Get the angle from a vector to a reference. Note that the result returns positiv as well as negative angles depending on the relative location of the reference vector.
base (XYZ) – The base point that represents 0,0 of the coordinate system
reference (XYZ) – The endpoint of the reference line starting from the basepoint
endpoint (XYZ) – The endpoint of the line starting from the basepoint that represents the vector in question
The angle
float
Get a list of points from a given boundary that is usually returned by
methods such as GetBoundarySegments
.
boundary (list) – A list of boundary segment lists
The list of points that define a boundary polygon
list
Check whether a given polygon that is planar to a horizontal surface contains a given point. Note that both, the polygon as well as the point must share common Z values.
The algorithm accumulates all angles (positive and negative) between neighboring lines that span from a given point to all vertices of the polygon. In case the accumulated absolute value equals 360, the point is located inside the polygon.
polygonPoints (list) – A list of points
point (XYZ) – The point that is tested
True, if the polygon contains the point
boolean
The Grid submodule contains all classes that are related to Revit grids. It helps you to quickly get filtered lists of grid lines or find closests intersections to given points in orthogonal grids.
Classes:
|
The |
|
In contrast to the |
|
An |
Bases: object
The Grid
class is the base class for other grid classes such as the OrthoGrid
class.
A grid object contains a collection of grid lines. That collection can be filtered when creating a grid instance.
The following example will create a grid object based on all grid lines with a type name that either contains “main” or “sub”:
grid = revitron.Grid('main, sub')
Alternatively you can create a OrthoGrid
object only including orthogonal grid lines:
ortho = revitron.OrthoGrid('main, sub')
Methods:
|
Creates a new |
Attributes:
The dict of grid lines contained in the |
Creates a new Grid
instance. A comma separated string can be passed as an argument to filter
the grid elements by their type name.
typeFilterCsv (string, optional) – A CSV filter. Defaults to False.
The dict of grid lines contained in the Grid
object where the grid line name serves as key.
A dict of Revit grid line elements where the grid name serves as key
dict
Bases: Grid
In contrast to the Grid
class, the OrthoGrid
object only contains grid lines that are orthogonal.
The following example will create a orthogonal grid object based on all grid lines with a type name that either contains “main” or “sub”:
grid = revitron.OrthoGrid('main, sub')
Methods:
|
Creates a new |
Find the grid intersection that is closest to a given point on the bottom right side. |
|
Find the grid intersection that is closest to a given point on the top left side. |
|
|
Create a new grid line that is defined by single X value and therefore is parallel to the Y axis. |
|
Create a new grid line that is defined by single Y value and therefore is parallel to the X axis. |
Attributes:
An object that contains one |
Creates a new Grid
instance. A comma separated string can be passed as an argument to filter
the grid elements by their type name.
typeFilterCsv (string, optional) – A CSV filter. Defaults to False.
Find the grid intersection that is closest to a given point on the bottom right side.
point (object) – A Revit XYZ
object
A OrthoGridIntersection
object
object
Find the grid intersection that is closest to a given point on the top left side.
point (object) – A Revit XYZ
object
A OrthoGridIntersection
object
object
An object that contains one X
and one Y
property, both dicts containing
grid line elements where the grid name serves as key.
The X
property contains all grid lines that are defined by a single value on the X axis
and the the Y
property contains all grid lines that are defined by a single value on the Y axis.
Note
Note that the lines of the X property are by definition always parallel to the Y axis since they are defined by a single X value and vice versa.
An object containing orthogonal grid elements split into X and Y lines
object
Create a new grid line that is defined by single X value and therefore is parallel to the Y axis.
Note
Note that the grid line created by this methods marks a position on the X axis that is represented by a line that is parallel to the Y axis.
X (float) – The position on the X axis
name (string) – The name of the new grid line
A Revit grid element
object
Create a new grid line that is defined by single Y value and therefore is parallel to the X axis.
Note
Note that the grid line created by this methods marks a position on the Y axis that is represented by a line that is parallel to the X axis.
Y (float) – The position on the Y axis
name (string) – The name of the new grid line
A Revit grid element
object
Bases: object
An OrthoGridIntersection
object contains all relevant information about an intersection
of two orthogonal grid lines.
Attributes:
The X coordinate of the intersection on plan. |
|
The Y coordinate of the intersection on plan. |
|
The Revit grid line element that is defined by a single value on the X axis and is parallel to the Y axis. |
|
The Revit grid line element that is defined by a single value on the Y axis and is parallel to the X axis. |
|
The name of the grid line element that is defined by a single value on the X axis. |
|
The name of the grid line element that is defined by a single value on the Y axis. |
Methods:
|
Create a new intersection object based on two orthogonal grid lines. |
The X coordinate of the intersection on plan.
The X coordinate
float
The Y coordinate of the intersection on plan.
The Y coordinate
float
Create a new intersection object based on two orthogonal grid lines.
gridX (object) – A Revit grid element
gridY (object) – A Revit grid element
The Revit grid line element that is defined by a single value on the X axis and is parallel to the Y axis.
A Revit grid element
object
The Revit grid line element that is defined by a single value on the Y axis and is parallel to the X axis.
A Revit grid element
object
The name of the grid line element that is defined by a single value on the X axis.
The name of the grid
string
The name of the grid line element that is defined by a single value on the Y axis.
The name of the grid
string
This submodule contains wrapper classes for links used in Revit models.
Classes:
|
A wrapper class for Revit links. |
Bases: Element
A wrapper class for Revit links.
Methods:
|
Define default method to be returned on attribute errors. |
|
Inits a new element instance. |
|
Delete an element. |
|
Returns a parameter value. |
|
Returns a bounding box for the element. |
Returns the category name of the element. |
|
Returns the class name of the element. |
|
|
Returns a list of dependent elements. |
Returns the family name of the element. |
|
Returns the family name of the element. |
|
|
Returns a parameter value of the element type. |
Return the Revitron Geometry instance for this element. |
|
|
Returns a parameter object. |
|
Gets the path of the linked document. |
|
Get possibly existing tags of an element. |
|
Gets the type object of the link. |
Checks whether an element is owned by another user. |
|
|
Checks whether an element is a type or not. |
|
Sets a parameter value. |
Attributes:
The actual Revit element. |
Define default method to be returned on attribute errors.
Since this is a generic element class that is extended by other more specialized classes such
as the Room
class, a default method along with an error message is returned when accidently
calling a special methods that only exists in one of the derived classes on an element of another class.
name (string) – The name of the called method
An empty method
method
Inits a new element instance.
element (object) – The Revit element or an element ID
Delete an element.
Example:
_(element).delete()
The actual Revit element.
The Revit element object
object
Returns a parameter value.
Example:
value = _(element).get('name')
paramName (string) – The name of the parameter
The parameter value
mixed
Returns a bounding box for the element.
The bounding box or false on error
object
Returns the category name of the element.
The category name
string
Returns the class name of the element.
The class name
string
Returns a list of dependent elements.
filterClass (class, optional) – An optional class to filter the list of dependent elements by. Defaults to None.
The list with the dependent Revit elements.
list
Returns the family name of the element.
The family name
string
Returns the family name of the element.
The family name
string
Returns a parameter value of the element type.
Example:
value = _(element).getFromType('name')
paramName (string) – The name of the parameter
The parameter value
mixed
Return the Revitron Geometry instance for this element.
A Revitron Geometry object
object
Returns a parameter object.
paramName (string) – The name of the parameter
The parameter object
object
Gets the path of the linked document.
The path on disk
string
Get possibly existing tags of an element.
A list of Revit tag objects depending on the element class
list
Checks whether an element is owned by another user.
True if the element is not owned by another user.
boolean
Checks whether an element is a type or not.
True if element is a type.
bool
Sets a parameter value.
Example:
_(element).set('name', 'value', 'type')
Some possible parameter types are:
Text
Integer
Number
Length
Angle
Material
YesNo
MultilineText
FamilyType
You can find a list of all types here.
paramName (string) – The parameter name
value (mixed) – The value
paramType (string, optional) – The parameter type. Defaults to ‘Text’.
The element instance
object
Besides the element
and the filter
submodules,
this submodule is one of the most elementary submodules of the Revitron package.
It contains all classes related to parameters, built-in parameters and value providers.
Classes:
A helper class for mapping lists of built-in parameter names to their representation visible to the user. |
|
|
A wrapper class for interacting with element parameters. |
A helper class for listing all parameter names in the active document. |
|
|
Create a string based on a parameter template where parameter names are wrapped in |
A collection of static parameter utilities. |
|
|
A wrapper for parameter value providers used for filtering elements. |
Bases: object
A helper class for mapping lists of built-in parameter names to their representation visible to the user.
Methods:
|
Inits a new BuiltInParameterNameMap instance. |
|
Return the list of matching built-in parameters for a given name. |
Bases: object
A wrapper class for interacting with element parameters.
Note
In most cases it is not required to actually create a Parameter class
instance in order to access paramter values of a given element.
The fastest way of getting or setting parameter values is using the _(element).get('parameter')
shortcut function or an instance of the revitron.element class.
Methods:
|
Init a new parameter instance. |
|
Checks if a parameter exists. |
|
Return the parameter value. |
Return the parameter value as double. |
|
Return the parameter value as ElementId. |
|
Return the parameter value as integer. |
|
Return the parameter value as string. |
|
Return the parameter value as value string. |
|
|
Checks if parameter has a value. |
|
Set a parameter value for an element. |
Attributes:
The definition parameter type. |
|
The displayed unit type of a parameter. |
Init a new parameter instance.
Getting a parameter by name visible to the user:
value = revitron.Parameter(element, 'parameterName').get()
Or the short version:
value = _(element).get('parameterName')
To be language independent it is possible to get a parameter value by its built-in parameter name like for example the view scale:
scale = _(view).get('VIEW_SCALE')
element (object) – Revit element
name (string) – The parameter name or the name of a built-Iin parameter
The definition parameter type.
The definition parameter type name
string
Return the parameter value.
Note
As mentioned above, the fastest way of getting a parameter value is to use the
get method
of the revitron.Element
class.
The value
mixed
Return the parameter value as ElementId.
The value
object
Return the parameter value as value string.
The value
string
Checks if parameter has a value.
True if the parameter has a value
boolean
Set a parameter value for an element. The parameter will be automatically created if not existing. The parameter type can be specified. If not type is given, it will be determined automatically in case of text, integer or float values.
Note
As mentioned above, the fastest way of setting a parameter value is to use the
set method
of the revitron.Element
class.
Example:
_(element).set('name', 'value', 'type')
Some possible parameter types are:
Text
Integer
Number
Length
Angle
Material
YesNo
MultilineText
FamilyType
You can find a list of all types here.
value (string) – The value
paramType (string, optional) – The parameter type
The displayed unit type of a parameter.
Note that since Revit 2021 the preferred return value is of type ForgeTypeId
.
The displayed unit type (ForgeTypeId or DisplayUnitType)
mixed
Bases: object
A helper class for listing all parameter names in the active document.
Methods:
|
Inits a new ParameterNameList instance including all parameter names in the document. |
|
Returns the parameter list. |
Bases: object
Create a string based on a parameter template where parameter names are wrapped in {...}
and get substituted with their value:
This sheet has the number {Sheet Number}
It is also possible to get parameter values from the project information instead by wrapping the parameter names
in {%...%}
instead:
This sheet of the project {%Project Name%} has the number {Sheet Number}
Methods:
|
Inits a new ParameterTemplate instance. |
|
The callback function used by the |
|
Returns the rendered template string. |
Inits a new ParameterTemplate instance.
element (object) – A Revit element
template (string) – A template string
sanitize (bool, optional) – Optionally sanitize the returned string. Defaults to True.
Bases: object
A collection of static parameter utilities.
Methods:
|
Bind a new parameter to a category. |
|
Create proper definition creation options based on a given name and type, that is passed as string. |
|
Get the parameter type as string from a definition. |
|
Get the storage type of a parameter definition by name. |
Bind a new parameter to a category.
category (string) – The built-in category
paramName (string) – The parameter name
paramType (string) –
The parameter type (see here) Defaults to “Text”.
typeBinding (bool) – Bind parameter to type instead of instance. Defaults to False.
Returns True on success and False on error.
boolean
Create proper definition creation options based on a given name and type, that is passed as string.
paramName (string) – The name of the parameter definition
paramType (string) – The name of the type
The ExternalDefinitionCreationOptions object
ExternalDefinitionCreationOptions
Bases: object
A wrapper for parameter value providers used for filtering elements.
Methods:
|
Inits a new ParameterValueProviders instance by name. |
|
Returns the list of value providers. |
Inits a new ParameterValueProviders instance by name. Such an instance consists of a list of value providers matching a parameters with a name visible to the user. Note that this list can have more than one value provider, since a parameter name possible matches multiple built-in parameters.
name (string) – Name
The raytrace submodule contains helper methods for easily raytracing intersections or similar.
Classes:
|
The Raytracer class. |
Bases: object
The Raytracer class.
Methods:
|
Inits a raytracer instance. |
|
Finds and returns an intersection point of a ray in a given direction based on an optional element filter. |
Inits a raytracer instance.
point (object) – A Revit XYZ object used as the base point for the raytracing.
view3D (object) – A Revit 3D view.
Finds and returns an intersection point of a ray in a given direction based on an optional element filter.
direction (object) – A Revit XYZ vector.
elementFilter (mixed, optional) – Either a list of Revit element IDs or a Revit ElementClassFilter. Defaults to None.
A Revit XYZ object or False on errors.
object
This submodule contains a wrapper classes for Revit room elements.
Classes:
|
A wrapper class for room elements. |
Bases: Element
A wrapper class for room elements.
Methods:
|
Define default method to be returned on attribute errors. |
|
Inits a new element instance. |
|
Delete an element. |
|
Returns a parameter value. |
|
Returns a bounding box for the element. |
|
Get the center point of a room's bounding box. |
Get the boundary of a given room. |
|
|
Get all points along an inset of the room boundary. |
Get all points along a room boundary. |
|
Returns the category name of the element. |
|
Returns the class name of the element. |
|
|
Returns a list of dependent elements. |
Returns the family name of the element. |
|
Returns the family name of the element. |
|
|
Returns a parameter value of the element type. |
Return the Revitron Geometry instance for this element. |
|
|
Returns a parameter object. |
|
Get the most bottom left point of a room boundary. |
|
Get the most bottom right point of a room boundary. |
|
Get the point on a room boundary that is the closest to a given point. |
|
Generates a point grid based on a given size within the room boundary. |
|
Get the most top left point of a room boundary. |
|
Get the most top right point of a room boundary. |
|
Get possibly existing tags of an element. |
Checks whether an element is owned by another user. |
|
|
Checks whether an element is a type or not. |
|
Sets a parameter value. |
|
Traces the room heights and returns an object containing the min/max bottom and min/max top points. |
Attributes:
The actual Revit element. |
Define default method to be returned on attribute errors.
Since this is a generic element class that is extended by other more specialized classes such
as the Room
class, a default method along with an error message is returned when accidently
calling a special methods that only exists in one of the derived classes on an element of another class.
name (string) – The name of the called method
An empty method
method
Inits a new element instance.
element (object) – The Revit element or an element ID
Delete an element.
Example:
_(element).delete()
The actual Revit element.
The Revit element object
object
Returns a parameter value.
Example:
value = _(element).get('name')
paramName (string) – The name of the parameter
The parameter value
mixed
Returns a bounding box for the element.
The bounding box or false on error
object
Get the center point of a room’s bounding box.
inRoomOnly (boolean) – Optionally only return a point in case the bounding box center is actually in the room
A Revit point object
object
Get the boundary of a given room.
A list of boundary segment curves
list
Get all points along an inset of the room boundary.
The inset is useful in cases where a point has to be used as a location for a tag and therefore should be located direktly on the boundary but a little bit more inside instead to avoid issues and warnings.
inset (float, optional) – The inset. Defaults to 0.1.
The list of points
list
Get all points along a room boundary.
A list of points
list
Returns the category name of the element.
The category name
string
Returns the class name of the element.
The class name
string
Returns a list of dependent elements.
filterClass (class, optional) – An optional class to filter the list of dependent elements by. Defaults to None.
The list with the dependent Revit elements.
list
Returns the family name of the element.
The family name
string
Returns the family name of the element.
The family name
string
Returns a parameter value of the element type.
Example:
value = _(element).getFromType('name')
paramName (string) – The name of the parameter
The parameter value
mixed
Return the Revitron Geometry instance for this element.
A Revitron Geometry object
object
Returns a parameter object.
paramName (string) – The name of the parameter
The parameter object
object
Get the most bottom left point of a room boundary.
inset (float, optional) – An optional room boundary inset. Defaults to 0.1.
A Revit XYZ object
object
Get the most bottom right point of a room boundary.
inset (float, optional) – An optional room boundary inset. Defaults to 0.1.
A Revit XYZ object
object
Get the point on a room boundary that is the closest to a given point.
point (object) – A Revit XYZ object
inset (float, optional) – An optional room boundary inset. Defaults to 0.1.
A Revit XYZ object
object
Generates a point grid based on a given size within the room boundary.
size (float, optional) – The maximum grid field size. Defaults to 5.00.
inset (float, optional) – The inset of the room boundary. Defaults to 0.05.
A list of Revit XYZ objects
list
Get the most top left point of a room boundary.
inset (float, optional) – An optional room boundary inset. Defaults to 0.1.
A Revit XYZ object
object
Get the most top right point of a room boundary.
inset (float, optional) – An optional room boundary inset. Defaults to 0.1.
A Revit XYZ object
object
Get possibly existing tags of an element.
A list of Revit tag objects depending on the element class
list
Checks whether an element is owned by another user.
True if the element is not owned by another user.
boolean
Checks whether an element is a type or not.
True if element is a type.
bool
Sets a parameter value.
Example:
_(element).set('name', 'value', 'type')
Some possible parameter types are:
Text
Integer
Number
Length
Angle
Material
YesNo
MultilineText
FamilyType
You can find a list of all types here.
paramName (string) – The parameter name
value (mixed) – The value
paramType (string, optional) – The parameter type. Defaults to ‘Text’.
The element instance
object
Traces the room heights and returns an object containing the min/max bottom and min/max top points.
view3D (object) – A Revit 3D view.
elementFilter (mixed, optional) – Either a list of Revit element IDs or a Revit ElementClassFilter. Defaults to None.
gridSize (float, optional) – The maximum grid field size for the raytracing. Defaults to 5.00.
inset (float, optional) – The inset of the room boundary. Defaults to 0.05.
Both properties are nested objects containing an Min and a Max value.
object
A simple helper module for creating room tags.
Classes:
|
This class contains methods to create room tags in given locations. |
Bases: object
This class contains methods to create room tags in given locations.
Methods:
|
Create a room tag in the bottom left corner. |
|
Create a room tag in the bottom right corner. |
|
Create a room tag in the bounding box center. |
|
Create a room tag in a given location. |
|
Create a room tag in the top left corner. |
|
Create a room tag in the top right corner. |
Create a room tag in the bottom left corner.
All existing room tags will be removed before automatically.
room (object) – A Revit room element.
tagTypeId (ElementId, optional) – A Revit element Id of a custom tag type. Defaults to False.
viewId (ElementId, optional) – A Revit element Id a view. Defaults to False.
A Revit RoomTag
element
object
Create a room tag in the bottom right corner.
All existing room tags will be removed before automatically.
room (object) – A Revit room element.
tagTypeId (ElementId, optional) – A Revit element Id of a custom tag type. Defaults to False.
viewId (ElementId, optional) – A Revit element Id a view. Defaults to False.
A Revit RoomTag
element
object
Create a room tag in the bounding box center.
All existing room tags will be removed before automatically.
room (object) – A Revit room element.
tagTypeId (ElementId, optional) – A Revit element Id of a custom tag type. Defaults to False.
viewId (ElementId, optional) – A Revit element Id a view. Defaults to False.
A Revit RoomTag
element
object
Create a room tag in a given location.
All existing room tags will be removed before automatically.
location (object) – A Revit location point object.
tagTypeId (ElementId, optional) – A Revit element Id of a custom tag type. Defaults to False.
viewId (ElementId, optional) – A Revit element Id a view. Defaults to False.
A Revit RoomTag
element
object
Create a room tag in the top left corner.
All existing room tags will be removed before automatically.
room (object) – A Revit room element.
tagTypeId (ElementId, optional) – A Revit element Id of a custom tag type. Defaults to False.
viewId (ElementId, optional) – A Revit element Id a view. Defaults to False.
A Revit RoomTag
element
object
Create a room tag in the top right corner.
All existing room tags will be removed before automatically.
room (object) – A Revit room element.
tagTypeId (ElementId, optional) – A Revit element Id of a custom tag type. Defaults to False.
viewId (ElementId, optional) – A Revit element Id a view. Defaults to False.
A Revit RoomTag
element
object
A small helper submodule to simplify accessing the list of selected elements.
Classes:
A selection helper class. |
Bases: object
A selection helper class.
Example:
for element in revitron.Selection.get():
...
Methods:
|
Get the first elements of the list of selected elements. |
|
Get the currently selected elements. |
|
Set the selection to a list of element ids. |
Get the first elements of the list of selected elements.
The first element in a list of selected elements
object
The transaction
submodule contains a wrapper class to simplify the usage of transactions,
transaction groups and subtransactions:
t = revitron.Transaction()
...
t.close()
Or alternatively you can also use the following syntax:
with revitron.Transaction():
...
A transaction group can be started using:
with revitron.TransactionGroup():
...
Classes:
The base class for Revitron transaction classes. |
|
|
A wrapper class for transactions and subtransactions. |
|
The transaction group wrapper. |
Bases: object
The base class for Revitron transaction classes. This class should not be used directly.
Methods:
Enter transaction context. |
|
|
Commit the transaction when leaving context. |
|
Init a basic transaction wrapper. |
|
Commits the open transaction. |
|
Rolls back the open transaction. |
Bases: BaseTransaction
A wrapper class for transactions and subtransactions. A subtransaction is started whenever there is already another active transaction in use. In case the transaction is not a subtransaction, it is possible to optionally suppress warnings and automatically roll back on errors.
Methods:
Enter transaction context. |
|
|
Commit the transaction when leaving context. |
|
Inits a new transaction. |
|
Commits the open transaction. |
|
Rolls back the open transaction. |
Enter transaction context.
Commit the transaction when leaving context.
Inits a new transaction.
doc (object, optional) – An optional document to be used instead of the currently active one. Defaults to None.
suppressWarnings (bool, optional) – Optionally suppress any warning messages displayed during the transaction. Not available in subtransactions. Defaults to False.
rollbackOnError – (bool, optional): Optionally roll back automatically on errors. Not available in subtransactions. Defaults to False.
Commits the open transaction.
Rolls back the open transaction.
Bases: BaseTransaction
The transaction group wrapper.
Methods:
Enter transaction context. |
|
|
Commit the transaction when leaving context. |
|
Init a new transaction group. |
Assimilates the open transaction group. |
|
|
Commits the open transaction. |
|
Rolls back the open transaction. |
Enter transaction context.
Init a new transaction group.
doc (bool, optional) – The document for the transaction. Defaults to False.
Commits the open transaction.
Rolls back the open transaction.
This submodule contains the TransmissionData
class
which allows for editing the paths of linked files without opening a model.
Classes:
|
A transmission data wrapper. |
Bases: object
A transmission data wrapper.
Methods:
|
Inits a new TransmissionData instance. |
List all links in the host document. |
|
|
Moves all external CAD and RVT links on disk and relinks them. |
|
Search and replace in all link paths of the document. |
|
Writes the TransmissionData back to the model. |
Inits a new TransmissionData instance.
hostPath (string) – The path of the host model
Moves all external CAD and RVT links on disk and relinks them.
source (string) – The source directory
target (string) – The target directory
The unit module and its Unit class provide little helper for handling units in Revit.
Classes:
|
The Unit class contains helpers for handling units. |
Bases: object
The Unit class contains helpers for handling units.
Methods:
|
Convert a given value from a given unit into Revit's internal unit. |
Convert a given value from a given unit into Revit’s internal unit.
value (mixed) – A number or string value. Strings are converted to floats automatically.
unit (object) – A Revit DisplayUnitType
or ForgeTypeId
object
The converted number
number
This submodule provides helpers related to Revit views.
Classes:
|
The ViewSheetList class creates a list of custom view objects based on a list of sheets. |
Bases: object
The ViewSheetList class creates a list of custom view objects based on a list of sheets.
Methods:
|
Inits an new ViewSheetList object. |
|
Returns the list of view objects. |
Inits an new ViewSheetList object.
sheets (list) – A list with sheets or sheet ids
Returns the list of view objects. The view objects have the following properties:
id: The ID of the view
sheet: The sheet object where the view is placed on
view: The actual view object
The returned list can be used as follows:
sheets = revitron.Filter().byCategory('Sheets').getElements()
for view in revitron.ViewSheetList(sheets).get():
print(view.id, view.sheet, view.view)
A list with view objects as described above
list
Revitron ships its own little wrapper for the pyRevit CLI that includes some additional features such as the ability to handle cloud models and to pass configuration files.
revitron [command] "path\to\config.json"
In order to be able to run the revitron
command from anywhere it has to be added
to your path environment variable.
You can do that manually or by running the following commands once:
cd path\to\revitron.lib
cli\setup
Revitron ships with two default commands.
Command |
Description |
---|---|
|
Creates analytical snapshots from models. More here. |
|
Compacts a model. The configuration JSON file only has to include model and revit fields. |
The configuration for the compact
command operating on cloud models looks as follows:
{
"model": {
"type": "cloud",
"projectGUID":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"modelGUID":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"region": "EMEA"
},
"revit": "2022"
}
Alternatively local models have a slightly different configuration:
{
"model": {
"type": "local",
"path": "C:\\path\\to\\model.rvt"
},
"revit": "2022"
}
The compacting can be started with the following command. Manually or as a command used in a task scheduler.
revitron compact "path\to\config.json"
Revitron supports custom commands as well to be used with the CLI. In order to be used as a command, a command has to meet the following requirements for its location and its content.
In order to be picked up as a valid command, a custom command file must have the .cli.py
extension
and be located somewhere subdirectory tree of the main extension directory of pyRevit. It is strongly recommended
to ship commands as Revitron packages that will be installed automatically in the correct location by the Revitron
package manager.
You can use one of the following example commands below in order to quickly get a custom command up and running:
import revitron
from cli import App, Config, getLogFromEnv
# Get the config dictionary from the JSON file.
config = Config().get()
# Get a log handle to use for logging.
log = getLogFromEnv().write
log('Hello')
# Open the model that is configured in the JSON file.
# Use App.open(True) in order to open and detach the file.
revitron.DOC = App.open(True)
# Implement your functionality here.
# Use the config dict in order to access your configuration stored
# in the JSON file that is passed as CLI argument.
revitron.DOC.Close(False)
In order to sync changes that have been applied by your command, you can use the following boiler plate that includes synching as well.
import revitron
from cli import App, Config, getLogFromEnv
config = Config().get()
log = getLogFromEnv().write
revitron.DOC = App.open(False)
# Implement your functionality here before synching ...
if revitron.Document().synchronize(compact=True, comment='Some comment'):
log('Synching finished successfully')
else:
log('Synching failed')
revitron.DOC.Close(False)
You can take a look at the included commands as simple but fully working examples for command files.
Revitron ships with a small CLI wrapper that uses the pyRevit CLI in the background in order to automatically collect model analytics using a task scheduler such as the Windows Task Scheduler. The CLI analyzer is configured using a JSON file that is passed as argument. The configuration includes the model path, storage configuration, the Revit version and the data providers.
revitron analyze "path\to\config.json"
Conceptually the revitron analyze config.json
command reads a JSON file, opens the configured Revit version,
opens the given model, creates data provider instances as configured and sends the extracted data to a storage driver.
Data providers are basically not more than a class that filters elements and aggregates a certain property or counts certain items in a model. Storage drivers are interfaces to data storage formats such as JSON, SQLite or a RESTful API. However, for the time being, only Directus is supported as RESTful API.
In order to be able to run the revitron command from anywhere it has to be added to your path environment variable. You can do that manually or by running the following commands once:
cd path\to\revitron.lib
cli\setup
As mentioned before, analytics jobs are configured using a JSON file. No coding is required at all. A basic configuration consits of four top fields:
Field |
Description |
---|---|
|
the Revit model path information |
|
the Revit version to be used to run the analytics |
|
the storage configuration for the extracted data snapshots |
|
the actual configuartion for the data the has to be tracked |
Note
You can find a set of example configuration in the official Github repository. Feel free to uses those configuration as template for your own projects.
A typical JSON file that can be used to create snapshots of a model’s accumulated room area looks as follows:
{
"model": {
"type": "cloud",
"projectGUID":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"modelGUID":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"region": "EMEA"
},
"storage": {
"driver": "Directus",
"config": {
"token": "YOUR_DIRECTUS_API_KEY",
"host": "http://domain.com/",
"collection": "Project Name"
}
},
"revit": "2022",
"providers": [
{
"name": "Room Area",
"class": "ElementAreaProvider",
"config": {
"filters": [
{
"rule": "byCategory",
"args": ["Rooms"]
},
{
"rule": "byStringContains",
"args": ["Name", "Room"]
}
]
}
}
]
}
The model path field contains information about where the source model is loaded from — local or cloud. Local models can be loaded by just providing a local file system path as demonstrated in the snippet below.
{
"model": {
"type": "local",
"path": "C:\\path\\to\\model.rvt"
}
}
Models that are stored in the BIM360 cloud require a bit more information, such as the project GUID, the model GUID and the region. You can use the Cloud → Cloud Model Info button in the Revitron UI in order to get the required GUIDs and the region information for the currently opened model.
{
"model": {
"type": "cloud",
"projectGUID":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"modelGUID":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"region": "EMEA"
}
}
The storage driver can be configured using the storage
field.
It field takes a single configuration object that provides the required data for Revitron to write or connect.
There are currently multiple options for storing the actual analytics snapshots — SQLite, JSON and Directus
In order to quickly get up and running and for testing the analytics configuration, the extracted snapshot data can be dumped into a JSON file.
{
"storage": {
"driver": "JSON",
"config": {
"file": "C:\\path\\to\\snapshots.json"
}
}
}
Alternatively to JSON files it is also possible to use SQLite databases as local storage.
{
"storage": {
"driver": "SQLite",
"config": {
"file": "C:\\path\\to\\snapshots.sqlite"
}
}
}
The recommended but by far more complex solution is to send the snapshots data to a Directus instance. Directus is data platform that can be used in the cloud or self-hosted, installed on a local server. The cloud version even provides a free plan. After creating your Directus instance, you will have to create an API key in order to give Revitron write access.
Note
Using Directus for snapshots storage also enables you to make use of automatically generated analytics dashboards.
{
"storage": {
"driver": "Directus",
"config": {
"token": "YOUR_DIRECTUS_API_KEY",
"host": "http://domain.com/url/to/directus",
"collection": "Project Name"
}
}
}
Note
Storing the token in plain text in your configuration might not be the best solution. Alternatively it is therefore possible to reference any environment variable instead:
{
"storage": {
"driver": "Directus",
"config": {
"token": "{{ ENV_VARIABLE }}",
"host": "http://domain.com/url/to/directus",
"collection": "Project Name"
}
}
}
So far we have configured where the data is taken from and where the snapshots are stored. Now we can define what kind of analytics we want to extract from the model. The data extraction is handled by Data Providers that define how and what data is aggregated and what set of elements is used for the calculation. Therefore a provider configuration consits of the following fields:
{
"providers": [
{
"name": "Room Area",
"class": "ElementAreaProvider",
"config": {
"filters": [
{
"rule": "byCategory",
"args": ["Rooms"]
},
{
"rule": "byStringContains",
"args": ["Name", "Room"]
}
]
}
}
]
}
Aside from the name
field, that has to be unique, the class
field and the config.filters
field are important here.
The classes field defines what provider type is used to calculate the extracted value. There are currently five different types of providers available.
The filters
field contains a list of filter objects that have two properties:
Name |
Description |
---|---|
|
The filter method that is used to filter a collection of elements. |
|
A list of arguments that is passed to the filter method. Take a look at the documentation for these methods in order get all available parameters. |
"filters": [
{
"rule": "byCategory",
"args": ["Rooms"]
},
{
"rule": "byStringContains",
"args": ["Name", "Room"]
}
]
Since we want the snapshots to be taken periodically, like on a daily basis,
we can configure the Windows Task Scheduler
to run the revitron
command, or a .bat
file containing multiple calls.
revitron analyze "C:\\path\\to\\config.json"
Analytics snapshots that are stored in Directus can automatically visualized in a web based dashboard using Revitron Charts.
The charts app can easily be deployed on a local webserver using Docker. A working Dockerfile is included in the repository. An installation guide can be found here. After a successfull deployment, there is no further setup needed. All analytically tracked projects are automatically added to the dashboard.
This is a collection of some useful little snippets and examples that can help you getting started quickly.
To make use of Revitron and the _() function the following items have to be imported:
import revitron
from revitron import _
The revitron
module also exposes some useful properties such as the active document and gives you access
to the Autodesk.Revit.DB
class as well as follows:
doc = revitron.DOC
db = revitron.DB
Getting all selected elements:
selection = revitron.Selection.get()
Getting the first element in the selection:
elements = revitron.Selection.first()
Printing the category and class names for of all selected elements:
for el in revitron.Selection.get():
name = _(el).getClassName()
cat = _(el).getCategoryName()
print(name, cat)
You can get a list of all dependent elements of a given element as follows:
dependents = _(el).getDependent()
For example the following loop prints the ElementIds
of all dependent elements of the selected elements:
for el in revitron.Selection.get():
for d in _(el).getDependent():
print(d.Id)
Getting a parameter value of all Revit elements in the selection:
for el in revitron.Selection.get():
name = _(el).get('Name')
print(name)
Getting the Family and Type
parameter as id
and string
of elements in the selection.
Note that here we want actually the value string instead of an ElementId
.
So the first function will return the ElementId
and the second one will give us the actual string.
for el in revitron.Selection.get():
famTypeId = _(el).get('Family and Type')
famType = _(el).getParameter('Family and Type').getValueString()
print(famTypeId)
print(famType)
Setting a parameter value. Note that a shared parameter will be created and bound to the element’s
category in case the parameter doesn’t exist yet. The el
variable contains a Revit element.
t = revitron.Transaction()
_(el).set('Cool Parameter', 'Hello there!')
t.commit()
By default the parameter type will be text
.
It is possible to pass a third argument to the function to set a parameter type:
t = revitron.Transaction()
_(el).set('Cool Integer Parameter', 10, 'Integer')
t.commit()
Getting all elements of a certain category, specified by a string, for example “Room”:
rooms = revitron.Filter().byCategory('Rooms').getElements()
for room in rooms:
print(_(room).get('Name'))
Instead of the natural category name, it is also valid to use the string representation of a built-in category as filter argument:
rooms = revitron.Filter().byCategory('OST_Rooms').getElements()
Note
A full list of natural category names and their corresponding built-in categories can be found here.
Filtering those rooms by filtering the Name
“beginning with the word Room” can be done as follows.
Note the flexible way of breaking down the filtering into multiple line for better readability:
fltr = revitron.Filter()
fltr = fltr.byCategory('Rooms')
fltr = fltr.byStringBeginsWith('Name', 'Room')
for room in fltr.getElements():
print(_(room).get('Name'))
The filter can be inverted to get only rooms with a Name
value “not beginning with Room”:
fltr = revitron.Filter()
fltr = fltr.byCategory('Rooms')
fltr = fltr.byStringBeginsWith('Name', 'Room', True)
for room in fltr.getElements():
print(_(room).get('Name'))
Getting intersecting elements of one selected element and for example printing their category name:
el = revitron.Selection.first()
for intEl in revitron.Filter().byIntersection(el).getElements():
print(_(intEl).getCategoryName())
Printing or getting the boundary points of one (first) selected room:
el = revitron.Selection.first()
points = _(el).getBoundaryPoints()
for p in points:
print(p)
Or with an inset:
el = revitron.Selection.first()
points = _(el).getBoundaryInsetPoints(0.2)
for p in points:
print(p)
Get list of all boundary segments of the first selected room:
el = revitron.Selection.first()
boundary = _(el).getBoundary()
for segment in boundary:
print(segment)
Getting the Revitron bounding box object of the first element in the selection:
el = revitron.Selection.first()
bbox = _(el).getBbox()
print(bbox)
In order to filter elements and using revitron.Filter
with any other model than the active one,
it is possible to temporarily change the document context as follows:
with revitron.Document(anyOtherDoc):
fltr = revitron.Filter().noTypes()
elements = fltr.getElements()
You can store any kind of easily serializable data such as string
, number
, list
or dict
in a config storage container as follows:
data = {'some': 'content'}
revitron.DocumentConfigStorage().set('my.namespace', data)
To get data out of that storage simply do the following. Note that you can pass a default value as a second argument to be returned in case there is no data stored yet and you don’t want to check for existence first:
config = revitron.DocumentConfigStorage().get('my.namespace', dict())
print(config.get('some'))