Class TLcdRevitModelDecoder
- All Implemented Interfaces:
ILcdModelDecoder,ILcdStatusSource
ILcdModel.
For more information on how this model decoder handles Revit files,
please consult The Revit data format article.
Input
| File | Required | Entry point | Description |
|---|---|---|---|
| *.rvt | x | x | A supported Revit file. |
| File | Required | Entry point | Description |
|---|---|---|---|
| *.rvt.index | x | x | A text file containing relative path names to Revit files (one file per line) that belong to the same project and that have the same reference. Refer to the Combining multiple Revit files article for more details. |
Supported transfer protocols
- This decoder only supports data from a file system.
Model reference
Revit files can contain geo-referencing information themselves, but that is not supported by this decoder. The coordinates read by this decoder are the Shared Coordinates. Specifying a model reference should be done with this coordinate system in mind. This section describes what strategies this decoder uses to find a suitable reference for the data.
-
The decoder obtains the model reference from an
ILcdModelReferenceDecoder, which decodes the reference from an additional model reference file placed next to the data file. The default reference decoder set on this model decoder is based on all model reference decoders annotated with theLcdServiceannotation. You can add a.prjfile with WKT information next to the input data, for example, or a.epgsfile with an EPSG code. -
Alternatively, you can use a
.llhfile next to the input data with a single text line containing a longitude, latitude and height coordinate (defined in the default EPSG 4326 reference). This will then be used as a topocentric reference to position your model in the world. -
You can set a fallback model reference to be used when no reference information can be found
next to the input data: see
setDefaultModelReference(com.luciad.model.ILcdModelReference).decoder.setDefaultModelReference(fallbackModelReference);
If no geo-reference information can be found with any of these strategies, then the data will be loaded in its
original, non-georeferenced coordinate system.
This is equivalent to setting a TLcdCartesianReference as fallback reference:
decoder.setDefaultModelReference(new TLcdCartesianReference(TLcdDistanceUnit.METRE_UNIT,
TLcdDistanceUnit.METRE_UNIT,
TLcdDistanceUnit.METRE_UNIT));
Note: Data that is decoded in its original coordinate system, cannot be visualized on a geographical map. The dataset must be geo-located with an external tool, after conversion has been done.
Model structure
This decoder can create 2 different kinds of models:
- The geometry model: this model contains the Revit geometry. The display name has the suffix "[GEOMETRY]".
- The features model: this model contains the properties of the Revit family types (like doors, walls, etc.),
together with their bounding box. This model is a
TLcd2DBoundsIndexedModel, its display name has the suffix "[FEATURES]".
To specify the model type, you must use a TLcdBIMDataSource with the appropriate Type
as input for the decodeSource(ILcdDataSource) and decodeModelMetadata(ILcdDataSource) methods.
The geometry type is assumed for the decode(String) and decodeModelMetadata(String) methods.
The possibility to decode 2 different models is also reflected through the discoverDataSources(java.lang.String) method:
it returns 2 ILcdDataSource instances, one for the geometry model and one for the features model, that
can both be decoded using the decodeSource(ILcdDataSource) method.
Model descriptor
The type name of the model descriptor is "Revit".Model elements
The objects in the model depend on the type of the model.
- The geometry model: this model contains elements that do not implement any public LuciadLightspeed
API. However, this model can be used as input for the
TLcdOGC3DTilesModelEncoder. - The features model: this model contains elements implementing the
ILcdDataObjectinterface. They are also annotated withTLcdHasGeometryAnnotationandTLcdPrimaryKeyAnnotationannotations so this model can for instance be used as input for theTLcdGeoJsonModelEncoderor other encoders supportingILcdDataObjects.These objects have the following properties:
FeatureID: a unique ID identifying the feature. This is a sequential number assigned to each feature, based on the order in which the features are processed during the decoding process. Its initial value is specified by theFeatureIDOffsetproperty of the root (see below).Name: a name for the feature. Can be null.Bounds: the 2D bounds of the feature.MinZ: the minimum height of the feature.MaxZ: the maximum height of the feature.Metadata: aMapwith uncategorized metadata.MetadataGroups: aMapwith metadata grouped per category.
The features in the model are organized hierarchically. Each feature can reference its parent features through an
AncestorPathproperty and its child features through aChildrenproperty. This structure allows you to navigate the feature hierarchy, representing relationships such as the arrangement of building parts within the dataset.AncestorPath: a list that represents the hierarchy from the root feature down to the current feature. Each element in the list is a FeatureID of an ancestor, ordered from the highest-level ancestor (the root feature) to the immediate parent of the current feature. The last element in the list is always the direct parent of the feature.Children: a collection of FeatureIDs pointing to the direct child features of the object.
The root features have two additional properties compared to the normal feature objects:
FeatureIDOffset: the offset that has been used for the featureIDs of its children. This value is non-zero when multiple input files have been combined into an.rvt.indexfile. The offset value can be used to determine the original identifier in the referenced dataset.SourceName: the source name of the dataset.
Sample code
Obtain the default model containing the geometry: ILcdModelDecoder decoder = new TLcdRevitModelDecoder();
ILcdModel model = decoder.decode(sourceName);
TLcdBIMDataSource:
ILcdModelDecoder decoder = new TLcdRevitModelDecoder();
ILcdModel model = decoder.decodeSource(new TLcdBIMDataSource(sourceName, TLcdBIMDataSource.Type.GEOMETRY));
TLcdBIMDataSource:
TLcdRevitModelDecoder decoder = new TLcdRevitModelDecoder();
ILcdModel model = decoder.decodeSource(new TLcdBIMDataSource(sourceName, TLcdBIMDataSource.Type.FEATURES));
Performance tips
If your dataset contains elements outside the area that you are interested in, this can cause problems when
converting the geometry to an OGC 3D Tiles dataset, affecting a client application that consumes the 3D Tiles.
To mitigate this problem, you can define a filter that retains only objects inside the area of interest. The
tutorial Filtering BIM data describes in depth
how you can do that.
Thread safety
- The decoding of models is thread-safe.
- The decoded models are thread-safe for read access.
Supported versions and specifications
This decoder supports Revit versions from 2011 up to 2025.
Known limitations
- Only Revit project files (.rvt) are supported. Revit template files (.rte) are not supported.
- The color of the elements depends on the selected
Model Display Styleof the default 3D view:- Realistic: the color is based on the
Appearance | Generic colorproperty of the material - Shaded: the color is based on the
Graphics | Shading colorproperty of the material
- Realistic: the color is based on the
Notes
- If not available, the decoder will try to create a binzx file next to the Revit file. This file contains a Binz dataset and additional metadata. It is used to improve the decoding time for future decode requests of the Revit file. If such a binzx file cannot be written (for instance because the directory of the Revit file is read-only), it is generated in a temp directory and deleted again when the model is returned.
- Decoding large Revit files can take a considerable amount of time.
- Since:
- 2024.0
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddStatusListener(ILcdStatusListener aListener) Registers the given listener so it will receive status events from this source.booleancanDecodeSource(ILcdDataSource aDataSource) Checks whether this model decoder can decode the data source(s), identified by the passedILcdDataSource.booleancanDecodeSource(String aSourceName) Checks whether this model decoder can decode the specified data source.Creates a new model from the given data source.decodeModelMetadata(ILcdDataSource aDataSource) Decodes metadata for the specified data source.decodeModelMetadata(String aSourceName) Decodes metadata for the specified data source.decodeSource(ILcdDataSource aDataSource) Creates a new model from the given data source.List<? extends ILcdDataSource> discoverDataSources(String aPath) Retrieves a set of model-specificILcdDataSourceinstances.Returns a short, displayable name for the format that is decoded by thisILcdModelDecoder.voidremoveStatusListener(ILcdStatusListener aListener) Removes the specified listener so it is no longer notified.voidsetDefaultModelReference(ILcdModelReference aModelReference) voidsetModelReferenceDecoder(ILcdModelReferenceDecoder aModelReferenceDecoder)
-
Field Details
-
TYPE_NAME
- See Also:
-
-
Constructor Details
-
TLcdRevitModelDecoder
public TLcdRevitModelDecoder()
-
-
Method Details
-
getDisplayName
Description copied from interface:ILcdModelDecoderReturns a short, displayable name for the format that is decoded by thisILcdModelDecoder.- Specified by:
getDisplayNamein interfaceILcdModelDecoder- Returns:
- the displayable name of this
ILcdModelDecoder.
-
setDefaultModelReference
-
getDefaultModelReference
-
getModelReferenceDecoder
-
setModelReferenceDecoder
-
discoverDataSources
Description copied from interface:ILcdModelDecoderRetrieves a set of model-specific
ILcdDataSourceinstances.By default, this method:
- returns a list containing at least a single
TLcdDataSourcethat contains a reference to the supplied path, whenILcdModelDecoder.canDecodeSource(String)returnstruefor the supplied path. - throws an
IOExceptionwhenILcdModelDecoder.canDecodeSource(String)returnsfalsefor the supplied path.
ILcdDataSource, for instance, if the path references a collection of data sources.An example where this is useful is for container formats, such as NetCDF. A NetCDF file can contain multiple measurement layers. This
ILcdModelDecoder.discoverDataSources(String)method allows you to distinguish between them usingILcdDataSources, where each measurement layer can be referenced to and decoded separately usingILcdModelDecoder.decodeSource(ILcdDataSource)- Specified by:
discoverDataSourcesin interfaceILcdModelDecoder- Parameters:
aPath- A path to the data source to be decoded; typically a file path or a URL.- Returns:
- If this model decoder returns
trueforILcdModelDecoder.canDecodeSource(String), it will return a list containing at least a singleILcdDataSource. - Throws:
IOException- If this model decoder returnsfalseforILcdModelDecoder.canDecodeSource(String)or if any exceptions caused by IO problems or invalid data occur.
- returns a list containing at least a single
-
canDecodeSource
Description copied from interface:ILcdModelDecoderChecks whether this model decoder can decode the specified data source. It is acceptable for this method to returntruefor a source name whiledecodethrows an exception for that same source name.For performance reasons, we strongly recommend that this will only be a simple test. For example: check the file extension of a file, but not that the file exists or contains expected content.
- Specified by:
canDecodeSourcein interfaceILcdModelDecoder- Parameters:
aSourceName- the data source to be verified; typically a file name or a URL.- Returns:
trueif this decoder can likely decode the data specified by the source name,falseotherwise.- See Also:
-
canDecodeSource
Description copied from interface:ILcdModelDecoderChecks whether this model decoder can decode the data source(s), identified by the passed
ILcdDataSource.For performance reasons, we strongly recommend that this will only be a simple test. For example: check the instance class of
aDataSource, or check the file extension if it is aTLcdDataSource.The default implementation of this method will check if the given
ILcdDataSourceis aTLcdDataSource. If not, this method returns false. Otherwise, it delegates the source to theILcdModelDecoder.canDecodeSource(String)method.- Specified by:
canDecodeSourcein interfaceILcdModelDecoder- Parameters:
aDataSource- theILcdModelSourceto be verified.- Returns:
trueif this decoder can likely decode the data specified byaDataSource,falseotherwise.- See Also:
-
decodeSource
Description copied from interface:ILcdModelDecoderCreates a new model from the given data source.
By default, this method:
- Throws a
NullPointerExceptionwhen anulldata source is passed. - Delegates to the
ILcdModelDecoder.decode(String)method when aTLcdDataSourceis passed. - Throws an IOException in other case.
- Specified by:
decodeSourcein interfaceILcdModelDecoder- Parameters:
aDataSource- theILcdDataSourceto be decoded.- Returns:
- a model containing the decoded data. While
nullis allowed, implementors are advised to throw an error instead. - Throws:
IOException- for any exceptions caused by IO problems or invalid data. Since decoding invalid data almost always results in RunTimeExceptions (NullPointerException, IndexOutOfBoundsException, IllegalArgumentException, ...) on unexpected places, implementations are advised to catch RuntimeExceptions in their decode() method, and wrap them into an IOException, as illustrated in the code snippet below.public ILcdModel decodeSource(ILcdDataSource aDataSource) throws IOException { try { // Perform decoding ... } catch (RuntimeException e) { throw new IOException(e); } }- See Also:
- Throws a
-
decodeModelMetadata
Description copied from interface:ILcdModelDecoderDecodes metadata for the specified data source. By default, this decodes the model and returns the model metadata found on that model. Implementations can override this method to speed up the retrieval.- Specified by:
decodeModelMetadatain interfaceILcdModelDecoder- Parameters:
aDataSource- the data source to be decoded.- Returns:
- the model metadata for the data source, never null.
- Throws:
IOException- if the metadata cannot be decoded for some reason.- See Also:
-
decodeModelMetadata
Description copied from interface:ILcdModelDecoderDecodes metadata for the specified data source. By default, this decodes the model and returns the model metadata found on that model. Implementations can override this method to speed up the retrieval.- Specified by:
decodeModelMetadatain interfaceILcdModelDecoder- Parameters:
aSourceName- the data source to be decoded; typically a file name or a URL.- Returns:
- the model metadata for the data source, never null.
- Throws:
IOException- if the metadata cannot be decoded for some reason.- See Also:
-
decode
Description copied from interface:ILcdModelDecoderCreates a new model from the given data source.- Specified by:
decodein interfaceILcdModelDecoder- Parameters:
aSourceName- the data source to be decoded; typically a file name or a URL.- Returns:
- A model containing the decoded data. While
nullis allowed, implementors are advised to throw an error instead. - Throws:
IOException- for any exceptions caused by IO problems or invalid data. Since decoding invalid data almost always results in RunTimeExceptions (NullPointerException, IndexOutOfBoundsException, IllegalArgumentException, ...) on unexpected places, implementations are advised to catch RuntimeExceptions in their decode() method, and wrap them into an IOException, as illustrated in the code snippet below.public ILcdModel decode( String aSourceName ) throws IOException { try (InputStream input = fInputStreamFactory.createInputStream(aSourceName)) { // Perform decoding ... } catch (RuntimeException e) { throw new IOException(e); } }- See Also:
-
addStatusListener
Description copied from interface:ILcdStatusSourceRegisters the given listener so it will receive status events from this source.
In case you need to register a listener which keeps a reference to an object with a shorter life-time than this status source, you can use a
ALcdWeakStatusListenerinstance as status listener.- Specified by:
addStatusListenerin interfaceILcdStatusSource- Parameters:
aListener- The listener to be notified when the status has changed.
-
removeStatusListener
Description copied from interface:ILcdStatusSourceRemoves the specified listener so it is no longer notified.- Specified by:
removeStatusListenerin interfaceILcdStatusSource- Parameters:
aListener- The listener to remove.
-