BIM - IfcOpenShell importer problems

This forum section is only for IFC-related issues
Post Reply
maker
Posts: 192
Joined: Sun Apr 01, 2018 10:25 am

BIM - IfcOpenShell importer problems

Post by maker »

Hi Community,

OS: openSUSE Leap 15.2 (KDE//usr/share/xsessions/default)
Word size of FreeCAD: 64-bit
Version: 0.20.Unknown
Build type: Release
Python version: 3.6.10
Qt version: 5.12.7
Coin version: 4.0.0
OCC version: 7.5.1
Locale: German/Germany (de_DE)


looking for a solution to import some provided FreeCAD *.ifc files into FC, I had a longer net research to find a solution for my used OS because the IfcOpenShell version [here: IfcOpenShell-python for python 3.6 64bit Linux] provided at http://ifcopenshell.org/python did not work. :!:
Luckily I have ended up with IfcOpenShell which has to be provided in the openSUSE Leap 15.2 package version, which I've finally found in as an non-official openSUSE build repo.

I've carried out testing FreeCAD BIM WB with the installed IfcOpenShell.rpm against the online
viewer https://view.ifcopenshell.org/ with a total of 5 *.ifc files.

Unfortunately 2 of these *.ifc files show the following error message in the FreeCAD report
panel:

Code: Select all

12:38:31  Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib64/FreeCAD/Mod/Arch/importIFC.py", line 211, in open
    doc = insert(filename, doc.Name, skip, only, root)
  File "/usr/lib64/FreeCAD/Mod/Arch/importIFC.py", line 350, in insert
    mattable = importIFCHelper.buildRelMattable(ifcfile)
  File "/usr/lib64/FreeCAD/Mod/Arch/importIFCHelper.py", line 244, in buildRelMattable
    for o in r.RelatedObjects:
<class 'TypeError'>: 'NoneType' object is not iterable
--> Results:
1) file does not open in FreeCAD
2) file opens correctly without error message on https://view.ifcopenshell.org/

Maybe view.ifcopenshell.org is using IfcOpenShell in the back-end, so it could be explained that the online viewer works fine.

I don't have an detailed idea how the BIM workbench cooperates with IfcOpenShell during *.ifc file import, apparently there is a problem in Python code, as the error message above shows.

==>
Does anyone have an idea what is running wrong in Ifc importer python script files:

Code: Select all

importIFC.py
importIFCHelper.py
and to what this is related to?

...for the sake of completeness I would like to mention while all *.ifc files are opened online on https://view.ifcopenshell.org/
properly without any problems, 3 other *.ifc files show some different minor error messages in the FreeCAD report
panel:

Code: Select all

13:13:02  failed to compute placement 
13:13:12  failed to compute placement 

could not create roof 
13:29:03  Failed to rebuild a valid solid for object  Component039
13:29:03  Failed to rebuild a valid solid for object  Component040
...
object color != material color for object:  752457
13:29:03      material color is used (most software uses shape color)
although it looks quite complete in FC's 3D view...
maker
Posts: 192
Joined: Sun Apr 01, 2018 10:25 am

Re: BIM - IfcOpenShell importer problems

Post by maker »

a close look in the installed and nominated file /usr/lib64/FreeCAD/Mod/Arch/importIFC.py
produces in line 211
.
Screenshot_installed_importIFC.py_Line211.jpg
Screenshot_installed_importIFC.py_Line211.jpg (59.78 KiB) Viewed 9055 times
.
in line 350
.
Screenshot_installed_importIFC.py_Line350.jpg
Screenshot_installed_importIFC.py_Line350.jpg (92.23 KiB) Viewed 9055 times
.
and a close look in the installed and nominated file /usr/lib64/FreeCAD/Mod/Arch/importIFCHelper.py
.
and here in line 244
.
Screenshot_installed_importIFCHelper.py_Line244.jpg
Screenshot_installed_importIFCHelper.py_Line244.jpg (97.28 KiB) Viewed 9055 times
.

Does anyone have an idea what is running wrong in the 2 Ifc importer python script files?? :geek:
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: BIM - IfcOpenShell importer problems

Post by Roy_043 »

Try:

Code: Select all

def buildRelMattable(ifcfile):
    """Build the mattable relation table."""
    mattable = {}  # { objid:matid }

    for r in ifcfile.by_type("IfcRelAssociatesMaterial"):
        if r.RelatedObjects:
            for o in r.RelatedObjects:
                if r.RelatingMaterial.is_a("IfcMaterial"):
                    mattable[o.id()] = r.RelatingMaterial.id()
                elif r.RelatingMaterial.is_a("IfcMaterialLayer"):
                    mattable[o.id()] = r.RelatingMaterial.Material.id()
                elif r.RelatingMaterial.is_a("IfcMaterialLayerSet"):
                    mattable[o.id()] = r.RelatingMaterial.MaterialLayers[0].Material.id()
                elif r.RelatingMaterial.is_a("IfcMaterialLayerSetUsage"):
                    mattable[o.id()] = r.RelatingMaterial.ForLayerSet.MaterialLayers[0].Material.id()

    return mattable
maker
Posts: 192
Joined: Sun Apr 01, 2018 10:25 am

