Skip to content
This repository was archived by the owner on Oct 10, 2024. It is now read-only.

Commit d6c554e

Browse files
committed
Merge branch 'release/2.6.0'
2 parents 2953ad4 + 6b68d2c commit d6c554e

File tree

31 files changed

+1370
-1055
lines changed

31 files changed

+1370
-1055
lines changed

avalon/blender/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
lsattrs,
2929
read,
3030
maintained_selection,
31+
get_selection,
3132
# unique_name,
3233
)
3334

@@ -54,5 +55,6 @@
5455
"lsattr",
5556
"lsattrs",
5657
"read",
58+
"get_selection",
5759
# "unique_name",
5860
]

avalon/blender/lib.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@
44
from typing import Dict, List, Union
55

66
import bpy
7+
78
from ..lib import logger
89
from . import pipeline
910

1011

11-
def get_selection():
12-
return [obj for obj in bpy.context.scene.objects if obj.select_get()]
13-
14-
1512
def imprint(node: bpy.types.bpy_struct_meta_idprop, data: Dict):
1613
r"""Write `data` to `node` as userDefined attributes
1714
@@ -53,10 +50,8 @@ def imprint(node: bpy.types.bpy_struct_meta_idprop, data: Dict):
5350
pipeline.metadata_update(node, imprint_data)
5451

5552

56-
def lsattr(
57-
attr: str,
58-
value: Union[str, int, bool, List, Dict, None] = None
59-
) -> List:
53+
def lsattr(attr: str,
54+
value: Union[str, int, bool, List, Dict, None] = None) -> List:
6055
r"""Return nodes matching `attr` and `value`
6156
6257
Arguments:
@@ -95,24 +90,19 @@ def lsattrs(attrs: Dict) -> List:
9590
# For now return all objects, not filtered by scene/collection/view_layer.
9691
matches = set()
9792
for coll in dir(bpy.data):
98-
nodes = getattr(bpy.data, coll, None)
9993
if not isinstance(
100-
nodes, bpy.types.bpy_prop_collection,
94+
getattr(bpy.data, coll),
95+
bpy.types.bpy_prop_collection,
10196
):
10297
continue
103-
for node in nodes:
98+
for node in getattr(bpy.data, coll):
10499
for attr, value in attrs.items():
105100
avalon_prop = node.get(pipeline.AVALON_PROPERTY)
106101
if not avalon_prop:
107102
continue
108-
109-
avalon_prop_val = avalon_prop.get(attr)
110-
if not avalon_prop_val:
111-
continue
112-
113-
if value is None or avalon_prop_val == value:
103+
if (avalon_prop.get(attr)
104+
and (value is None or avalon_prop.get(attr) == value)):
114105
matches.add(node)
115-
116106
return list(matches)
117107

118108

@@ -130,6 +120,11 @@ def read(node: bpy.types.bpy_struct_meta_idprop):
130120
return data
131121

132122

123+
def get_selection() -> List[bpy.types.Object]:
124+
"""Return the selected objects from the current scene."""
125+
return [obj for obj in bpy.context.scene.objects if obj.select_get()]
126+
127+
133128
@contextlib.contextmanager
134129
def maintained_selection():
135130
r"""Maintain selection during context
@@ -140,6 +135,7 @@ def maintained_selection():
140135
... bpy.ops.object.select_all(action='DESELECT')
141136
>>> # Selection restored
142137
"""
138+
143139
previous_selection = get_selection()
144140
previous_active = bpy.context.view_layer.objects.active
145141
try:

0 commit comments

Comments
 (0)