How to make a certain object the active object from scripts

Hello :slight_smile:

Started python scripting for blender a few days ago to be able to make a exporter to a certain game. So far I’m just messing around and preparing the object for export.
Like that I stumbled upon a possable error, which I (so far) couldn’t fix by using the resources on the internet about blender 2.5+.
It’s the folowing :

  • How to make a object the active object?

I need to know this 'cause if I wish to join objects from script, and e.g. a lamp is the last user selected object, an error will be raised that lamp can’t be joined together with meshes.

This is the script so far :

import bpy

#-----If not in object mode ==> go to object mode-----1
if bpy.ops.object.mode_set.poll():

#-----If something other then the object is selected(like lamp etc), 
#       deselect it-----0
for currentelyLoopedObject in bpy.context.selected_objects[:]:
    if currentelyLoopedObject.type != "MESH":
        #make this object the active object to prevent
        #that e.g. the lamp remains the active one

#-----Make temperory object (copied) to prevent permanent changes-----1

#-----Join/merge temperory objects if multiple are selected-----1
if(len(bpy.context.selected_objects) > 1):

#-----Convert Quads meshes to Triangles-----1
bpy.ops.mesh.select_all(action = "SELECT")

It works like this: User selects meshes, scripts makes a copy from it, joins meshes, convert to triangles, export, delete temp. mesh

I’d also be happy to hear advices from you pro’s here if so far I’d have written it in a shabby way :slight_smile:

Thanks on advance

Edit: Sorry for posting in wrong section, really though I was inside Support :smiley:

Found it :), took some time, but this is what I used:
bpy.ops.object.select_name(name =

I know this is an old thread, but I’ll just add this for the sake of other people that came from a search like me. You can do this without an operator like this: =[“Cube”]

Unfortunately this function seems to have disappeared in Blender 2.62 :frowning:

you can now do similar things with


Yeah, at first I was disappointed, but pattern is actually more useful