Obtain 3D Vertex Data from .rvt file in Python

Hi All,

I am not at all sure this is the right forum for this question but here goes. I have some .rvt files and .rcs files, and I want to extract 3D vertex data from each in Python. That is to say, I hope to get a list (or numpy array) of 3D positional attributes, each of which represents the position of a vertex in a .rvt / .rcs file.

What’s the best way to accomplish this goal? I’ve worked with various 3D file format converters in the past but Revit files are terra incognita. Any suggestions would be hugely helpful!

By vertex data do you mean the points of a given point cloud? I do not currently have access to Revit so I can’t test anything myself, but here’s a possible starting point:

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import FilteredElementCollector, PointCloudInstance

clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument

point_clouds = FilteredElementCollector(doc).OfClass(PointCloudInstance)

Past this, I don’t know exactly what to do. Each PointCloudInstance has a GetPoints() method which will return a PointCollection. You can then use the GetEnumerator() method of the PointCollection to retrieve an IEnumerable of CloudPoints. The CloudPoint structure contains a type conversion for an XYZ, from which you can retrieve its X, Y, and Z properties. Be aware that Dynamo uses IronPython which does not support numpy, but you can easily export a CSV file and open it in a standard CPython script.

2 Likes

@cgartland Amazing! This sounds promising!

I haven’t used any of these imports in the past: do you know how I can install them? I seem to be able to pip install clr but the installed module doesn’t have an AddReference method, so that clr must be different. If you can provide a little insight on how one can install these modules, I’d be super grateful!

Aha, this seems to be a little guide to getting going. I don’t yet have Revit so I think I’ll need to get as a first step: https://blog.productspec.net/2015/02/03/beginners-guide-to-python-in-autodesk-revit/

Yes, my above answer assumes that you are using a Python node within a Dynamo workspace (in Revit). clr is specific to IronPython–it looks like there is indeed a clr module for CPython but it is unrelated to the module of the same name in IronPython. You may want to have a look at pyRevit which appears to support standard CPython modules, so you may be able to do everything from a single script rather than exporting a CSV as I had previously suggested.

1 Like

@Ewan_Opie has some great nodes for working with point cloud data in the Sastrugi package.

Forum post here:

And website here:
https://sites.google.com/view/sastrugi/home

1 Like

Hi @douglas.duhaime

Can you post a hand-sketch of the intent of your workflow?
(I find they communicate requirements the best, as to be able to draw a picture you first have to know what you are trying to say :wink:)

Then I may be able to suggest a node combination that will assist.