Re: BIM - IfcOpenShell importer problems

Post by maker »

@Roy_043

Thank you so much! YOUR analysis and input with the additional line in the importIfcHelper.py file

Code: Select all

...
 if r.RelatedObjects:
...
was apparently the solution!!

I copied your code-snippet line and inserted it in importIfcHelper.py file. The following test run already showed after a few seconds that the "importing behaviour" of the two .ifc files was completely different. The importing process started running...
And finally after approximately 1128 seconds each model were imported with minor errors, such as:
Unable to create a roof

although the models had both roofs...

How can it be arranged for the FC community, that the additional python code line will be added to importIfcHelper.py?
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: BIM - IfcOpenShell importer problems

Post by bernd »

User avatar
Moult
Posts: 321
Joined: Sat Jan 05, 2019 11:46 am
Contact:

Re: BIM - IfcOpenShell importer problems

Post by Moult »

Can I perhaps make a suggestion here that the line of code added may be a symptom covering a more fundamental problem. I would recommend reverting the commit and finding the fundamental problem.

The cardinality of RelatedObjects in IfcRelAssociatesMaterial is S[1:?] - this means that it must always exist - the "if" statement should never be required. This suggests that the originator of the IFC files created malformed IFCs. If FreeCAD created the IFC files to begin with, then this is a great opportunity to find the issue within FreeCAD's exporter and fix it there. Over time, I believe this "stricter" strategy can lead to much more robust IFC handling in IFC.
I also blog about 3D rendering, architecture, software and other on thinkMoult.com. RSS / Atom feed available for your convenience.
maker
Posts: 192
Joined: Sun Apr 01, 2018 10:25 am

Re: BIM - IfcOpenShell importer problems

Post by maker »

Hi,

I would not retract the commit, as long as there is no better solution for the undoubtedly existing problem.
It is suspected that we are only curing the symptom here and not the problem.
.
Moult wrote: Tue May 18, 2021 11:12 pm ...]

The cardinality of RelatedObjects in IfcRelAssociatesMaterial is S[1:?] - this means that it must always exist - the "if" statement should never be required. This suggests that the originator of the IFC files created malformed IFCs. If FreeCAD created the IFC files to begin with, then this is a great opportunity to find the issue within FreeCAD's exporter and fix it there.
...[
In in my particular case, the files provided were created in autodesk Revit and then converted to .ifc files.
A sample .log file of conversion process shows this content:

Code: Select all

/******************************************************************************************
* WriteStepFile diagnostics.
* Date:                           Tue May 11 19:46:36 2021 
* Produced by:                    The EXPRESS Data Manager Version 5.02.0100.07 : 28 Aug 2013
* Module:                         EDMstepFileFactory/EDMstandAlone
* Host:                           LAPTOP-anon
* Database:                       C:\Users\name\AppData\Local\Temp\a3651c51-c265-48d6-a197-195fdcd9102f\df0e3080-7a8b-4f8d-8216-b24c4cb65adc\ifc
* Database version:               5507
* Database creation date:         Tue May 11 19:44:53 2021
* Model:                          DataRepository.ifc
* Model creation date:            Tue May 11 19:44:53 2021
* Header model:                   DataRepository.ifc_HeaderModel
* Header model creation date:     Tue May 11 19:44:53 2021
* Step file:                      Filename - Lph 2.ifc
* EDMuser:                        sdai-user
* EDMgroup:                       sdai-group
* License ID and type:            5605 : Permanent license. Expiry date: 
* EDMstepFileFactory options:     020000
******************************************************************************************/


------------------------------------------------------------------------------------------------
Operation terminated successfully.
------------------------------------------------------------------------------------------------

Moult wrote: Tue May 18, 2021 11:12 pm ...]
Over time, I believe this "stricter" strategy can lead to much more robust IFC handling in IFC.

...[
Nevertheless I agree with you. It is always better to find the root cause of a problem, than curing the symptom. I needed a quick solution for my problem, experience shows that solving the root cause takes usually unfortunately much more time...
.
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: BIM - IfcOpenShell importer problems

Post by bernd »

We should not support Autodesk in providing corrupted ifc. I am with you moult.

Nerveless as a user I do know the problem. One has a dead line an the customer does not care if Autodesk does provide corrupted ifc. The custumer just would like to have to be delivered his data or drawings in time. If delivery will not be in time, big problems will arise ... I am with you too maker.

IMHO we should not read the file in standard mode and tell the user the file is corrupt. But we should allow him due to a preference to read the file anyway. This preference could even be hidden. Means not on the official preference gui but on the preference editor.

Arch is not my may play ground, but I may have a look at this anyway.

cheers bernd
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: BIM - IfcOpenShell importer problems

Post by yorik »

It is also my philosophy to be tolerant with bad IFC files... Of course Autodesk issuing poor files is really shameful and we have definitely no interest in being tolerant with Autodesk, but I can very well imagine another app that is not well versed in IFC that didn't interpret correctly the specs, and having only Autodesk files as examples to work with. It wouldn't be entirely their fault IMHO.

In this case it doesn't really harm to perform that test, and after all only turns FreeCAD more resistant.
Post Reply