revitron.document¶
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 |
- 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 therevitron.DOC
property within the scope of thatwith
statement. Therefore it is also possible to use arevitron.Filter
instance on any model by just using a filter within awith
statement:with revitron.Document(doc): fltr = revitron.Filter().noTypes() elements = fltr.getElements()
Methods:
Set
revitron.DOC
to the document of the currentDocument
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 currentDocument
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
- isFamily()[source]¶
Checks whether the document is a family.
- Returns
True in case the document is a family
- 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.
- 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