(obj: Union[bpy.types.Object, bpy.types.Material], data: str)
| 52 | |
| 53 | |
| 54 | def name_callback(obj: Union[bpy.types.Object, bpy.types.Material], data: str) -> None: |
| 55 | try: |
| 56 | obj.name |
| 57 | except: |
| 58 | # The object is invalid but somehow still has a callback. |
| 59 | # This can occur during undo/redo when the Python wrapper is stale. |
| 60 | return |
| 61 | # Blender names are up to 63 UTF-8 bytes |
| 62 | if len(bytes(obj.name, "utf-8")) >= 63: |
| 63 | return |
| 64 | |
| 65 | if isinstance(obj, bpy.types.Material): |
| 66 | props = tool.Style.get_material_style_props(obj) |
| 67 | if ifc_definition_id := props.ifc_definition_id: |
| 68 | if props.is_renaming: |
| 69 | props.is_renaming = False |
| 70 | return |
| 71 | tool.Ifc.get().by_id(ifc_definition_id).Name = obj.name |
| 72 | refresh_ui_data() |
| 73 | return |
| 74 | |
| 75 | props = tool.Blender.get_object_bim_props(obj) |
| 76 | if not props.ifc_definition_id: |
| 77 | return |
| 78 | |
| 79 | if props.is_renaming: |
| 80 | props.is_renaming = False |
| 81 | return |
| 82 | |
| 83 | element = tool.Ifc.get().by_id(props.ifc_definition_id) |
| 84 | if "/" in obj.name: |
| 85 | object_name = obj.name |
| 86 | element_name = obj.name.split("/", 1)[1] |
| 87 | else: |
| 88 | element_name = obj.name |
| 89 | object_name = element.is_a() + f"/{element_name}" |
| 90 | obj.name = object_name # NOTE: doesn't trigger infinite recursion |
| 91 | |
| 92 | if element.is_a("IfcGridAxis"): |
| 93 | element.AxisTag = object_name.split("/")[1] |
| 94 | refresh_ui_data() |
| 95 | |
| 96 | if not element.is_a("IfcRoot"): |
| 97 | return |
| 98 | element.Name = element_name |
| 99 | if props.collection: |
| 100 | props.collection.name = object_name |
| 101 | refresh_ui_data() |
| 102 | |
| 103 | |
| 104 | def active_object_callback(): |
nothing calls this directly
no test coverage detected