IfcOpenShell access IFC-SPF header data

edited December 2020 in General

Is it possible to get the Header FILE_DESCRIPTION and FILE_NAME by Python?

HEADER;FILE_DESCRIPTION(('no view'),'2;1');
FILE_NAME('C:\\Users\\BHA\\Desktop\\exporter_new.ifc',
'2020-10-29T15:57:39',('Bernd Hahnebach'),('My Office AG',
'My Street 32, 9999 My Town'),
'EDMsix Version 2.0100.09 Sep  7 2016',
'Allplan 2020.1 09.09.2020 - 17:35:19','');
FILE_SCHEMA(('IFC2X3'));
ENDSEC;

The schema is possible with ifcos_ifc_class.schema. This is what I know and use.

Comments

  • but this is set_header, for export. I would like to read the data out of a ifc file like get_header ...

  • @bernd no, set_header is simply a function in the BlenderBIM Add-on during the export process. Look at the lines after it.

    bernd
  • edited December 2020

    got it ... :-)

    myifcfile.wrapped_data.header.file_description.description
    myifcfile.wrapped_data.header.file_description.implementation_level
    myifcfile.wrapped_data.header.file_name.name
    

    ...

  • How about the comments Revit does write before it even starts the ifc file contents. I assume reading comments is not possible?!

  • @bernd good point, I haven't seen a way to access comments. It's a relatively simple string parse, though...

  • edited July 2022

    How would once acces the timestamp in FILE_NAME using IfcOpenShell?

    ISO-10303-21;
    HEADER;
    FILE_DESCRIPTION(('ViewDefinition[DesignTransferView]'),'2;1');
    FILE_NAME('test_load.ifc','2022-07-28T16:10:23+02:00',(),(),'IfcOpenShell v0.7.0-1b1fd1e6','BlenderBIM 0.0.220516','Nobody');
    FILE_SCHEMA(('IFC4'));
    ENDSEC;
    DATA;
    

    It's a relatively simple string parse, though...

    As I understand it is not possible with IfcOpenShell yet... :-)?

    What about something like this?

    import os
    import re
    import bpy
    import ifcopenshell
    
    from blenderbim.bim.ifc import IfcStore
    
    
    ifc_file = ifcopenshell.open(IfcStore.path)
    
    
    with open(IfcStore.path) as ifc_text:
        for line_no, line_file in enumerate(ifc_text):
            if line_no  == 3:
                if line_file.startswith("FILE_NAME"):
                    print (line_file.split(',')[1])
    

    Is the FILE_NAME always on line 4? seems a bit risky method, string parsing...

  • It will work for this specific file but I'm sure it's not that hard to make it fail ^^ What if your file name has a , in it ? I think it would be a bit more robust to check all lines and see if they begin with FILE_NAME and then parse the string with a regular expression to see if something matches a date formating.

  • @Coen said:
    How would once acces the timestamp in FILE_NAME using IfcOpenShell?

    I'm very late to the party, just found this thread looking for similar issues, but it's just ifc_file.wrapped_data.header.file_name.time_stamp, in similar way as accessing any other header entities.

    Coen
Sign In or Register to comment.