IFC Export using Document.Export not working

IFC Export using Document.Export not working

dirk.neethling
Advocate Advocate
2,997 Views
12 Replies
Message 1 of 13

IFC Export using Document.Export not working

dirk.neethling
Advocate
Advocate

I'm exporting a model using Document.Export(String, String, IFCExportOptions). It always exports an empty project, with the same filesize, regardless of which IFCExportOptions I set.

The alternative would be using IExporterIFC (https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/Revit-API/files/GUID-...). However, after referencing the dll, the compiler says that:

Error    120      The type or namespace name 'BIM' could not be found (are you missing a using directive or an assembly reference?)

No idea what to do.

 

Back to Document.Export: The result of the following code is an empty project, when reimporting into Revit 2017 (in order to verify):

 

                        IFCExportOptions IFCOptions = new IFCExportOptions();
                        IFCOptions.FileVersion = IFCVersion.IFC2x3;
                        IFCOptions.WallAndColumnSplitting = true;
                        IFCOptions.ExportBaseQuantities = true;
                        IFCOptions.FilterViewId = v.Id;
                        IFCOptions.AddOption("IFCVersion", "IFC 2x3 Coordination View 2.0");
                        IFCOptions.AddOption("ExportInternalRevitPropertySets", "true");
                        IFCOptions.AddOption("ExportAnnotations ", "true");
                        IFCOptions.AddOption("SpaceBoundaries ", "0");
                        IFCOptions.AddOption("VisibleElementsOfCurrentView ", "true");
                        IFCOptions.AddOption("Use2DRoomBoundaryForVolume ", "true");
                        IFCOptions.AddOption("UseFamilyAndTypeNameForReference ", "true");
                        IFCOptions.AddOption("ExportInternalRevitPropertySets ", "true");
                        IFCOptions.AddOption("ExportIFCCommonPropertySets", "true");
                        IFCOptions.AddOption("Exportuserdefinedpropertysets", "true");
                        IFCOptions.AddOption("Export2DElements", "false");
                        IFCOptions.AddOption("ExportPartsAsBuildingElements", "false");
                        IFCOptions.AddOption("ExportBoundingBox", "false");
                        IFCOptions.AddOption("ExportSolidModelRep", "true");
                        IFCOptions.AddOption("ExportSchedulesAsPsets", "false");
                        IFCOptions.AddOption("ExportLinkedFiles", "false");
                        IFCOptions.AddOption("IncludeSiteElevation", "true");
                        IFCOptions.AddOption("UseActiveViewGeometry", "false");
                        IFCOptions.AddOption("ExportSpecificSchedules", "false");
                        IFCOptions.AddOption("TessellationLevelOfDetail", "0.5");
                        IFCOptions.AddOption("StoreIFCGUID", "true");
                        IFCOptions.AddOption("ExportRoomsInView", "false");

                        //Export the model to IFC
                        doc.Export(TEMP, ifcname, IFCOptions);

 

Is there an example on the net of an IFC export which actually works? (not code snippets, files/features of mere interest, or tutorials which are irrelevant)

 

0 Likes
2,998 Views
12 Replies
Replies (12)
Message 2 of 13

jeremytammik
Autodesk
Autodesk

I implemented such a sample for you just now and added it to The Building Coder samples:

 

https://github.com/jeremytammik/the_building_coder_samples

 

I implemented a new external command CmdExportIfc for it:

 

https://github.com/jeremytammik/the_building_coder_samples/blob/master/BuildingCoder/BuildingCoder/C...

 

You can see the changes I made for that by comparing with the previous version: 

 

https://github.com/jeremytammik/the_building_coder_samples/compare/2019.0.142.1...2019.0.143.0

 

Here is the relevant code snippet:

 

  /// <summary>
  /// Export current view to IFC
  /// </summary>
  static Result ExportToIfc( Document doc )
  {
    Result r = Result.Failed;

    using( Transaction tx = new Transaction( doc ) )
    {
      tx.Start( "Export IFC" );

      string desktop_path = Environment.GetFolderPath(
        Environment.SpecialFolder.Desktop );

      IFCExportOptions opt = null;

      doc.Export( desktop_path, doc.Title, opt );

      tx.RollBack();

      r = Result.Succeeded;
    }
    return r;
  }

 

This is obviously following the KISS principle, which I always highly recommend doing:

 

https://en.wikipedia.org/wiki/KISS_principle

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 13

dirk.neethling
Advocate
Advocate

Thanks Jeremy,

I downloaded your latest BuildingCoder version and am giving this a try.

Dirk

0 Likes
Message 4 of 13

dirk.neethling
Advocate
Advocate

Hello Jeremy,

 

I got the same result, the ifc-file is empty. Even when I set the view to the 3D view, using the code below (which I think is from one of your blog pages), I get an empty file.

