IFC Export fails

IFC Export fails

ivo.lafeber
Enthusiast Enthusiast
234 Views
2 Replies
Message 1 of 3

IFC Export fails

ivo.lafeber
Enthusiast
Enthusiast

This is a piece of IFC exporter I use, it used to work, but if we want to export an IFC, the file is or empty or some (only few) of the element's of the 3D view are exported.

 

When we use the same json with the normal export button in revit it works, but with this code it sometimes works but most of the time not. 

When it works in a model, it keeps working in that model, but when it's not working in a model, it's not exporting. so it's a consistant 'bug'.

 

What can I try to solve this ? 

 

 

  Using tx As New Transaction(doc)
      tx.Start("IFC")

      If System.IO.Directory.Exists(IFC_Pad) = False Then System.IO.Directory.CreateDirectory(IFC_Pad)

      ' select ifc file 
      Dim IFCInstance As New IFC
      Dim configfile As String = Json_Filename
      If configfile.Length = 0 Then
          configfile = IFCInstance.Get_Ifc_Settings_Filename()
      End If

      If configfile.Length = 0 Then Return 0

      Dim ifcconfig As New IfcExportSettings(configfile)
      Dim ifcoptions As New IFCExportOptions

      Dim threedv As View3D

      For Each id As ElementId In Viewlist
          Dim el As Element = doc.GetElement(id)
          threedv = TryCast(el, View3D)

          If Not threedv Is Nothing Then
              ifcoptions.FilterViewId = id
              ifcoptions.ExportBaseQuantities = ifcconfig.ExportBaseQuantities
              ifcoptions.SpaceBoundaryLevel = ifcconfig.SpaceBoundaries
              ifcoptions.WallAndColumnSplitting = ifcconfig.SplitWallsAndColumns
              ifcoptions.FileVersion = ifcconfig.IFC_Version

              For Each item In ifcconfig.Settings_Overig
                  ifcoptions.AddOption(item.Name, item.Value)
              Next

              Dim selectedconfig As BIM.IFC.Export.UI.IFCExportConfiguration = BIM.IFC.Export.UI.IFCExportConfiguration.CreateDefaultConfiguration
              selectedconfig.VisibleElementsOfCurrentView = False
              selectedconfig.UpdateOptions(ifcoptions, threedv.Id)

              Try
                  doc.Export(IFC_Pad, threedv.Name, ifcoptions)
              Catch
                  Debug.Print(Err.Description)
              End Try
              cnt_Exported_Views += 1

          End If
      Next
      tx.Commit()
  End Using
0 Likes
235 Views
2 Replies
Replies (2)
Message 2 of 3

jeremy_tammik
Alumni
Alumni

I do not know what IFC might be in this context. Is that a class? It is not part of the Revit API, is it? Is it defined by the Revit IFC open source project? If so, you may have better luck discussing this in the IFC discussion forum:

  

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 3

ivo.lafeber
Enthusiast
Enthusiast

This is the full class, it's not defined by the open source project. 

I only use the the autodesk dll 

"C:\Program Files\Autodesk\Revit 2023\AddIns\IFCExporterUI\Autodesk.IFC.Export.UI.dll"

Public Class IFC

    Const IFC_Pad As String = "c:\ifc\"

    Public Shared Function Export_IFC(ByVal doc As Document, Viewlist As List(Of ElementId), ByVal Json_Filename As String) As Integer

        Dim cnt_Exported_Views As Integer = 0

        Using tx As New Transaction(doc)
            tx.Start("Kropman_IFC")

           
            If System.IO.Directory.Exists(IFC_Pad) = False Then System.IO.Directory.CreateDirectory(IFC_Pad)

            ' select ifc file 
            Dim IFCInstance As New IFC
            Dim configfile As String = Json_Filename
            If configfile.Length = 0 Then
                configfile = IFCInstance.Get_Ifc_Settings_Filename()
            End If

            If configfile.Length = 0 Then Return 0

            Dim ifcconfig As New IfcExportSettings(configfile)
            Dim ifcoptions As New IFCExportOptions

            Dim threedv As View3D

            For Each id As ElementId In Viewlist
                Dim el As Element = doc.GetElement(id)
                threedv = TryCast(el, View3D)

                If Not threedv Is Nothing Then

                    ifcoptions.FilterViewId = id
                    ifcoptions.ExportBaseQuantities = ifcconfig.ExportBaseQuantities
                    ifcoptions.SpaceBoundaryLevel = ifcconfig.SpaceBoundaries
                    ifcoptions.WallAndColumnSplitting = ifcconfig.SplitWallsAndColumns
                    ifcoptions.FileVersion = ifcconfig.IFC_Version

                    For Each item In ifcconfig.Settings_Overig
                        ifcoptions.AddOption(item.Name, item.Value)
                    Next

                    Dim selectedconfig As BIM.IFC.Export.UI.IFCExportConfiguration = BIM.IFC.Export.UI.IFCExportConfiguration.CreateDefaultConfiguration
                    selectedconfig.VisibleElementsOfCurrentView = True
                    selectedconfig.UpdateOptions(ifcoptions, threedv.Id)

                    doc.Export(IFC_Pad, threedv.Name, ifcoptions)

                    cnt_Exported_Views += 1

                End If
            Next
            tx.Commit()
        End Using

        
        Return cnt_Exported_Views

    End Function


    Private Function Get_Ifc_Settings_Filename() As String

        Dim fd As System.Windows.Forms.OpenFileDialog = New System.Windows.Forms.OpenFileDialog()
        Dim strFileName As String = ""

        fd.Title = "Select Ifc Config File (Json)"
        fd.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments

        fd.Filter = "All files (*.*)|*.*|Json files (*.Json)|*.Json"
        fd.FilterIndex = 2
        fd.RestoreDirectory = True

        If fd.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
            strFileName = fd.FileName
        End If
        Return strFileName

    End Function



End Class

 

0 Likes