revitron.document

The document submodule contains classes to interact with the currently active Revit document or store individual project configurations within a model.

Classes:

Document([doc])

A basic wrapper class for Revit documents.

DocumentConfigStorage()

The DocumentConfigStorage allows for easily storing project configuration items.

class Document(doc=None)[source]

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:

__enter__()

Set revitron.DOC to the document of the current Document class instance.

__exit__(execType, execValue, traceback)

Restore the original context.

__init__([doc])

Inits a new Document instance.

getDuplicateInstances([preferOlderElement])

Returns a list of duplicate family instances.

getLinkedDocuments([scope])

Returns a dictionary of all linked documents.

getPath()

Returns the path to the document.

isFamily()

Checks whether the document is a family.

isOpen(path)

Checks whether a document is open by passing its path.

synchronize([compact, comment])

Synchronize the document.

__enter__()[source]

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.

__exit__(execType, execValue, traceback)[source]

Restore the original context.

Parameters
  • execType (string) – The execution type

  • execValue (string) – The execution value

  • traceback (mixed) – The traceback

__init__(doc=None)[source]

Inits a new Document instance.

Parameters

doc (object, optional) – Any document instead of the active one. Defaults to None.

getDuplicateInstances(preferOlderElement=False)[source]

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!

Parameters

preferOlderElement (bool, optional) – Optionally return the list with the older instances. Defaults to False.

Returns

A list with duplicate instances, either the younger or the older ones.

Return type

list

getLinkedDocuments(scope=None)[source]

Returns a dictionary of all linked documents. The key is the ID of the link and the value is the actual document object.

Parameters

scope (mixed, optional) – List or view ID. Defaults to None.

Returns

A dictionary of all linked documents.

Return type

dict

getPath()[source]

Returns the path to the document.

Returns

The path

Return type

string

isFamily()[source]

Checks whether the document is a family.

Returns

True in case the document is a family

Return type

boolean

static isOpen(path)[source]

Checks whether a document is open by passing its path.

Parameters

path (string) – The path

Returns

True in case the document is open

Return type

boolean

synchronize(compact=True, comment='')[source]

Synchronize the document.

Parameters
  • compact (bool, optional) – Compact while synchronizing. Defaults to True.

  • comment (str, optional) – A comment for the synch that shows up in the log. Defaults to ‘’.

Returns

True on success

Return type

boolean

class DocumentConfigStorage[source]

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:

__init__()

Inits a new DocumentConfigStorage object.

get(key[, default])

Returns storage entry for a given key.

set(key, data)

Updates or creates a config storage entry.

__init__()[source]

Inits a new DocumentConfigStorage object.

get(key, default=None)[source]

Returns storage entry for a given key.

Example:

config = revitron.DocumentConfigStorage()
item = config.get('name')
Parameters
  • key (string) – The key of the storage entry

  • default (mixed, optional) – An optional default value. Defaults to None.

Returns

The stored value

Return type

mixed

set(key, data)[source]

Updates or creates a config storage entry.

Example:

config = revitron.DocumentConfigStorage()
config.set('name', value)
Parameters
  • key (string) – The storage entry key

  • data (mixed) – The value of the entry