Error importing IfcDraughtingPreDefinedColour

This forum section is only for IFC-related issues
Post Reply
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Error importing IfcDraughtingPreDefinedColour

Post by vocx »

Code: Select all

OS: Ubuntu 18.04.4 LTS (ubuntu:GNOME/ubuntu)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.22219 (Git)
Build type: Release
Branch: master
Hash: 4ce85d39d394abf7844754e839631e3c8308ac7d
Python version: 3.6.9
Qt version: 5.9.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedStates (en_US)

Code: Select all

>>> ifcopenshell.version
'0.6.0b0'
When importing an IFC file, an IfcProduct may have a reference to an IfcRepresentationItem that sets its color by means of an IfcStyledItem, which may have different styles like IfcSurfaceStyle or IfcCurveStyle defining a color.

The color may be an IfcColourRgb and have RGB numeric values

Code: Select all

IfcColourRgb.Red
IfcColourRgb.Green
IfcColourRgb.Blue
or it may be an IfcDraughtingPreDefinedColour, in which case it may have a fixed name

Code: Select all

IfcDraughtingPreDefinedColour.Name == 'red'
IfcDraughtingPreDefinedColour.Name == 'blue'
IfcDraughtingPreDefinedColour.Name == 'black'
etc.
See more under IfcDraughtingPreDefinedColour.

The predefined color names currently are not handled by our IFC importer, which causes an error.

Code: Select all

Opening  /opt/freecad-build-debug-vocx/ifc_s/01_KIT_IFC_examples_IFC4/AC20-Institute-Var-2.ifc ...Building types and relationships table...Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/opt/freecad-build-main/Mod/Arch/importIFC.py", line 209, in open
    doc = insert(filename, doc.Name, skip, only, root)
  File "/opt/freecad-build-main/Mod/Arch/importIFC.py", line 327, in insert
    colors = importIFCHelper.buildRelProductColors(ifcfile, prodrepr)
  File "/opt/freecad-build-main/Mod/Arch/importIFCHelper.py", line 334, in buildRelProductColors
    colors[p] = getColorFromStyledItem(styled_item)
  File "/opt/freecad-build-main/Mod/Arch/importIFCHelper.py", line 425, in getColorFromStyledItem
    col = [rgb_color.Red, rgb_color.Green, rgb_color.Blue]
  File "/home/vocx/.local/lib/python3.6/site-packages/ifcopenshell/entity_instance.py", line 65, in __getattr__
    "entity instance of type '%s' has no attribute '%s'" % (self.wrapped_data.is_a(), name))
<class 'AttributeError'>: entity instance of type 'IfcDraughtingPreDefinedColour' has no attribute 'Red'
Pull request #3785 translates the fixed names to a tuple (r, g, b).

Code: Select all

PREDEFINED_RGB = {'black': (0, 0, 0),
                  'red': (1.0, 0, 0),
                  'green': (0, 1.0, 0),
                  'blue': (0, 0, 1.0),
                  'yellow': (1.0, 1.0, 0),
                  'magenta': (1.0, 0, 1.0),
                  'cyan': (0, 1.0, 1.0),
                  'white': (1.0, 1.0, 1.0)}
Finally the tuple is augmented with zero transparency, (r, g, b, 0), as expected by the code that assigns colors to the created shapes.

We are testing using KIT IFC Examples (IFC4). In this case the error is triggered by "Office Building", AC20-Institute-Var-2.ifc (10 MB).

If you have other failing IFC files made with Revit or Archicad, let me know so I can take a look at it.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
Post Reply