BIM: fix BuildingPart issues with Arch_Reference

This commit is contained in:
Roy-043
2026-01-24 20:43:42 +01:00
committed by Yorik van Havre
parent 6abb2b447f
commit db5fff6ccc

View File

@@ -171,6 +171,10 @@ class ArchReference:
FreeCAD.Console.PrintError(t + "\n")
else:
for part in self.parts.values():
if part[3]:
# Do not include BuildingParts as their
# shape is just a copy of their group:
continue
f = zdoc.open(part[1])
shapedata = f.read()
f.close()
@@ -385,6 +389,7 @@ class ArchReference:
label = None
part = None
materials = {}
is_buildingpart = False
writemode = False
for line in docf:
line = line.decode("utf8")
@@ -392,6 +397,8 @@ class ArchReference:
n = re.findall(r"name=\"(.*?)\"", line)
if n:
name = n[0]
elif 'class="BuildingPart"' in line:
is_buildingpart = True
elif '<Property name="Label"' in line:
writemode = True
elif writemode and "<String value=" in line:
@@ -417,11 +424,12 @@ class ArchReference:
writemode = False
elif "</Object>" in line:
if name and label and part:
parts[name] = [label, part, materials]
parts[name] = [label, part, materials, is_buildingpart]
name = None
label = None
part = None
materials = {}
is_buildingpart = False
writemode = False
return parts
@@ -452,7 +460,11 @@ class ArchReference:
return []
totalcolors = []
parts = [obj.Part] if obj.Part else self.parts.keys()
if obj.Part:
parts = [obj.Part]
else:
# Do not include BuildingParts as their shape is just a copy of their group:
parts = [key for key, val in self.parts.items() if not val[3]]
lenparts = len(parts)
for i, part in enumerate(parts):
lenfaces = len(self.shapes[i].Faces)
@@ -471,7 +483,6 @@ class ArchReference:
zdoc = zipfile.ZipFile(filename)
if not "GuiDocument.xml" in zdoc.namelist():
return []
colors = []
colorfile = None
with zdoc.open("GuiDocument.xml") as docf:
writemode1 = False
@@ -481,26 +492,27 @@ class ArchReference:
line = line.decode("utf8")
if ('<ViewProvider name="' + part + '"') in line:
writemode1 = True
elif writemode1 and '<ViewProvider name="' in line:
# We have reached the next item:
break
elif writemode1 and ('<Property name="DiffuseColor"' in line):
writemode1 = False
writemode2 = True
elif writemode1 and ('<Property name="ShapeAppearance"' in line):
writemode1 = False
writemode3 = True
elif writemode2 and ("<ColorList file=" in line):
n = re.findall(r"file=\"(.*?)\"", line)
if n:
if n and n[0] and n[0] in zdoc.namelist():
colorfile = n[0]
writemode3 = False
break
elif writemode3 and ("<MaterialList file=" in line):
n = re.findall(r"file=\"(.*?)\"", line)
if n:
if n and n[0] and n[0] in zdoc.namelist():
colorfile = n[0]
writemode2 = False
break
if not colorfile:
return []
if not colorfile in zdoc.namelist():
if colorfile is None:
return []
cf = zdoc.open(colorfile)
@@ -526,7 +538,7 @@ class ArchReference:
for material in colors:
material.Transparency = 1.0 - material.Transparency
if writemode3:
elif writemode3:
# File format ShapeAppearance files in FCStd file:
# - 1st byte: number of faces
# - Next 3 bytes: zero