mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 02:02:22 +00:00
Fix critical bug where a user might override and break existing objects if they reused an object name
This commit is contained in:
@@ -155,14 +155,23 @@ class Root(blenderbim.core.tool.Root):
|
||||
profile_set_usage=profile_set_usage,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def set_element_specific_display_settings(cls, obj, element):
|
||||
if element.is_a("IfcOpeningElement"):
|
||||
obj.display_type = "WIRE"
|
||||
|
||||
@classmethod
|
||||
def set_object_name(cls, obj, element):
|
||||
name = obj.name
|
||||
if "/" in name and name.split("/")[0][0:3] == "Ifc":
|
||||
name = "/".join(name.split("/")[1:])
|
||||
obj.name = "{}/{}".format(element.is_a(), name)
|
||||
name = "{}/{}".format(element.is_a(), name)
|
||||
|
||||
# By default, if another object with the same name exists, the existing
|
||||
# object becomes Foo.001 and the new object becomes Foo. However, if we
|
||||
# also had a collection that was named Foo, it wouldn't change to
|
||||
# Foo.001. This code ensures existing objects and their corresponding
|
||||
# collections stay in sync.
|
||||
existing_obj = bpy.data.objects.get(name)
|
||||
existing_collection = bpy.data.collections.get(name)
|
||||
|
||||
obj.name = name
|
||||
|
||||
if existing_obj:
|
||||
if existing_collection:
|
||||
existing_collection.name = existing_obj.name
|
||||
|
||||
Reference in New Issue
Block a user