From ad8a81642cf5b0bb51f2127e6d9f76da4a4f70fc Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Wed, 7 Aug 2019 18:14:47 +0200 Subject: [PATCH] Arch: IFC import, only merge materials if they have same name and color --- src/Mod/Arch/Resources/ui/preferences-ifc.ui | 4 +-- src/Mod/Arch/importIFC.py | 33 +++++++++++++------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/Mod/Arch/Resources/ui/preferences-ifc.ui b/src/Mod/Arch/Resources/ui/preferences-ifc.ui index 4cb0fa9cac..8ef7fcbff5 100644 --- a/src/Mod/Arch/Resources/ui/preferences-ifc.ui +++ b/src/Mod/Arch/Resources/ui/preferences-ifc.ui @@ -275,11 +275,11 @@ Note that this might slow things down. - If several materials with the same name are found in the IFC file, + If several materials with the same name and color are found in the IFC file, they will be treated as one. - Merge materials with same name + Merge materials with same name and same color ifcMergeMaterials diff --git a/src/Mod/Arch/importIFC.py b/src/Mod/Arch/importIFC.py index 9be945cb3b..2cce316976 100644 --- a/src/Mod/Arch/importIFC.py +++ b/src/Mod/Arch/importIFC.py @@ -1203,26 +1203,37 @@ def insert(filename,docname,skip=[],only=[],root=None): #print("materials:",materials) fcmats = {} for material in materials: + # get and set material name name = "Material" if material.Name: name = material.Name if six.PY2: name = name.encode("utf8") - if MERGE_MATERIALS and (name in fcmats.keys()): - mat = fcmats[name] + # get material color + mdict = {} + if material.id() in colors: + mdict["DiffuseColor"] = str(colors[material.id()]) else: + for o,m in mattable.items(): + if m == material.id(): + if o in colors: + mdict["DiffuseColor"] = str(colors[o]) + # merge materials with same name and color if setting in prefs is True + add_material = True + if MERGE_MATERIALS: + for key in list(fcmats.keys()): + if key.startswith(name) \ + and "DiffuseColor" in mdict and "DiffuseColor" in fcmats[key].Material \ + and mdict["DiffuseColor"] == fcmats[key].Material["DiffuseColor"]: + mat = fcmats[key] + add_material = False + # add a new material object + if add_material is True: mat = Arch.makeMaterial(name=name) - mdict = {} - if material.id() in colors: - mdict["DiffuseColor"] = str(colors[material.id()]) - else: - for o,m in mattable.items(): - if m == material.id(): - if o in colors: - mdict["DiffuseColor"] = str(colors[o]) if mdict: mat.Material = mdict - fcmats[name] = mat + fcmats[mat.Name] = mat + # fill material attribut of the objects for o,m in mattable.items(): if m == material.id(): if o in objects: