44from typing import Dict , List , Union
55
66import bpy
7+
78from ..lib import logger
89from . import pipeline
910
1011
11- def get_selection ():
12- return [obj for obj in bpy .context .scene .objects if obj .select_get ()]
13-
14-
1512def 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
134129def 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