Exporting 3D Geometry (original) (raw)

January 24, 2022, 8:58pm 1

Can PyRevit be used to export 3D geometry?? :crossed_fingers:

Jean-Marc (Jean-Marc Couffin) January 25, 2022, 8:53am 2

The question should read:
Can Revit export to some kind of 3D formats?

Short answer: Yes

Longer answer: to IFC, SAT, FBX, … yes

a commented example from Data-shapes github repo to export to FBX, it is from a dynamo custom node in python https://github.com/MostafaElAyoubi/Data-shapes/blob/master/Nodes/Export%20to%20FBX.dyf

#Data-Shapes www.data-shapes.net`

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import*
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

t = Transaction(doc,'export')
t.Start() # could be handled differently with pyrevit module with Transaction('do something')

def tolist(input):
    if isinstance(input,list):
        return input
    else:
        return [input]

folder = IN[0] # to be change to grad the destination folder
prefix = IN[1] # no use in the code
views = tolist(IN[2]) # to be change to grad the list of views to export
result = []
vset = ViewSet()


for v in views: # meant to iterate on a list of views to be exported

    vset.Insert(UnwrapElement(v))
    result.append(doc.Export(folder,UnwrapElement(v).Name,vset,FBXExportOptions()))

t.Commit()
OUT = 'Success' # no use in pure python

or in C# from the building coder samples
pretty much the same structure

corybarr (Cory Barr) January 27, 2023, 9:06pm 3

When I use FBXExportOptions, I lose all materials. In an Autodesk forum, I got a response that these days more people use the CustomExporter. So presently I’m trying to find a minimal example of creating an FBX file with the CustomExporter. Does anyone know of one?

At present, CustomExporter is confusing me. It seems to assume that I by and large need to write the output file mesh by mesh. With the previous but apparently dated FBXExportOptions, it was very intuitive. Unity is much the same way:

public static void ExportGameObjects(Object[] objects)
{
    string filePath = Path.Combine(Application.dataPath, "MyGame.fbx");
    ModelExporter.ExportObjects(filePath, objects);
}

It seems like the Revit API is very low-level for these operations now, unless I’m missing something. Which is probable. I’m new to the Revit API, but not very new to graphics, file formats, etc.

radh-pmac (Patrick) April 24, 2025, 8:27pm 4

@corybarr How did you get on with this? Did you roll your own?