From 38e5321dbba10590818b93e35235e6e87a571c01 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Sun, 11 Oct 2020 13:13:33 +1100 Subject: [PATCH] Add IFC remove node --- src/ifcsverchok/__init__.py | 1 + src/ifcsverchok/nodes/ifc/remove.py | 37 +++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/ifcsverchok/nodes/ifc/remove.py diff --git a/src/ifcsverchok/__init__.py b/src/ifcsverchok/__init__.py index 5f44c58ec2..4c4b018b47 100644 --- a/src/ifcsverchok/__init__.py +++ b/src/ifcsverchok/__init__.py @@ -32,6 +32,7 @@ def nodes_index(): ("ifc.by_type", "SvIfcByType"), ("ifc.by_query", "SvIfcByQuery"), ("ifc.add", "SvIfcAdd"), + ("ifc.remove", "SvIfcRemove"), ("ifc.select_blender_objects", "SvIfcSelectBlenderObjects"), ])] diff --git a/src/ifcsverchok/nodes/ifc/remove.py b/src/ifcsverchok/nodes/ifc/remove.py new file mode 100644 index 0000000000..90ab29a854 --- /dev/null +++ b/src/ifcsverchok/nodes/ifc/remove.py @@ -0,0 +1,37 @@ +import bpy +import ifcopenshell +import ifcsverchok.helper +from bpy.props import StringProperty +from sverchok.node_tree import SverchCustomTreeNode +from sverchok.data_structure import updateNode + + +class SvIfcRemove(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.SvIfcCore): + bl_idname = 'SvIfcRemove' + bl_label = 'IFC Remove' + file: StringProperty(name='file', update=updateNode) + entity: StringProperty(name='entity', update=updateNode) + + def sv_init(self, context): + self.inputs.new('SvStringsSocket', 'file').prop_name = 'file' + self.inputs.new('SvStringsSocket', 'entity').prop_name = 'entity' + self.outputs.new('SvStringsSocket', 'file') + + def process(self): + file = self.inputs['file'].sv_get()[0][0] + self.new_file = ifcopenshell.file.from_string(file.wrapped_data.to_string()) + self.remove_entity(self.inputs['entity'].sv_get()) + self.outputs['file'].sv_set([[self.new_file]]) + + def remove_entity(self, entity): + if isinstance(entity, (tuple, list)): + for e in entity: + self.remove_entity(e) + else: + self.new_file.remove(self.new_file.by_id(entity.id())) + +def register(): + bpy.utils.register_class(SvIfcRemove) + +def unregister(): + bpy.utils.unregister_class(SvIfcRemove)