Files
IfcOpenShell/src/ifcsverchok/nodes/ifc/select_blender_objects.py
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

91 lines
3.2 KiB
Python
Raw Normal View History

2021-08-17 08:39:38 +10:00
# IfcSverchok - IFC Sverchok extension
# Copyright (C) 2020, 2021, 2022 Dion Moult <dion@thinkmoult.com>
2021-08-17 08:39:38 +10:00
#
# 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 <http://www.gnu.org/licenses/>.
2025-12-19 18:53:04 +05:00
import bonsai.tool as tool
import bpy
import ifcopenshell
import ifcopenshell.util.selector
from bpy.props import StringProperty
from sverchok.data_structure import updateNode
2025-12-19 18:53:04 +05:00
from sverchok.node_tree import SverchCustomTreeNode
import ifcsverchok.helper
import ifcsverchok.helper as helper
2020-10-10 10:21:17 +11:00
class SvIfcSelectBlenderObjectsRefresh(bpy.types.Operator):
bl_idname = "node.sv_ifc_select_blender_objects_refresh"
bl_label = "IFC Select Blender Objects Refresh"
bl_options = {"UNDO"}
tree_name: StringProperty(default="")
node_name: StringProperty(default="")
2020-10-10 10:21:17 +11:00
def execute(self, context):
2025-03-21 12:53:13 +05:00
node: SvIfcSelectBlenderObjects
node = bpy.data.node_groups[self.tree_name].nodes[self.node_name]
2020-10-10 10:21:17 +11:00
node.process()
return {"FINISHED"}
class SvIfcSelectBlenderObjects(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.SvIfcCore):
bl_idname = "SvIfcSelectBlenderObjects"
bl_label = "IFC Select Blender Objects"
2025-03-21 12:53:13 +05:00
bl_description = "Select Blender objects based on IFC entities."
file: StringProperty(name="file", update=updateNode)
2025-03-21 12:53:13 +05:00
# TODO: never used.
query: StringProperty(name="query", update=updateNode)
def sv_init(self, context):
helper.create_socket(
self.inputs,
"entities",
description="IFC entities to select Bonsai Blender objects for (selects only objects by matching GlobalId).",
data_type="list[list[ifcopenshell.entity_instance]]",
prop_name="entities",
)
2020-10-10 10:21:17 +11:00
def draw_buttons(self, context, layout):
2021-07-03 18:46:17 +10:00
self.wrapper_tracked_ui_draw_op(
layout, "node.sv_ifc_select_blender_objects_refresh", icon="FILE_REFRESH", text="Refresh"
)
2020-10-10 10:21:17 +11:00
2025-03-21 12:53:13 +05:00
def process(self) -> None:
self.sv_input_names = ["entities"]
2025-03-21 12:53:13 +05:00
self.guids: list[str] = []
super().process()
for obj in bpy.context.visible_objects:
2025-03-21 12:53:13 +05:00
element = tool.Ifc.get_entity(obj)
if not element:
continue
2025-03-21 12:53:13 +05:00
if getattr(element, "GlobalId", None) in self.guids:
obj.select_set(True)
2025-03-21 12:53:13 +05:00
def process_ifc(self, entities: ifcopenshell.entity_instance) -> None:
self.guids.append(entities.GlobalId)
def register():
2020-10-10 10:21:17 +11:00
bpy.utils.register_class(SvIfcSelectBlenderObjectsRefresh)
bpy.utils.register_class(SvIfcSelectBlenderObjects)
2020-11-01 19:24:01 +07:00
def unregister():
bpy.utils.unregister_class(SvIfcSelectBlenderObjects)
2020-10-10 10:21:17 +11:00
bpy.utils.unregister_class(SvIfcSelectBlenderObjectsRefresh)