CLIifc export does not output ifc file

Hello pyrevit community,

I need a simple script that takes rvt file and exports it in ifc format. First I tested this example code. Then I used the code from this thread as a basis for the export, calling HOST_APP.uiapp.OpenAndActivateDocument(models[0]) to open the file in CLI.

Here is the current iteration of my code:

from pyrevit import HOST_APP, DB, coreutils, revit
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *
import os

def export_ifc():
    logger = coreutils.logger.get_logger("test")
    logger.dev_log("Exporting IFC")
    folder_path = os.path.dirname(__file__)
    
    uidoc = HOST_APP.uiapp.OpenAndActivateDocument(__models__[0])
    doc = DB.Document(uidoc.Document)
    t = Transaction(doc,"IfcExport")
    t.Start()
    options = IFCExportOptions()
    options.FileVersion = IFCVersion.IFC2x3
    options.WallAndColumnSplitting = False
    options.AddOption("Export2DElements", "false")
    options.AddOption("ExportRoomsInView", "false")
    options.AddOption("VisibleElementsOfCurrentView ", "true")
    options.AddOption("ExportLinkedFiles", "false")
    options.ExportBaseQuantities = True
    options.AddOption("ExportInternalRevitPropertySets", "true")
    options.AddOption("ExportIFCCommonPropertySets", "true")
    options.AddOption("ExportSchedulesAsPsets", "false")
    options.AddOption("ExportSpecificSchedules", "false")
    options.AddOption("ExportUserDefinedPsets", "false")
    options.AddOption("Use2DRoomBoundaryForVolume ", "false")
    options.AddOption("UseFamilyAndTypeNameForReference ", "false")
    options.AddOption("ExportPartsAsBuildingElements", "false")
    options.AddOption("ExportBoundingBox", "false")
    options.AddOption("ExportSolidModelRep", "true")
    options.AddOption("StoreIFCGUID", "true")
    options.AddOption("UseActiveViewGeometry", "true")
    options.AddOption("IncludeSiteElevation", "true")
    options.AddOption("ExportAnnotations ", "true")

    options.AddOption("TessellationLevelOfDetail", "0,5")
    options.AddOption("IFCFileType", "0")
    doc.Export(folder_path, "output.ifc", options)

    t.Commit()
    t.Dispose()
        

# Run the export function
export_ifc()

This code did not produce errors or the result ifc file to the script folder when ran with the following command:

pyrevit run “<script_path>” “<file_path>” --revit=24.3.10.22

I tried to search the documentation and the forums for a solution, but was unable to diagnose the problem. The file was created with revit 2021.

1 Like