Revit .NET C# add-in to validate that certain BIM element properties have not been modified
MIT License
Revit .NET C# add-in to validate that certain BIM element properties have not been modified.
Revit does not provide any functionality to ensure that parameter values are not modified.
The add-in stores a checksum for the original read-only values of selected parameters and implements a validation function to ensure that these intended values are not modified.
The validation process can be launched in various ways:
That said, please note the caveats on model checking and change analysis. However, they both report on modifications ater the fact. RvtLock3r using DMU goes one step further and prevents all forbidden modifications in the first place.
Lastly, it is impossible to prevent the user from corrupting models if they really try. A large level of trust and following best practices is required.
We have two actors:
To implement this protection, the vendor encodes the original property values in ground truth data.
The ground truth can be stored anywhere you like. We initially implemented it as an external text file, with the disadvantage that this can be manipulated or get lost. A better and safer solution would be to encode the ground truth in extensible storage.
We also have several options to ensure that the consumer has not modified any protected properties:
In any serious BIM environment, many rules and conventions are applied and required. Tools such as the Autodesk Model Checker ensure that these are strictly followed and can be relied upon. Maybe you should be using such a tool providing more coverage than RvtLock3r does?
BIM360 and ACC design collaboration provide a change visualization interface that enables you to find model differences by Model Properties API. It is based on the Forge Model Properties API. Another alternative approach to this task.
The customer add-in reads a set of ground truth data from some storage location. It contains a list of triples:
ElementId
BuiltInParameter
parameterId
or shared parameter GUID
The add-in iterates over all elements and parameters specified by these triples, reads the corresponding parameter value, calculates its checksum and validates it by comparison with the ground truth value.
Discrepancies are logged and a report is presented to the user.
The add-in does not care what kind of elements or parameters are being examined. That worry is left up to whoever creates the ground truth file.
In the initial proof of concept, the triples are simply space separated in individual lines in a text file.
There are various possible approaches to prepare the ground truth input text file, and they can be completely automated, more or less programmatically assisted, or fully manual.
In all three cases, the vendor must determine up front what elements and which of their parameters are to be checked. Retrieve the corresponding parameter values, compute their checksums, and save the above-mentioned triples.
The most generic approach might be the following:
Keep in mind that many documents may be open and each one has its own ground truth. So, we need to keep track of separate ground truth data for each open document.
The ground truth data triples containing the data required for integrity validation needs to be stored somewhere. That could be hard-wired directly into the add-in code for a specific BIM, stored in an external text file, within the RVT
document, or elsewhere; it may be JSON
formatted; it may be encrypted; still to be decided.
Two options are available for storing custom data directly within the RVT
project file: shared parameters and extensible storage.
The latter is more modern and explicitly tailored for use by applications and data that is not accessible to the end user or even Revit itself.
That seems most suitable for our purpose here.
Extensible storage can be added to any database element.
However, it interferes least with Revit operation when placed on a dedicated DataStorage
element,
especially in a worksharing environment.
Creation and population of a DataStorage
element is demonstrated by the named GUID storage for project identification sample.
Two obvious choices for storing the ground truth in extensible storage:
Entity
containing ground truth for each BIM Element
on thr Element
itself.DataStorage
element.References:
DataStorage
, not ProjectInfo
Currently, the add-in implements two commands: CmdGroundTruth
and Command
.
The former is only used once to initialise the ground truth data for a given model.
The latter can be used for testing purposes.
However, it may be replaced by an automated system to launch it on opening and saving a document.
Hence, there is no great need to implement a UI.
Otherwise, maybe, a ribbon tab with buttons to launch each command might be suitable.
CmdValidation
into a separate method that can beDocumentOpened
, DocumentSaving
, and DMUProposal:
.txt
DocumentClosing
eventWe can use the RevitPythonShell or RPS
to analyse the RVT
and export the element and parameter data of interest.
Maybe restrict to one single family, or only some types, or only some params, but that can come later.
Compute the checksum for each parameter value separately to enable reporting which element and which property has been modified, if any.
Optionally encrypt the entire file.
Use RPS only to export the list of parameters and values.
For each value, store:
Definition
ElementIdI would implement the checksum computation and later the optional encryption in C#, not Python.
The C# add-in skeleton already implements an external app + external command.
We can implement the command to read the text file listing element and parameter ids; for each pair, open the element and its parameter, determine the value (should match the text file) and calculate the checksum. Replace the parameter value in the txt file by its checksum. That becomes the ground truth file that is referenced later, containing just a list of three numbers for each property to check:
Definition
ElementIdThe final real-life command will read and decrypt the external ground truth file, run the code to calculate the current param value checksums, compare with the ground truth, log all discrepancies and report the result.
Once it works, we can trigger the validation command automatically via an event instead of manually via an external command, e.g., using the DocumentOpening and DocumentClosing events.
Carol Gitonga and Jeremy Tammik, The Building Coder, Forge Platform Development, ADN Open, Autodesk Inc.
This sample is licensed under the terms of the MIT License. Please see the LICENSE file for full details.