diff --git a/src/ifcsverchok/__init__.py b/src/ifcsverchok/__init__.py index 2c9e37f623..9745707e4d 100644 --- a/src/ifcsverchok/__init__.py +++ b/src/ifcsverchok/__init__.py @@ -119,6 +119,7 @@ def nodes_index() -> list[tuple[str, list[tuple[str, str]]]]: ("ifc.shape_builder.extrude", "SvIfcSbExtrude"), ("ifc.shape_builder.representation", "SvIfcSbRepresentation"), ("ifc.shape_builder.test", "SvIfcSbTest"), + ("ifc.shape_builder.shape_output", "SvSbShapeOutput"), ], ), ] diff --git a/src/ifcsverchok/nodes/ifc/shape_builder/shape_output.py b/src/ifcsverchok/nodes/ifc/shape_builder/shape_output.py new file mode 100644 index 0000000000..c3555c25e4 --- /dev/null +++ b/src/ifcsverchok/nodes/ifc/shape_builder/shape_output.py @@ -0,0 +1,67 @@ +# IfcSverchok - IFC Sverchok extension +# Copyright (C) 2022 Martina Jakubowska +# +# This file is part of IfcSverchok. +# +# IfcSverchok is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# IfcSverchok is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with IfcSverchok. If not, see . + +import bpy +import ifcopenshell +import ifcopenshell.geom +import ifcopenshell.ifcopenshell_wrapper as W +import ifcopenshell.util.shape +import sverchok.core.sockets +from sverchok.node_tree import SverchCustomTreeNode + +import ifcsverchok.helper as helper + + +class SvSbShapeOutput(bpy.types.Node, SverchCustomTreeNode, helper.SvIfcCore): + """ + Triggers: Ifc create shape by entity + Tooltip: Convert IfcShapeRepresentation to geometry data. + """ + + bl_idname = "SvSbShapeOutput" + bl_label = "IFC Shape Output" + + def sv_init(self, context): + helper.create_socket(self.inputs, "Representation", data_type="list[list[ifcopenshell.entity_instance]]") + helper.create_socket(self.outputs, "Vers", socket_type=sverchok.core.sockets.SvVerticesSocket) + helper.create_socket(self.outputs, "Edgs") + helper.create_socket(self.outputs, "Pols") + + def process(self): + entity: ifcopenshell.entity_instance = helper.get_socket_value(self.inputs, "Representation") + self.create(entity) + helper.set_socket_value(self.outputs, "Vers", [self.verts], value_type="FINAL_VALUE") + helper.set_socket_value(self.outputs, "Edgs", [self.edges], value_type="FINAL_VALUE") + helper.set_socket_value(self.outputs, "Pols", [self.polys], value_type="FINAL_VALUE") + + def create(self, entity: ifcopenshell.entity_instance) -> None: + assert bpy.context.scene + settings = ifcopenshell.geom.settings() + shape = ifcopenshell.geom.create_shape(settings, entity) + assert isinstance(shape, W.Triangulation) + self.verts = ifcopenshell.util.shape.get_vertices(shape).tolist() + self.edges = ifcopenshell.util.shape.get_edges(shape).tolist() + self.polys = ifcopenshell.util.shape.get_faces(shape).tolist() + + +def register(): + bpy.utils.register_class(SvSbShapeOutput) + + +def unregister(): + bpy.utils.unregister_class(SvSbShapeOutput)