mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-22 13:48:03 +00:00
bim.create_instance - simplify logic
Just use active object instead of the selected, move basic check to `poll`.
This commit is contained in:
@@ -3447,23 +3447,23 @@ class UnassignRepresentationLayer(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
class CreateInstance(bpy.types.Operator, tool.Ifc.Operator):
|
class CreateInstance(bpy.types.Operator, tool.Ifc.Operator):
|
||||||
bl_idname = "bim.create_instance"
|
bl_idname = "bim.create_instance"
|
||||||
bl_label = "IFC Create Instance"
|
bl_label = "IFC Create Instance"
|
||||||
bl_description = "Create an instance of the type associated with the selected object"
|
bl_description = "Create an instance of the type associated with the active object."
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
def _execute(self, context):
|
@classmethod
|
||||||
if not context.selected_objects or len(context.selected_objects) > 1:
|
def poll(cls, context):
|
||||||
self.report({"ERROR"}, "Select exactly one object to create an instance of its type")
|
if not (obj := context.active_object) or not tool.Ifc.get_entity(obj):
|
||||||
return {"CANCELLED"}
|
cls.poll_message_set("Active object is not an IFC element.")
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
active_obj = context.active_object
|
def _execute(self, context):
|
||||||
element = tool.Ifc.get_entity(active_obj)
|
assert (obj := context.active_object)
|
||||||
if not element:
|
assert (element := tool.Ifc.get_entity(obj))
|
||||||
self.report({"ERROR"}, "Selected object is not an IFC element")
|
|
||||||
return {"CANCELLED"}
|
|
||||||
|
|
||||||
relating_type = ifcopenshell.util.element.get_type(element)
|
relating_type = ifcopenshell.util.element.get_type(element)
|
||||||
if not relating_type:
|
if not relating_type:
|
||||||
self.report({"ERROR"}, "Selected object has no associated type")
|
self.report({"ERROR"}, "Active object has no associated type")
|
||||||
return {"CANCELLED"}
|
return {"CANCELLED"}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user