Support Forum

[Frage] IFC import/export doesn't work ? [Gelöst]

Schlagworte:
  • IFC
  • Import
  • Export
  • PythonAPI
  • PythonParts
  • Script

Update I could make the IFC export work but still no sucess with import,

Hi,
I'm trying to write a python script to automate IFC import and export tasks, but I can't quite make it work.

I checked the ExportImportInteractor example where there supposed to be example for these kind of processes, and the DWG import and export works perfectly, but there is no example for ifc import, and the IFC export doesn't generate any output, nor any error message.

This is the code that I'm trying to run for export:

def ExportIFC(exportPath):
    drawingFileService = AllplanBaseElements.DrawingFileService()
    activeFileIndex = AllplanBaseElements.DrawingFileService.GetActiveFileNumber()
    doc =  AllplanIFW.InputViewDocumentData().GetInputViewDocument()
    ifcVersion = AllplanBaseElements.Ifc_4
    drawingFileService.ExportIFC(doc, [activeFileIndex], ifcVersion, exportPath)

and this is the import
def ImportIFC (importPath ):
    drawingFileService = AllplanBaseElements.DrawingFileService()
    doc = AllplanIFW.InputViewDocumentData().GetInputViewDocument()
    activeFileIndex = AllplanBaseElements.DrawingFileService.GetActiveFileNumber()
    drawingFileService.UnloadAll(doc)
    drawingFileService.LoadFile(doc, activeFileIndex, AllplanBaseElements.DrawingFileLoadState.ActiveForeground)
    ifcVersion = AllplanBaseElements.Ifc_4
    drawingFileService.ImportIFC(doc,ifcVersion, importPath)

Did I miss a step somewhere in the code?
Is there any prerequisites for the ExportImportInteractor to work with IFC ?

Lösung anzeigen Lösung verbergen

Hello!
I don't see any issues in your code for exporting the file. In fact I've used your code and it worked just fine on my computer.

For the import however the argument for ifcVersion should be given as an integer. See the documentation

ImportIFC( (DrawingFileService)doc, (DocumentAdapter)fileIndex, (int)ifcVersion, (wstring)fileName) -> BaseElementAdapterList

On the other hand the documentation is very confusing here. The second argument fileIndex is actually where the document adapter should be given. And I also don't understand, why the IfcVersion has to be given as integer, as in the IFCExport it is given as an instance of a IfcVersion class. And what is the sense of giving an IfcVersion to an import function in the first place. Seems we need to work on that. But for the moment please find the examples for IFC import and export attached.

Anhänge (2)

Typ: text/xml
625-mal heruntergeladen
Größe: 2,50 KiB
Typ: text/plain
675-mal heruntergeladen
Größe: 6,43 KiB

Hello!
I don't see any issues in your code for exporting the file. In fact I've used your code and it worked just fine on my computer.

For the import however the argument for ifcVersion should be given as an integer. See the documentation

ImportIFC( (DrawingFileService)doc, (DocumentAdapter)fileIndex, (int)ifcVersion, (wstring)fileName) -> BaseElementAdapterList

On the other hand the documentation is very confusing here. The second argument fileIndex is actually where the document adapter should be given. And I also don't understand, why the IfcVersion has to be given as integer, as in the IFCExport it is given as an instance of a IfcVersion class. And what is the sense of giving an IfcVersion to an import function in the first place. Seems we need to work on that. But for the moment please find the examples for IFC import and export attached.

Anhänge (2)

Typ: text/xml
625-mal heruntergeladen
Größe: 2,50 KiB
Typ: text/plain
675-mal heruntergeladen
Größe: 6,43 KiB

Zitiert von: bmarciniec
Hello!

I don't see any issues in your code for exporting the file. In fact I've used your code and it worked just fine on my computer.
For the import however the argument for ifcVersion should be given as an integer. See the documentation
ImportIFC( (DrawingFileService)doc, (DocumentAdapter)fileIndex, (int)ifcVersion, (wstring)fileName) -> BaseElementAdapterListOn the other hand the documentation is very confusing here. The second argument fileIndex is actually where the document adapter should be given. And I also don't understand, why the IfcVersion has to be given as integer, as in the IFCExport it is given as an instance of a IfcVersion class. And what is the sense of giving an IfcVersion to an import function in the first place. Seems we need to work on that. But for the moment please find the examples for IFC import and export attached.

Thank you for your answer, this is just what I was looking for