Create instance context menu (#6830)

This commit is contained in:
falken10vdl
2025-06-22 14:09:57 +02:00
committed by GitHub
parent d875baefde
commit 98c479f1bd
4 changed files with 44 additions and 1 deletions
+1 -1
View File
@@ -314,7 +314,7 @@ def prop_with_search(
row = layout.row(align=True)
row.prop(data, prop_name, **kwargs)
try:
if len(get_enum_items(data, prop_name, original_operator_path=original_operator_path)) > 10:
if len(get_enum_items(data, prop_name, original_operator_path=original_operator_path)) > 0:
# Magick courtesy of https://blender.stackexchange.com/a/203443/86891
row.context_pointer_set(name="data", data=data)
op = row.operator("bim.enum_property_search", text="", icon="VIEWZOOM")
@@ -77,6 +77,7 @@ classes = (
operator.UpdateItemAttributes,
operator.UpdateParametricRepresentation,
operator.UpdateRepresentation,
operator.CreateInstance,
prop.RepresentationItem,
prop.RepresentationItemObject,
prop.ShapeAspect,
@@ -46,6 +46,7 @@ import bonsai.core.root
import bonsai.core.drawing
import bonsai.tool as tool
import bonsai.bim.handler
from bonsai.bim.module.model.data import AuthoringData
from mathutils import Vector, Matrix, Quaternion
from time import time
from bonsai.bim.ifc import IfcStore
@@ -3432,3 +3433,38 @@ class UnassignRepresentationLayer(bpy.types.Operator, tool.Ifc.Operator):
layer = ifc_file.by_id(self.layer_id)
ifcopenshell.api.layer.unassign_layer(ifc_file, [representation], layer)
return {"FINISHED"}
class CreateInstance(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.create_instance"
bl_label = "IFC Create Instance"
bl_description = "Create an instance of the type associated with the selected object"
bl_options = {"REGISTER", "UNDO"}
def _execute(self, context):
if not context.selected_objects or len(context.selected_objects) > 1:
self.report({"ERROR"}, "Select exactly one object to create an instance of its type")
return {"CANCELLED"}
active_obj = context.active_object
element = tool.Ifc.get_entity(active_obj)
if not element:
self.report({"ERROR"}, "Selected object is not an IFC element")
return {"CANCELLED"}
relating_type = ifcopenshell.util.element.get_type(element)
if not relating_type:
self.report({"ERROR"}, "Selected object has no associated type")
return {"CANCELLED"}
try:
props = tool.Model.get_model_props()
props.ifc_class = relating_type.is_a()
props.relating_type_id = str(relating_type.id())
except:
self.report({"ERROR"}, "You must be using the Multiobject Tool or the relevant editing tool")
return {"CANCELLED"}
bpy.ops.bim.hotkey(hotkey="S_A")
return {"FINISHED"}
@@ -66,6 +66,12 @@ def object_menu(self, context):
self.layout.menu("BIM_MT_object_set_origin", icon="PLUGIN")
self.layout.menu("BIM_MT_separate", icon="PLUGIN")
# only show the create instance operator if the current tool is the BIM tool
# if context.space_data and hasattr(context.space_data, "show_object_viewport_mesh"):
# current_tool = context.workspace.tools.from_space_view3d_mode(context.mode, create=False)
# if current_tool and current_tool.idname == "bim.bim_tool":
self.layout.operator("bim.create_instance", icon="PLUGIN")
def edit_mesh_menu(self, context):
self.layout.separator()