mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-21 13:13:44 +00:00
Bug fixes and changed behaviour of create_entity, so it creates an entity pr. each representation
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user