whats important about the screenshot is that the only selected object is the cube named selectednode. however when i remove the return statement instead of selecting the children of the cube it selects the 3 previously selected objects before the deselect all line. dose anybody know what might be happening? its frustrating cause im trying to turn my script that worked before into an addon
Without the actual blend file (and blender version) it’s going to be a bit hard to figure out what’s going.
Are you trying to select parented objects of cube? Your title has me confused.
import bpy
sel_node = bpy.context.active_object # or bpy.data.objects['selectednode']
view = bpy.context.view_layer
for o in view.objects:
# Deselect all objects that's not active object
if o != sel_node:
o.select_set(False)
# Check for objects parented to active object (selectednode)
if o.parent == sel_node:
# Select parented objects
o.select_set(True)
heres the blend file http://a.tmp.ninja/lcvV6sPeEw52.blend
lmk if the link expired(should be up 48 hours)
my blender version is 2.82
I am trying to select the cubes children but instead it selects the 3 items that are selected before i run bpy.ops.object.select_all(action=‘DESELECT’) to reiterate I know how to get that behaviour to work because when I run the script thats inside the main function as a standalone script it works 100% intended, it is only when its inside the main function
ok to anyone having this problem, i dont know what is causing it, but i have a workaround. I have been getting lines of code from the info tab, but it appears some commands execute different depending on whether you ran them through the console or an addon. my method of fixing this script was to stop selecting children from the already selected object, then storing them in a variable
bpy.context.view_layer.objects.active = bpy.data.objects['selectednode']
bpy.ops.object.select_hierarchy(direction='CHILD', extend=False)
child_objs = bpy.context.selected_objects
but to instead directing set the variable to the objects children property
child_objs = bpy.data.objects['selectednode'].children:
basically its better to implement script from the blender python docs than the info tab
With 2.83.3 based on your test file the selection of children of selectednode
works correctly for me with this script (which is based on your original screenshot):
import bpy
tempp = bpy.context.selected_objects
bpy.ops.object.select_hierarchy(direction='CHILD', extend=False)
temp = bpy.context.selected_objects
selected = []
for i in range(len(temp)):
selected.append(bpy.context.selected_objects[i].name)
bpy.context.view_layer.objects.active = bpy.data.objects['selectednode']
bpy.ops.object.select_all(action='DESELECT')
bpy.data.objects['selectednode'].select_set(True)
bpy.context.view_layer.objects.active = bpy.data.objects['selectednode']
if True:
bpy.ops.object.select_hierarchy(direction='CHILD', extend=False)