Export to OBJ format

I tried to use pyRevit to export model 3d view to obj and associated mtl file, I use: obj_options = OBJExportOptions() where I found available in Revit API since 2022

however, there is constantly this error:
Failed to export: The provided options are not valid.
Parameter name: options

Does anyone know whether pyRevit support OBJExportOptions()?

Hi Tony,

The issue makes sense up to a point, but not sharing any code does not :stuck_out_tongue:

pyRevit support the entire RevitAPI as it is just passing the Revit API calls made in python to Revit.

The way save or export options work is pretty much the same all the time:

  1. you declare the option set
  2. you add option to that set

Hi Jean-Marc,

Thank you very for the reply. Really appreciate you answer.

First I set the path

obj_file_path = 'C:/revit/objDir/3dModel.obj'

Then I define one function to set export option, using all default parameter values

def export_view_as_obj(doc, obj_file_path):
     obj_options = OBJExportOptions()
     doc.Export(os.path.dirname(obj_file_path), os.path.basename(obj_file_path), obj_options)

At last I called this function

uidoc = __revit__.ActiveUIDocument
doc = uidoc.Document
with Transaction(doc, "Create 3D View") as t:
      export_view_as_obj(doc, obj_file_path)

But I keep getting this error from pyRevit: Failed to export: The provided options are not valid.
Parameter name: options

Exporting to fbx works fine

Let’s go from the top of the pyramid:

  1. The Export method is part of the Document Class Export Method
    It takes 3 arguments: folder path where you want to save you export, name of you export, export options

  2. our mistake was here: The export options takes at a minimum, one argument, the view id of the view the geometry is exported from.

from pyrevit import forms, revit, DB, script

output = script.get_output()

view = revit.active_view
doc = revit.doc

# set export options

eo = DB.OBJExportOptions()

# set the view to export
eo.ViewId = view.Id

# set the output folder path
output_folder_path = __file__.rsplit("\\", 1)[0]

# export the geometry
doc.Export(output_folder_path, "output.obj", eo)

It does not require a transaction as you are not doing anything to the revit DB, you are just collecting and saving stuffs outside revit

you will need to learn how to read the error message / traceback that pyRevit gives you. They are usually pretty self-explanatory if you take the time to read them.
When I try the code above without setting the view Id, I got:

IronPython Traceback:
Traceback (most recent call last):
File "C:\pyRevit\B1_ToolBar.extension\Outils BIM One.tab\Z_PROTOTYPING.panel\Tests.pulldown\z.pushbutton\script.py", line 18, in <module>
Exception: The provided options do not specify a printable 3D view.
Parameter name: options