Page MenuHome

bpy.data.objects.foreach_set("select", seq) does nothing
Closed, InvalidPublic

Description

foreach_get returns a list of 0 and 1, but trying to set the select state doesn't select them in view

Blender 2.63 official

>>> ob_len = len(bpy.data.objects)
>>> a = [None]*ob_len
>>> bpy.data.objects.foreach_get("select", a)
[0, 0, 1, 0, 1, 1]

>>> a = [1] * ob_len
>>> bpy.data.objects.foreach_set("select", a)
--> no change!

Details

Type
Bug

Event Timeline

Campbell, can you please look into this? Thanks :)

foreach_set is for low level data access, like setting vert locations in an array.
like the animation system, updates don't run here.

closing.

This task should not have been closed.
This is a bug and it would be nice to have fast access to the selection without have to use python iterators.

currently foreach_set('select', array) works for setting deselected vertices to selected.
However, it does not work for setting selected vertices to deselected.

I really think this should be looked at again.

Object selection state does not update in the viewport after calling foreach_set('select', array) even after updating with:

scene.frame_set(scene.frame_current)

However properties such as show_all_edges and hide update in the viewport using the exact same update method.
It seems like a bug unless the select property requires some special update method the other properties don't.

I noticed common behavior while working through the foreach_get on vertices for their selection state. My sample code is as follows:

import bpy
import numpy as np

C = bpy.context
ob = C.object
num_vertices = len(ob.data.vertices)
vertices_state = np.empty(num_vertices, dtype=bool)
ob.data.vertices.foreach_get('select', vertices_state)
print(vertices_state)

The above works only when the viewport shows object interaction mode as "Object Mode". When the view port shows "Edit Mode" then any selection (of vertices) made by the user is not visible by the above program unless the user goes to "Object Mode". Notice that you can always change the object interaction mode via bpy.ops.object.editmode_toggle(). Take a look at [1] and [2].

[1]: https://stackoverflow.com/questions/20349361/selected-vertex-did-not-highlight-in-blender-3d
[2]: https://docs.blender.org/api/blender_python_api_2_69_3/info_gotcha.html#modes-and-mesh-access