I'm trying to understand how selections and active objects work within a context. I thought I understood that a selection is part of a context. I read somewhere that you can create a copy of a context (context.copy()) in order to avoid changing the user's actual selections.
Some code I've seen fits this concept, such as..
context['selected_objects'] = list
context['active_object'] = object
But other code I've seen does not, such as..
object.select = False
bpy.ops.object.select_all(action='DESELECT')
Would anyone be able to help me understand what's happening behind the scenes? I can't imagine how object.select = False
can be triggering any state changes inside of a context? Perhaps objects have their own selection states, but they can be overridden by a context? Or maybe the things I read were completely wrong?
Thanks!
Edit: It appears that part of my issue is that Blender keeps changing the syntax and setup of how selections work. It looks like they are now part of the view layer. But if I make a copy of the context, Blender reports that it doesn't even have a view layer. Does anyone know how to properly copy the context and select/activate objects with the copy?
obj.select = Bool
is replaced byobj.select_get()
andobj.select_set()
. Context should track all change inside it, I guess $\endgroup$ – Hikariztw Sep 7 at 0:52bpy.context.view_layer
. But if I copy the context withcopy= bpy.context.copy()
, my copy does not seem to have a view layer atcopy.view_layer
. Can anyone help me understand why? Or just how to use a context override correctly? $\endgroup$ – Robert Sep 7 at 12:12bpy.ops.object.delete({"selected_objects": objs})
, good read: poll() failed, context incorrect?. Otherwise all operator methods already provide the current context (default argument):def execute(self, context):
so don't worry about that too much. More about selection in 2.8 here: Python: Selecting object by name in 2.8 $\endgroup$ – brockmann Sep 7 at 17:09