Solved producing orphan objects data on drawing deletion

This commit is contained in:
Andrej730
2023-04-08 11:36:59 +05:00
parent 2dcc271dff
commit 9bca705dc3
+14 -1
View File
@@ -146,7 +146,20 @@ class Drawing(blenderbim.core.tool.Drawing):
tool.Ifc.delete(element) tool.Ifc.delete(element)
obj = tool.Ifc.get_object(element) obj = tool.Ifc.get_object(element)
if obj: if obj:
obj_data = obj.data
bpy.data.objects.remove(obj) bpy.data.objects.remove(obj)
if obj_data.users == 0: # in case we have drawing element types
cls.remove_object_data(obj_data)
@classmethod
def remove_object_data(cls, data):
"""also removes all related objects"""
if isinstance(data, bpy.types.Camera):
bpy.data.cameras.remove(data)
elif isinstance(data, bpy.types.Mesh):
bpy.data.meshes.remove(data)
elif isinstance(data, bpy.types.Curve):
bpy.data.curves.remove(C.object.data)
@classmethod @classmethod
def delete_object(cls, obj): def delete_object(cls, obj):
@@ -1244,7 +1257,7 @@ class Drawing(blenderbim.core.tool.Drawing):
# sync viewport objects visibility with selectors from EPset_Drawing/Include and /Exclude # sync viewport objects visibility with selectors from EPset_Drawing/Include and /Exclude
drawing_elements = cls.get_drawing_elements(tool.Ifc.get_entity(camera)) drawing_elements = cls.get_drawing_elements(tool.Ifc.get_entity(camera))
for element in tool.Ifc.get().by_type("IfcElement"): for element in tool.Ifc.get().by_type("IfcElement"):
if element.is_a() in ("IfcOpeningElement", ): if element.is_a() in ("IfcOpeningElement",):
continue continue
obj = tool.Ifc.get_object(element) obj = tool.Ifc.get_object(element)