Arch: import IFC, Materials, make merge materials working on duplicate label setting
This commit is contained in:
@@ -1261,7 +1261,7 @@ def insert(srcfile, docname, skip=[], only=[], root=None, preferences=None):
|
||||
# print(material.id())
|
||||
|
||||
mdict = {}
|
||||
# on ifc import only the "DiffuseColor" of the material dictionary is initialized
|
||||
# on ifc import only the "Description" and "DiffuseColor" (if it was read) of the material dictionary will be initialized
|
||||
# on editing material in Arch Gui a lot more keys of the material dictionary are initialized even with empty values
|
||||
# TODO: there should be a generic material obj init method which will be used by Arch Gui, import IFC, FEM, etc
|
||||
|
||||
@@ -1271,7 +1271,10 @@ def insert(srcfile, docname, skip=[], only=[], root=None, preferences=None):
|
||||
name = material.Name
|
||||
if six.PY2:
|
||||
name = name.encode("utf8")
|
||||
mdict["Name"] = name
|
||||
# mdict["Name"] = name on duplicate material names in IFC this could result in crash
|
||||
# https://forum.freecadweb.org/viewtopic.php?f=23&t=63260
|
||||
# thus use "Description"
|
||||
mdict["Description"] = name
|
||||
|
||||
# get material color
|
||||
# the "DiffuseColor" of a material should never be "None"
|
||||
@@ -1295,16 +1298,16 @@ def insert(srcfile, docname, skip=[], only=[], root=None, preferences=None):
|
||||
if preferences["MERGE_MATERIALS"]:
|
||||
for added_mat in added_mats:
|
||||
if (
|
||||
# added_mat.Material["Name"] == name
|
||||
# above does not work because FreeCAD would crash in some circumstances
|
||||
# https://forum.freecadweb.org/viewtopic.php?f=23&t=63260
|
||||
added_mat.Label == name
|
||||
and ("DiffuseColor" in mdict and "DiffuseColor" in added_mat.Material)
|
||||
and mdict["DiffuseColor"] == added_mat.Material["DiffuseColor"]
|
||||
"Description" in added_mat.Material
|
||||
and "DiffuseColor" in added_mat.Material
|
||||
and "DiffuseColor" in mdict # Description has been set thus it is in mdict
|
||||
and added_mat.Material["Description"] == mdict["Description"]
|
||||
and added_mat.Material["DiffuseColor"] == mdict["DiffuseColor"]
|
||||
):
|
||||
matobj = added_mat
|
||||
add_material = False
|
||||
break
|
||||
|
||||
# add a new material object
|
||||
if add_material is True:
|
||||
matobj = Arch.makeMaterial(name=name)
|
||||
|
||||
Reference in New Issue
Block a user