mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 02:02:22 +00:00
split_by_loose_parts to preserve the objects selection
Noticed that bim.assign_class started to loose the objects selection after 29d6d2b
This commit is contained in:
@@ -538,6 +538,13 @@ class Blender(bonsai.core.tool.Blender):
|
||||
else:
|
||||
cls.clear_active_object()
|
||||
|
||||
@classmethod
|
||||
def get_objects_selection(
|
||||
cls, context: bpy.types.Context
|
||||
) -> tuple[bpy.types.Context, Union[bpy.types.Object, None], list[bpy.types.Object]]:
|
||||
"""Get objects selection to later pass to `set_objects_selection`."""
|
||||
return context, context.view_layer.objects.active, context.selected_objects
|
||||
|
||||
@classmethod
|
||||
def set_objects_selection(
|
||||
cls,
|
||||
|
||||
@@ -1591,6 +1591,9 @@ class Geometry(bonsai.core.tool.Geometry):
|
||||
|
||||
@classmethod
|
||||
def split_by_loose_parts(cls, obj: bpy.types.Object) -> List[bpy.types.Mesh]:
|
||||
# Before .copy() since it also copies the selection.
|
||||
selection = tool.Blender.get_objects_selection(bpy.context)
|
||||
|
||||
dup_obj = obj.copy()
|
||||
dup_obj.data = obj.data.copy()
|
||||
bpy.context.scene.collection.objects.link(dup_obj)
|
||||
@@ -1607,6 +1610,8 @@ class Geometry(bonsai.core.tool.Geometry):
|
||||
results.append(obj.data)
|
||||
bpy.data.objects.remove(obj)
|
||||
|
||||
# Preserve original selection.
|
||||
tool.Blender.set_objects_selection(*selection)
|
||||
return results
|
||||
|
||||
@classmethod
|
||||
|
||||
Reference in New Issue
Block a user