Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Blender: Fix 'Deselect All' with object not in 'Object Mode' #2163

Merged
merged 2 commits into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions openpype/hosts/blender/api/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,30 @@ def get_local_collection_with_name(name):
return None


def deselect_all():
"""Deselect all objects in the scene.

Blender gives context error if trying to deselect object that it isn't
in object mode.
"""
modes = []
active = bpy.context.view_layer.objects.active

for obj in bpy.data.objects:
if obj.mode != 'OBJECT':
modes.append((obj, obj.mode))
bpy.context.view_layer.objects.active = obj
bpy.ops.object.mode_set(mode='OBJECT')

bpy.ops.object.select_all(action='DESELECT')

for p in modes:
bpy.context.view_layer.objects.active = p[0]
bpy.ops.object.mode_set(mode=p[1])

bpy.context.view_layer.objects.active = active


class Creator(PypeCreatorMixin, blender.Creator):
pass

Expand Down
4 changes: 2 additions & 2 deletions openpype/hosts/blender/plugins/load/load_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _remove(self, asset_group):
bpy.data.objects.remove(empty)

def _process(self, libpath, asset_group, group_name):
bpy.ops.object.select_all(action='DESELECT')
plugin.deselect_all()

collection = bpy.context.view_layer.active_layer_collection.collection

Expand Down Expand Up @@ -109,7 +109,7 @@ def _process(self, libpath, asset_group, group_name):
avalon_info = obj[AVALON_PROPERTY]
avalon_info.update({"container_name": group_name})

bpy.ops.object.select_all(action='DESELECT')
plugin.deselect_all()

return objects

Expand Down
4 changes: 2 additions & 2 deletions openpype/hosts/blender/plugins/load/load_fbx.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _remove(self, asset_group):
bpy.data.objects.remove(obj)

def _process(self, libpath, asset_group, group_name, action):
bpy.ops.object.select_all(action='DESELECT')
plugin.deselect_all()

collection = bpy.context.view_layer.active_layer_collection.collection

Expand Down Expand Up @@ -112,7 +112,7 @@ def _process(self, libpath, asset_group, group_name, action):
avalon_info = obj[AVALON_PROPERTY]
avalon_info.update({"container_name": group_name})

bpy.ops.object.select_all(action='DESELECT')
plugin.deselect_all()

return objects

Expand Down
2 changes: 1 addition & 1 deletion openpype/hosts/blender/plugins/load/load_layout_blend.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def _process(self, libpath, asset_group, group_name, actions):

bpy.data.orphans_purge(do_local_ids=False)

bpy.ops.object.select_all(action='DESELECT')
plugin.deselect_all()

return objects

Expand Down
2 changes: 1 addition & 1 deletion openpype/hosts/blender/plugins/load/load_layout_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def _get_loader(self, loaders, family):
return None

def _process(self, libpath, asset, asset_group, actions):
bpy.ops.object.select_all(action='DESELECT')
plugin.deselect_all()

with open(libpath, "r") as fp:
data = json.load(fp)
Expand Down
6 changes: 3 additions & 3 deletions openpype/hosts/blender/plugins/load/load_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def _process(self, libpath, asset_group, group_name):

bpy.data.orphans_purge(do_local_ids=False)

bpy.ops.object.select_all(action='DESELECT')
plugin.deselect_all()

return objects

Expand Down Expand Up @@ -126,7 +126,7 @@ def process_asset(
asset_group.empty_display_type = 'SINGLE_ARROW'
avalon_container.objects.link(asset_group)

bpy.ops.object.select_all(action='DESELECT')
plugin.deselect_all()

if options is not None:
parent = options.get('parent')
Expand Down Expand Up @@ -158,7 +158,7 @@ def process_asset(

bpy.ops.object.parent_set(keep_transform=True)

bpy.ops.object.select_all(action='DESELECT')
plugin.deselect_all()

objects = self._process(libpath, asset_group, group_name)

Expand Down
8 changes: 4 additions & 4 deletions openpype/hosts/blender/plugins/load/load_rig.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def _process(self, libpath, asset_group, group_name, action):
while bpy.data.orphans_purge(do_local_ids=False):
pass

bpy.ops.object.select_all(action='DESELECT')
plugin.deselect_all()

return objects

Expand Down Expand Up @@ -191,7 +191,7 @@ def process_asset(

action = None

bpy.ops.object.select_all(action='DESELECT')
plugin.deselect_all()

create_animation = False

Expand Down Expand Up @@ -227,7 +227,7 @@ def process_asset(

bpy.ops.object.parent_set(keep_transform=True)

bpy.ops.object.select_all(action='DESELECT')
plugin.deselect_all()

objects = self._process(libpath, asset_group, group_name, action)

Expand All @@ -250,7 +250,7 @@ def process_asset(
data={"dependencies": str(context["representation"]["_id"])}
)

bpy.ops.object.select_all(action='DESELECT')
plugin.deselect_all()

bpy.context.scene.collection.objects.link(asset_group)

Expand Down
4 changes: 2 additions & 2 deletions openpype/hosts/blender/plugins/publish/extract_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def process(self, instance):
# Perform extraction
self.log.info("Performing extraction..")

bpy.ops.object.select_all(action='DESELECT')
plugin.deselect_all()

selected = []
asset_group = None
Expand All @@ -50,7 +50,7 @@ def process(self, instance):
flatten=False
)

bpy.ops.object.select_all(action='DESELECT')
plugin.deselect_all()

if "representations" not in instance.data:
instance.data["representations"] = []
Expand Down
4 changes: 2 additions & 2 deletions openpype/hosts/blender/plugins/publish/extract_fbx.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def process(self, instance):
# Perform extraction
self.log.info("Performing extraction..")

bpy.ops.object.select_all(action='DESELECT')
plugin.deselect_all()

selected = []
asset_group = None
Expand Down Expand Up @@ -60,7 +60,7 @@ def process(self, instance):
add_leaf_bones=False
)

bpy.ops.object.select_all(action='DESELECT')
plugin.deselect_all()

for mat in new_materials:
bpy.data.materials.remove(mat)
Expand Down