Recently, the author has been exploring methods to display lightweight Revit models on web pages. After extensive research, a feasible approach has been identified for sharing these models.
Before diving into the article, it is important to clarify that the conversion of RVT files to JSON format and their subsequent rendering using Three.js on web pages is either not fully implemented or only partially achieved. This results in incomplete data representation. Testing has revealed that the surface data extracted from the model is insufficient, and it remains uncertain whether the basic data interface provided by the Revit API is entirely reliable.
With that said, let’s proceed to the main content.
To convert a Revit model into a JSON file, the Revit API offers an interface called IExportContext. This is a custom export interface provided to users, allowing them to export desired data by implementing its methods. The approach is outlined as follows:

Based on the author’s research and related materials, this interface is used to facilitate data export. Below are some source code examples and JSON files utilized by the author, available for download for those interested.
Readers can also download these resources directly from the following link:
If you are able to quickly understand the linked code and encounter no issues during testing, you may skip the remaining content.
However, the author frequently encountered the following issue when testing code obtained online:
The given value is not a valid index of a normal of the polymesh. A valid value must be non-negative and less than the total number of normals in the polymesh.
In other words, the provided value is invalid for indexing the polymesh’s normal vector. Valid indices must be within bounds and cannot be negative.
After troubleshooting, the author identified that this exception originates from the PolymeshTopology.GetNormal(idx) method, particularly under certain conditions with PolymeshTopology.
Special thanks to the original author who raised concerns about potential flaws in the Revit API. The exact statement is shown below:

At present, exporting Revit models to JSON data is only achievable up to this stage. Readers with better solutions or questions are encouraged to leave comments and engage in discussion.
The author commits to sharing any future advancements promptly to benefit the community.













Must log in before commenting!
Sign Up