Dirk

 

    /// <summary>
    /// Retrieve a suitable 3D view from document.
    /// </summary>
    static View3D Get3dView(Document doc)
    {
        FilteredElementCollector collector
          = new FilteredElementCollector(doc)
            .OfClass(typeof(View3D));
        foreach (View3D v in collector)
        {
            Debug.Assert(null != v,
              "never expected a null view to be returned"
              + " from filtered element collector");
            // Skip view template here because view
            // templates are invisible in project
            // browser
            if (!v.IsTemplate)
            {
                return v;
            }
        }
        return null;
    }

0 Likes
Message 5 of 13

jeremytammik
Autodesk
Autodesk

Then you probably have some other, more serious, non-API problem.

 

Does the export work from the user interface?

 

If not, please discuss and resolve the issue in the product support forums first.

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 6 of 13

dirk.neethling
Advocate
Advocate

Yes, it works from the User Interface.  No problem there.

Regards, Dirk

0 Likes
Message 7 of 13

jeremytammik
Autodesk
Autodesk

Sounds weird. 

  

You might want to ask about this in the IFC open source project forum:

 

https://sourceforge.net/p/ifcexporter/discussion/general

 

Meanwhile, I also asked the development team on your behalf.

 

Cheers,

 

Jeremy

 

 

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 8 of 13

dirk.neethling
Advocate
Advocate

Hello Jeremy,

Thanks! As I mentioned before, I tried to get the custom export going, using [https://www.bim42.com/2017/09/using-the-revit-ifc-export-in-your-own-add-on/.]. However when I reference the IFCExportUI.dll, I get the compiler message:

Error    125    The type or namespace name 'BIM' could not be found (are you missing a using directive or an assembly reference?)   

 

Sample code:

                        //Create an instance of IFCExportOptions
                        IFCExportOptions IFCOptions = new IFCExportOptions();

                        //Get an instance of IFCExportConfiguration
                        BIM.IFC.Export.UI.IFCExportConfiguration selectedConfig = BIM.IFC.Export.UI.IFCExportConfiguration.CreateDefaultConfiguration();//.Configuration;

                        //Get the current view Id, or -1 if you want to export the entire model
                        ElementId activeViewId = v.Id;
                        selectedConfig.ActiveViewId = selectedConfig.UseActiveViewGeometry ? activeViewId.IntegerValue : -1;

                        //Update the IFCExportOptions
                        selectedConfig.UpdateOptions(IFCOptions, activeViewId);

                        string folder = "A path to a folder where you want to save your IFC file";
                        string name = "the name of your IFC file";

                        //Export the model to IFC
                        doc.Export(folder, name, IFCOptions);

 

Regards, Dirk

 

0 Likes
Message 9 of 13

jeremytammik
Autodesk
Autodesk

Dear Dirk,

  

The namespace BIM is not part of the Revit API:

 

http://www.revitapidocs.com/2018.1/d4648875-d41a-783b-d5f4-638df39ee413.htm

 

It comes from some third-party component that I am not aware of and have no knowledge about.

 

That is why I always recommend KISS:

 

https://en.wikipedia.org/wiki/KISS_principle

 

One important rule, always, for me at least: minimise dependencies and external components.

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 10 of 13

dirk.neethling
Advocate
Advocate

Why can I not reference the ExporterIFC class in my project:

http://www.revitapidocs.com/2018.1/c8697b81-e080-9202-14d3-ec883f951521.htm

 

Autodesk.Revit.DB.IFC.ExporterIFC  exp = null;

 

Error    125    The type or namespace name 'ExporterIFC' does not exist in the namespace 'Autodesk.Revit.DB.IFC' (are you missing an assembly reference?)  

0 Likes
Message 11 of 13

jeremytammik
Autodesk
Autodesk

You need to reference the Revit API .NET assembly DLLs.

 

They live in the same folder as Revit.exe.

 

OK, first question - is he trying to do a standard IFC export (that is, using the built-in exporter), or is he trying to test his custom exporter?

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 12 of 13

dirk.neethling
Advocate
Advocate

I tried using the standard IFC Exporter. Regardless of the Document content, it generates an .ifc file with the same size, with NO content.

Since that did not work, regardless of IFCExportOptions-setttings, I tried using the custom exporter (calles “IFC for Revit”), see [https://www.bim42.com/2017/09/using-the-revit-ifc-export-in-your-own-add-on/]. But I cannot reference the dll IFCExportUI.dll (which lives under C:\Program Files\Autodesk\Revit 2017\AddIns\IFCExporterUI on my machine), even though I can see it and it has the same name as the one mentioned in the article.

So at this point I am stuck: The standard IFC-Export does not work, and I cannot get the custom code to compile.

0 Likes
Message 13 of 13

Anonymous
Not applicable

May be problem is not in IFCExporter. Try to open generated IFC file and in 3D view properties change "display phase" (not sure, I'm using non english localization) to some else.

0 Likes