mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-18 22:33:33 +00:00
Extend github.com/IfcOpenShell/IfcOpenShell/commit/1b2ad6c93f633df46d55f65bf97e730461fd7e6c - apply new type to all the selected objects.
This commit is contained in:
@@ -324,13 +324,13 @@ class DuplicateType(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
element: bpy.props.IntProperty()
|
element: bpy.props.IntProperty()
|
||||||
name: bpy.props.StringProperty(name="Name")
|
name: bpy.props.StringProperty(name="Name")
|
||||||
description: bpy.props.StringProperty(name="Description")
|
description: bpy.props.StringProperty(name="Description")
|
||||||
assign_active_object: bpy.props.BoolProperty(default=False)
|
assign_selected_objects: bpy.props.BoolProperty(default=False)
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
element: int
|
element: int
|
||||||
name: str
|
name: str
|
||||||
description: str
|
description: str
|
||||||
assign_active_object: bool
|
assign_selected_objects: bool
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
element = tool.Ifc.get().by_id(self.element)
|
element = tool.Ifc.get().by_id(self.element)
|
||||||
@@ -349,14 +349,16 @@ class DuplicateType(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
|
|
||||||
bpy.ops.bim.load_type_thumbnails()
|
bpy.ops.bim.load_type_thumbnails()
|
||||||
|
|
||||||
# Assign active object to the new type if requested
|
# Assign selected objects to the new type if requested
|
||||||
if self.assign_active_object and context.active_object:
|
if self.assign_selected_objects:
|
||||||
active_element = tool.Ifc.get_entity(context.active_object)
|
selected_objects = tool.Blender.get_selected_objects()
|
||||||
if active_element and active_element.is_a("IfcObject"):
|
prefs = tool.Blender.get_addon_preferences()
|
||||||
core.assign_type(tool.Ifc, tool.Type, element=active_element, type=new)
|
for selected_obj in selected_objects:
|
||||||
prefs = tool.Blender.get_addon_preferences()
|
selected_element = tool.Ifc.get_entity(selected_obj)
|
||||||
if prefs.occurrence_name_style == "TYPE":
|
if selected_element and selected_element.is_a("IfcObject"):
|
||||||
context.active_object.name = tool.Model.generate_occurrence_name(new, active_element.is_a())
|
core.assign_type(tool.Ifc, tool.Type, element=selected_element, type=new)
|
||||||
|
if prefs.occurrence_name_style == "TYPE":
|
||||||
|
selected_obj.name = tool.Model.generate_occurrence_name(new, selected_element.is_a())
|
||||||
|
|
||||||
if obj in context.selectable_objects:
|
if obj in context.selectable_objects:
|
||||||
tool.Blender.select_and_activate_single_object(context, new_obj)
|
tool.Blender.select_and_activate_single_object(context, new_obj)
|
||||||
@@ -381,7 +383,7 @@ class DuplicateType(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
self.layout.prop(self, "name")
|
self.layout.prop(self, "name")
|
||||||
self.layout.prop(self, "description")
|
self.layout.prop(self, "description")
|
||||||
if context.active_object:
|
selected_objects = tool.Blender.get_selected_objects()
|
||||||
active_element = tool.Ifc.get_entity(context.active_object)
|
ifc_objects = [obj for obj in selected_objects if tool.Ifc.get_entity(obj) and tool.Ifc.get_entity(obj).is_a("IfcObject")]
|
||||||
if active_element and active_element.is_a("IfcObject"):
|
if ifc_objects:
|
||||||
self.layout.prop(self, "assign_active_object", text="Assign Active Object to New Type")
|
self.layout.prop(self, "assign_selected_objects", text=f"Assign {len(ifc_objects)} Selected Object(s) to New Type")
|
||||||
|
|||||||
@@ -96,10 +96,10 @@ class BIM_PT_type(Panel):
|
|||||||
op = row.operator("bim.select_type", icon="OBJECT_DATA", text="")
|
op = row.operator("bim.select_type", icon="OBJECT_DATA", text="")
|
||||||
op.relating_type = 0 # will only select the relating types of only the selected objects
|
op.relating_type = 0 # will only select the relating types of only the selected objects
|
||||||
row.operator("bim.select_similar_type", icon="RESTRICT_SELECT_OFF", text="")
|
row.operator("bim.select_similar_type", icon="RESTRICT_SELECT_OFF", text="")
|
||||||
# Add duplicate button here with assign_active_object enabled
|
# Add duplicate button here with assign_selected_objects enabled
|
||||||
op = row.operator("bim.duplicate_type", icon="DUPLICATE", text="")
|
op = row.operator("bim.duplicate_type", icon="DUPLICATE", text="")
|
||||||
op.element = TypeData.data["relating_type"]["id"]
|
op.element = TypeData.data["relating_type"]["id"]
|
||||||
op.assign_active_object = True
|
op.assign_selected_objects = True
|
||||||
row.operator("bim.enable_editing_type", icon="GREASEPENCIL", text="")
|
row.operator("bim.enable_editing_type", icon="GREASEPENCIL", text="")
|
||||||
row.operator("bim.unassign_type", icon="X", text="")
|
row.operator("bim.unassign_type", icon="X", text="")
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user