Take the 2-minute tour ×
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It's 100% free, no registration required.

I have a mesh, and it has children. One of it's children is an Empty. I know there is a way to select an object by type using Python (and there's a button for it too) and it's this:

bpy.ops.object.select_by_type(type='EMPTY')

I was wondering if there was a way to deselect an object by type. Basically, I want to select the children of the mesh, then deselect the empty.

Thanks!

share|improve this question
    
How about select inverse, select by type, select inverse? –  WChargin May 18 at 4:30
    
That won't work, because I have other models in the scene. I just want the children of the current mesh without selecting the parent. I'll try to use one of the answers below. –  rioforce May 18 at 21:21

2 Answers 2

up vote 5 down vote accepted

I would suggest not to use bpy.ops and instead access the selection directly.

# assume you the active object is the parent
for obj in bpy.context.object.children:
    if obj.type != 'EMPTY':
        obj.select = True

This is a little more clever, you can do it recursively (to select children's children).

def select_children_recursive(obj_parent):
    for obj in obj_parent.children:
        select_children_recursive(obj)
        if obj.type != 'EMPTY':
            obj.select = True
# call the function
select_children_recursive(bpy.context.object)

Similar to above but caller can define types not to select

def select_children_recursive(obj_parent, type_mask):
    for obj in obj_parent.children:
        select_children_recursive(obj)
        if obj.type not in type_mask:
            obj.select = True
# call the function
select_children_recursive(bpy.context.object, {'EMPTY', 'LAMP'})
share|improve this answer
    
The first code box did the trick! –  rioforce May 18 at 21:30
    
Well, I am still having issues. It won't allow me to use bpy.context in my importer script. Any ideas? –  rioforce May 18 at 23:03
    
Please elaborate on "It won't allow me" –  ideasman42 May 19 at 1:52
    
Sorry, should have been more specific. :P I get an error that says "Context is incorrect". I've searched around, but no luck... –  rioforce May 19 at 18:14
    
@rioforce, Id need to see a link to full script and full stack trace. but this is probably another question. –  ideasman42 May 19 at 23:45

For your use case, something like this will work

import bpy

# go through the children of the parent object
for child in bpy.data.objects["Cube"].children:
    # if the child is not an empty, select it
    if child.type != 'EMPTY':
        child.select = True
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.