mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
Merge pull request #2163 from simonebarbieri/bugfix/blender-fix_unselect_all
This commit is contained in:
commit
28780ae969
9 changed files with 41 additions and 17 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ class CacheModelLoader(plugin.AssetLoader):
|
|||
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
|
||||
|
||||
|
|
@ -109,7 +109,7 @@ class CacheModelLoader(plugin.AssetLoader):
|
|||
avalon_info = obj[AVALON_PROPERTY]
|
||||
avalon_info.update({"container_name": group_name})
|
||||
|
||||
bpy.ops.object.select_all(action='DESELECT')
|
||||
plugin.deselect_all()
|
||||
|
||||
return objects
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class FbxModelLoader(plugin.AssetLoader):
|
|||
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
|
||||
|
||||
|
|
@ -112,7 +112,7 @@ class FbxModelLoader(plugin.AssetLoader):
|
|||
avalon_info = obj[AVALON_PROPERTY]
|
||||
avalon_info.update({"container_name": group_name})
|
||||
|
||||
bpy.ops.object.select_all(action='DESELECT')
|
||||
plugin.deselect_all()
|
||||
|
||||
return objects
|
||||
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ class BlendLayoutLoader(plugin.AssetLoader):
|
|||
|
||||
bpy.data.orphans_purge(do_local_ids=False)
|
||||
|
||||
bpy.ops.object.select_all(action='DESELECT')
|
||||
plugin.deselect_all()
|
||||
|
||||
return objects
|
||||
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ class JsonLayoutLoader(plugin.AssetLoader):
|
|||
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)
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ class BlendModelLoader(plugin.AssetLoader):
|
|||
|
||||
bpy.data.orphans_purge(do_local_ids=False)
|
||||
|
||||
bpy.ops.object.select_all(action='DESELECT')
|
||||
plugin.deselect_all()
|
||||
|
||||
return objects
|
||||
|
||||
|
|
@ -126,7 +126,7 @@ class BlendModelLoader(plugin.AssetLoader):
|
|||
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')
|
||||
|
|
@ -158,7 +158,7 @@ class BlendModelLoader(plugin.AssetLoader):
|
|||
|
||||
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)
|
||||
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ class BlendRigLoader(plugin.AssetLoader):
|
|||
while bpy.data.orphans_purge(do_local_ids=False):
|
||||
pass
|
||||
|
||||
bpy.ops.object.select_all(action='DESELECT')
|
||||
plugin.deselect_all()
|
||||
|
||||
return objects
|
||||
|
||||
|
|
@ -191,7 +191,7 @@ class BlendRigLoader(plugin.AssetLoader):
|
|||
|
||||
action = None
|
||||
|
||||
bpy.ops.object.select_all(action='DESELECT')
|
||||
plugin.deselect_all()
|
||||
|
||||
create_animation = False
|
||||
|
||||
|
|
@ -227,7 +227,7 @@ class BlendRigLoader(plugin.AssetLoader):
|
|||
|
||||
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)
|
||||
|
||||
|
|
@ -250,7 +250,7 @@ class BlendRigLoader(plugin.AssetLoader):
|
|||
data={"dependencies": str(context["representation"]["_id"])}
|
||||
)
|
||||
|
||||
bpy.ops.object.select_all(action='DESELECT')
|
||||
plugin.deselect_all()
|
||||
|
||||
bpy.context.scene.collection.objects.link(asset_group)
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ class ExtractABC(api.Extractor):
|
|||
# Perform extraction
|
||||
self.log.info("Performing extraction..")
|
||||
|
||||
bpy.ops.object.select_all(action='DESELECT')
|
||||
plugin.deselect_all()
|
||||
|
||||
selected = []
|
||||
asset_group = None
|
||||
|
|
@ -50,7 +50,7 @@ class ExtractABC(api.Extractor):
|
|||
flatten=False
|
||||
)
|
||||
|
||||
bpy.ops.object.select_all(action='DESELECT')
|
||||
plugin.deselect_all()
|
||||
|
||||
if "representations" not in instance.data:
|
||||
instance.data["representations"] = []
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ class ExtractFBX(api.Extractor):
|
|||
# Perform extraction
|
||||
self.log.info("Performing extraction..")
|
||||
|
||||
bpy.ops.object.select_all(action='DESELECT')
|
||||
plugin.deselect_all()
|
||||
|
||||
selected = []
|
||||
asset_group = None
|
||||
|
|
@ -60,7 +60,7 @@ class ExtractFBX(api.Extractor):
|
|||
add_leaf_bones=False
|
||||
)
|
||||
|
||||
bpy.ops.object.select_all(action='DESELECT')
|
||||
plugin.deselect_all()
|
||||
|
||||
for mat in new_materials:
|
||||
bpy.data.materials.remove(mat)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue