Get the selection when creating the instance

This commit is contained in:
Simone Barbieri 2023-11-03 16:50:11 +00:00
parent 58c9664f7e
commit 821b478830

View file

@ -15,6 +15,8 @@ class CreateBlendScene(plugin.Creator):
family = "blendScene"
icon = "cubes"
maintain_selection = False
def process(self):
""" Run the creator on Blender main thread"""
mti = ops.MainThreadItem(self._process)
@ -38,4 +40,29 @@ class CreateBlendScene(plugin.Creator):
self.data['task'] = get_current_task_name()
lib.imprint(asset_group, self.data)
try:
area = next(
area for area in bpy.context.window.screen.areas
if area.type == 'OUTLINER')
region = next(
region for region in area.regions
if region.type == 'WINDOW')
except StopIteration as e:
raise RuntimeError("Could not find outliner. An outliner space "
"must be in the main Blender window.") from e
with bpy.context.temp_override(
window=bpy.context.window,
area=area,
region=region,
screen=bpy.context.window.screen
):
ids = bpy.context.selected_ids
for id in ids:
if isinstance(id, bpy.types.Collection):
asset_group.children.link(id)
elif isinstance(id, bpy.types.Object):
asset_group.objects.link(id)
return asset_group