mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
Fix #4049. New basic "regenerate occurrence name" operator.
This commit is contained in:
@@ -59,6 +59,10 @@ def name_callback(obj, data):
|
||||
if not obj.BIMObjectProperties.ifc_definition_id:
|
||||
return
|
||||
|
||||
if obj.BIMObjectProperties.is_renaming:
|
||||
obj.BIMObjectProperties.is_renaming = False
|
||||
return
|
||||
|
||||
element = IfcStore.get_file().by_id(obj.BIMObjectProperties.ifc_definition_id)
|
||||
if "/" in obj.name:
|
||||
object_name = obj.name
|
||||
|
||||
@@ -22,6 +22,7 @@ from . import ui, prop, operator
|
||||
classes = (
|
||||
operator.AddType,
|
||||
operator.AssignType,
|
||||
operator.AutoRenameOccurrences,
|
||||
operator.DisableEditingType,
|
||||
operator.DuplicateType,
|
||||
operator.EnableEditingType,
|
||||
|
||||
@@ -498,6 +498,22 @@ class RenameType(bpy.types.Operator, tool.Ifc.Operator):
|
||||
self.layout.prop(self, "name")
|
||||
|
||||
|
||||
class AutoRenameOccurrences(bpy.types.Operator, tool.Ifc.Operator):
|
||||
bl_idname = "bim.auto_rename_occurrences"
|
||||
bl_label = "Auto Rename Occurrences"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
def _execute(self, context):
|
||||
obj = context.active_object
|
||||
element_type = tool.Ifc.get_entity(obj)
|
||||
if element_type and element_type.is_a("IfcTypeObject"):
|
||||
for occurrence in ifcopenshell.util.element.get_types(element_type):
|
||||
obj = tool.Ifc.get_object(occurrence)
|
||||
occurrence.Name = tool.Model.generate_occurrence_name(element_type, occurrence.is_a())
|
||||
if obj:
|
||||
tool.Root.set_object_name(obj, occurrence)
|
||||
|
||||
|
||||
class DuplicateType(bpy.types.Operator, tool.Ifc.Operator):
|
||||
bl_idname = "bim.duplicate_type"
|
||||
bl_label = "Duplicate Type"
|
||||
|
||||
@@ -64,6 +64,7 @@ class BIM_PT_type(Panel):
|
||||
select_type_objects_row.enabled = int(TypeData.data["total_instances"]) > 0
|
||||
op = row.operator("bim.duplicate_type", icon="DUPLICATE", text="")
|
||||
op.element = context.active_object.BIMObjectProperties.ifc_definition_id
|
||||
row.operator("bim.auto_rename_occurrences", icon="ITALIC", text="")
|
||||
|
||||
def draw_product_ui(self, context):
|
||||
layout = self.layout
|
||||
|
||||
@@ -425,6 +425,7 @@ class BIMObjectProperties(PropertyGroup):
|
||||
default="NONE",
|
||||
)
|
||||
is_reassigning_class: BoolProperty(name="Is Reassigning Class")
|
||||
is_renaming: BoolProperty(name="Is Renaming", default=False)
|
||||
location_checksum: StringProperty(name="Location Checksum")
|
||||
rotation_checksum: StringProperty(name="Rotation Checksum")
|
||||
|
||||
|
||||
@@ -214,5 +214,7 @@ class Root(blenderbim.core.tool.Root):
|
||||
|
||||
@classmethod
|
||||
def set_object_name(cls, obj, element):
|
||||
# This disables the Blender name event handler
|
||||
obj.BIMObjectProperties.is_renaming = True
|
||||
name = getattr(element, "Name", getattr(element, "AxisTag", None))
|
||||
obj.name = "{}/{}".format(element.is_a(), name or "Unnamed")
|
||||
|
||||
Reference in New Issue
Block a user