Bug fixes and changed behaviour of create_entity, so it creates an entity pr. each representation

This commit is contained in:
martinaCodes
2022-11-13 15:56:33 +01:00
committed by Dion Moult
parent 421f861e46
commit 0ab0213dea
5 changed files with 196 additions and 144 deletions
+40 -11
View File
@@ -26,7 +26,9 @@ from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import updateNode, flatten_data
class SvIfcWriteFile(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.SvIfcCore):
class SvIfcWriteFile(
bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.SvIfcCore
):
"""
Triggers: Ifc write to file
Tooltip: Write active Sverchok Ifc file to path
@@ -37,11 +39,17 @@ class SvIfcWriteFile(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.Sv
self.process()
self.refresh_local = False
refresh_local: BoolProperty(name="Write", description="Write to file", update=refresh_node_local)
refresh_local: BoolProperty(
name="Write", description="Write to file", update=refresh_node_local
)
bl_idname = "SvIfcWriteFile"
bl_label = "IFC Write File"
path: StringProperty(name="path", description="File path to write to. Can be relative.", update=updateNode)
path: StringProperty(
name="path",
description="File path to write to. Can be relative.",
update=updateNode,
)
def sv_init(self, context):
self.inputs.new("SvStringsSocket", "path").prop_name = "path"
@@ -71,18 +79,27 @@ class SvIfcWriteFile(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.Sv
def ensure_hirarchy(self, file):
elements_in_buildings = []
if not 0 <= 0 < len(file.by_type("IfcBuilding")):
my_building = ifcopenshell.api.run("root.create_entity", file, ifc_class="IfcBuilding", name="My Building")
my_building = ifcopenshell.api.run(
"root.create_entity", file, ifc_class="IfcBuilding", name="My Building"
)
elements = ifcopenshell.util.element.get_decomposition(my_building)
else:
for building in file.by_type("IfcBuilding"):
elements = ifcopenshell.util.element.get_decomposition(building)
elements_in_buildings.extend(elements)
for spatial in file.by_type("IfcSpatialElement") or file.by_type("IfcSpatialStructureElement"):
if not (spatial.is_a("IfcSite") or spatial.is_a("IfcBuilding")) and (spatial not in elements_in_buildings):
for spatial in file.by_type("IfcSpatialElement") or file.by_type(
"IfcSpatialStructureElement"
):
if not (spatial.is_a("IfcSite") or spatial.is_a("IfcBuilding")) and (
spatial not in elements_in_buildings
):
elements = ifcopenshell.util.element.get_decomposition(spatial)
ifcopenshell.api.run(
"aggregate.assign_object", file, product=spatial, relating_object=file.by_type("IfcBuilding")[0]
"aggregate.assign_object",
file,
product=spatial,
relating_object=file.by_type("IfcBuilding")[0],
)
elements_in_buildings_after = []
@@ -94,19 +111,31 @@ class SvIfcWriteFile(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.Sv
for element in elements:
if element not in elements_in_buildings:
ifcopenshell.api.run(
"spatial.assign_container", file, product=element, relating_structure=file.by_type("IfcBuilding")[0]
"spatial.assign_container",
file,
product=element,
relating_structure=file.by_type("IfcBuilding")[0],
)
for building in file.by_type("IfcBuilding"):
elements = ifcopenshell.util.element.get_decomposition(building)
if not building.Decomposes:
if not 0 <= 0 < len(file.by_type("IfcSite")):
ifcopenshell.api.run("root.create_entity", file, ifc_class="IfcSite", name="My Site")
ifcopenshell.api.run(
"root.create_entity", file, ifc_class="IfcSite", name="My Site"
)
ifcopenshell.api.run(
"aggregate.assign_object", file, product=building, relating_object=file.by_type("IfcSite")[0]
"aggregate.assign_object",
file,
product=building,
relating_object=file.by_type("IfcSite")[0],
)
try:
if file.by_type("IfcSite")[0].Decomposes[0].RelatingObject.is_a("IfcProject"):
if (
file.by_type("IfcSite")[0]
.Decomposes[0]
.RelatingObject.is_a("IfcProject")
):
continue
except IndexError:
pass