Python scripted button select hierarchy parent and children at same time

Hi there.

I was wondering if there was a way to select the parent and children at the same time of a group of objects that has been parented in the hierarchy? Not the groups coloured green but the groups that are connected with dotted lines in 3d view.

My aim is to create a button using a script that will select both the parent and it’s children at the same time without using the keyboard shortcuts.

You can ctrl+click the icon of the parent object in the outliner for that.

Hi Lumpengnom.

Unfortunately the outliner doesn’t scroll down to the object I selected in 3D view so I would have to scroll the outliner to do this and needing press ctrl whereas, I could have a panel left of a 3D view with my custom tab and button showing then all I do is, select parent in 3D view then press my button.

In the Outliner you can press the “comma” key (which is perhaps the “period” key on US Keyboards) on of the Numpad to jump to the object which is active in the viewport.

Otherwise, if you want a python solution you could use the following code and associate it with a button.

import bpy

myObj = bpy.context.active_object
bpy.ops.object.select_grouped(type='CHILDREN_RECURSIVE')
myObj.select = True
3 Likes

The python solution is just what I was after. Works fine with a button.

Cheers.