Autodesk / revit-ifc

IFC for Revit and Navisworks (2019+)
486 stars 196 forks source link

Access to IFC Export Configurations #540

Open josols opened 2 years ago

josols commented 2 years ago

We have an issue where we programmatically want to select a custom export config saved in a Revit file. It does not work as intended because the enumerator only contains the standard configs after opening the Revit file, UNTIL you actually open the IFC Export dialog box in Revit. Then afterwards it is accessible . This is a hindrance for mass exporting IFC files through Dynamo/Python/Revit Batch processor etc. Bug? I've used the AddSavedConfigurations() method, but it doesn't seem to work until I've actually opened the Export UI.

sanderobdeijn commented 1 month ago

I have the same issue, there is a workaround suggested in #93 that seems to work for me. But this relies on setting the active revitdocument in a private method through reflection.

internal static void InitializeDocument(Document document)
{
     typeof(IFCCommandOverrideApplication).GetProperty("TheDocument",
        BindingFlags.Static | BindingFlags.Public).SetValue(null, document);
}

This is a workaround but this does not seems like a sustainable solution long term. IFCCommandOverrideApplication.TheDocument is being used as a global parameter that is set in the UI logic of IFCCommandOverrideApplication but isn't set when methods are directly called from other addins.

We could move TheDocument to a non UI class and require other addin's to also set this property before calling other methods, but this still seams like an architectural anti-pattern to me.

A better solution would be to refactor all methods that currently use TheDocument to require a document in their method api or class constructor. So these methods are no longer dependent on state set in other classes.