Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blender 2.6: Select object by name through Python

Tags:

How do you select objects by name through Python in Blender 2.6?

In 2.4-2.5, one could simply use:

bpy.ops.object.select_name("OBJECT") 

... but this has been discontinued in 2.6, to be replaced by what?


In 2.6, one can get the currently selected objects like so...

bpy.context.selected_objects 

And there's a way to set the scene's active object...

bpy.context.scene.objects.active = bpy.data.objects["OBJECT"] 

And one can also select via operations, like select_all() or select_by_type()...

bpy.ops.object.select_all(action="TOGGLE") 

But I can't find a way to select simply by name.

Thanks very much.

like image 568
Jollywatt Avatar asked Oct 20 '13 00:10

Jollywatt


People also ask

How do you select an object from a list in Python?

To select elements from a Python list, we will use list. append(). We will create a list of indices to be accessed and the loop is used to iterate through this index list to access the specified element. And then we add these elements to the new list using an index.


2 Answers

bpy.data.objects['OBJECT'].select = True 

Selection data is contained within the individual objects. You can read and write them as shown. In a slightly more readable form:

object = bpy.data.objects['OBJECT'] object.select = True 
like image 87
Jollywatt Avatar answered Sep 23 '22 13:09

Jollywatt


bpy.ops.object.select_name() has been replaced by bpy.ops.object.select_pattern() (around 2.62, I think?), which is a more powerful version (it can select an exact name, but also use patterns with wildcards, be case-insensitive, etc.):

bpy.ops.object.select_pattern(pattern="Cube") 
like image 36
mont29 Avatar answered Sep 23 '22 13:09

mont29