mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-23 21:58:46 +00:00
Replace currently selected objects with occurences of type
Added operator to replace currently selected objects with occurences of the chosen type. I kept doing this from the code and thought it could be generally useful. It's working pretty naive now and just replacing objects with occurences preserving the original transform (location/rotation/scale), nothing else is preserved. Demo - https://imgur.com/a/qm8a6Ns PS Hopefully I'm not reinventing the wheel and not missed some other similar operator
This commit is contained in:
@@ -63,6 +63,7 @@ classes = (
|
|||||||
product.EnableAddType,
|
product.EnableAddType,
|
||||||
product.LoadTypeThumbnails,
|
product.LoadTypeThumbnails,
|
||||||
product.MirrorElements,
|
product.MirrorElements,
|
||||||
|
product.ReplaceSelectedWithTypeOccurences,
|
||||||
workspace.Hotkey,
|
workspace.Hotkey,
|
||||||
wall.AlignWall,
|
wall.AlignWall,
|
||||||
wall.ChangeExtrusionDepth,
|
wall.ChangeExtrusionDepth,
|
||||||
|
|||||||
@@ -283,6 +283,49 @@ class AddConstrTypeInstance(bpy.types.Operator):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
class ReplaceSelectedWithTypeOccurences(bpy.types.Operator, tool.Ifc.Operator):
|
||||||
|
bl_idname = "bim.replace_selected_with_type_occurences"
|
||||||
|
bl_label = "Replace Selected With Type Occurences"
|
||||||
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
bl_description = (
|
||||||
|
"\nReplace selected objects with type either chosen in BIM tools or provided in the argument.\n\n"
|
||||||
|
"NOTE: Currently it's just replacing original object by occurence with the same transform, \n"
|
||||||
|
"no other data from original object is preserved."
|
||||||
|
)
|
||||||
|
relating_type_id: bpy.props.IntProperty(default=0)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def poll(cls, context):
|
||||||
|
if not context.selected_objects:
|
||||||
|
cls.poll_message_set("No objects selected")
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
def _execute(self, context):
|
||||||
|
props = context.scene.BIMModelProperties
|
||||||
|
relating_type_id = self.relating_type_id or int(props.relating_type_id)
|
||||||
|
|
||||||
|
if not relating_type_id:
|
||||||
|
self.report({"ERROR"}, "No type provided.")
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
originally_active_object = context.active_object
|
||||||
|
new_active_object = None
|
||||||
|
objs = bpy.context.selected_objects[:]
|
||||||
|
new_objects = []
|
||||||
|
for replaced_obj in objs:
|
||||||
|
bpy.ops.bim.add_constr_type_instance(relating_type_id=relating_type_id)
|
||||||
|
new_objects.append(obj := bpy.context.active_object)
|
||||||
|
|
||||||
|
obj.matrix_world = replaced_obj.matrix_world
|
||||||
|
if replaced_obj == originally_active_object:
|
||||||
|
new_active_object = obj
|
||||||
|
|
||||||
|
bpy.data.objects.remove(replaced_obj)
|
||||||
|
tool.Blender.set_objects_selection(context, new_active_object, new_objects)
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
class ChangeTypePage(bpy.types.Operator, tool.Ifc.Operator):
|
class ChangeTypePage(bpy.types.Operator, tool.Ifc.Operator):
|
||||||
bl_idname = "bim.change_type_page"
|
bl_idname = "bim.change_type_page"
|
||||||
bl_label = "Change Type Page"
|
bl_label = "Change Type Page"
|
||||||
|
|||||||
@@ -461,6 +461,7 @@ class BimToolUI:
|
|||||||
else:
|
else:
|
||||||
row.label(text="No Construction Type", icon="FILE_3D")
|
row.label(text="No Construction Type", icon="FILE_3D")
|
||||||
row.operator("bim.launch_type_manager", icon="LIGHTPROBE_GRID", text="")
|
row.operator("bim.launch_type_manager", icon="LIGHTPROBE_GRID", text="")
|
||||||
|
row.operator("bim.replace_selected_with_type_occurences", icon="ARROW_LEFTRIGHT", text="")
|
||||||
else:
|
else:
|
||||||
if AuthoringData.data["ifc_element_type"]:
|
if AuthoringData.data["ifc_element_type"]:
|
||||||
row.label(text=f"No {AuthoringData.data['ifc_element_type']} Found", icon="ERROR")
|
row.label(text=f"No {AuthoringData.data['ifc_element_type']} Found", icon="ERROR")
|
||||||
@@ -474,6 +475,7 @@ class BimToolUI:
|
|||||||
else:
|
else:
|
||||||
row.label(text="No Element Types Found", icon="ERROR")
|
row.label(text="No Element Types Found", icon="ERROR")
|
||||||
row.operator("bim.launch_type_manager", icon="LIGHTPROBE_GRID", text="Launch Type Manager")
|
row.operator("bim.launch_type_manager", icon="LIGHTPROBE_GRID", text="Launch Type Manager")
|
||||||
|
row.operator("bim.replace_selected_with_type_occurences", icon="ARROW_LEFTRIGHT", text="")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def draw_basic_bim_tool_interface(cls):
|
def draw_basic_bim_tool_interface(cls):
|
||||||
|
|||||||
Reference in New Issue
Block a user