class OUTLINER_OT_duplicate_hierarchy(Operator):
bl_idname = "outliner.duplicate_hierarchy"
bl_label = "Duplicate Hierarchy"
bl_description = '''Duplicate selected objects with respecting the hierarchy'''
bl_options = { 'REGISTER', 'UNDO' }
def execute(self, context):
bpy.ops.object.mode_set(mode = 'OBJECT')
selection_names = [obj.name for obj in bpy.context.selected_objects]
for o in selection_names:
obj = bpy.context.scene.objects.get(o)
bpy.context.view_layer.objects.active = obj
obj.select_set(True)
bpy.ops.object.select_grouped(extend=True, type='CHILDREN_RECURSIVE')
bpy.ops.object.duplicate()
return { 'FINISHED' }
obj.select_set(True) to obj.select_set(False)
and it will duplicate only children.
You can just copy this code for your own script somewhere.
Or just copy this modified variant:
Summary
class OUTLINER_OT_duplicate_children(Operator):
bl_idname = "outliner.duplicate_children"
bl_label = "Duplicate Children"
bl_description = '''Duplicate only children objects in selected objects'''
bl_options = { 'REGISTER', 'UNDO' }
def execute(self, context):
bpy.ops.object.mode_set(mode = 'OBJECT')
selection_names = [obj.name for obj in bpy.context.selected_objects]
for o in selection_names:
obj = bpy.context.scene.objects.get(o)
bpy.context.view_layer.objects.active = obj
obj.select_set(False)
bpy.ops.object.select_grouped(extend=True, type='CHILDREN_RECURSIVE')
bpy.ops.object.duplicate()
return { 'FINISHED' }
Also variant with checkbox, but need to run from 3d view if you want “Adjust last operation” panel appeared. Need manually add keymap outliner.duplicate_hierarchy to “3D View - 3D View (Global)”
class OUTLINER_OT_duplicate_hierarchy(Operator):
bl_idname = "outliner.duplicate_hierarchy"
bl_label = "Duplicate Hierarchy"
bl_description = '''Duplicate selected objects with hierarchy'''
bl_options = { 'REGISTER', 'UNDO' }
children_only: bpy.props.BoolProperty (name="Children Only", default = False, description="Duplicate only children objects")
def execute(self, context):
bpy.ops.object.mode_set(mode = 'OBJECT')
selection_names = [obj.name for obj in bpy.context.selected_objects]
for o in selection_names:
obj = bpy.context.scene.objects.get(o)
bpy.context.view_layer.objects.active = obj
if self.children_only == True:
obj.select_set(False)
if self.children_only == False:
obj.select_set(True)
bpy.ops.object.select_grouped(extend=True, type='CHILDREN_RECURSIVE')
bpy.ops.object.duplicate()
return { 'FINISHED' }
Very cool stuff, I installed your addon and tested it out. Working with Machin3 tool “Groups” though already gives me the functionality to automatically select the whole hierarchy by default.
In my opinion selecting the top node of a hierarchy and hitting either delete or duplicate should duplicate or delete the whole hierarchy by default. But that might be my Maya background
While shift + d is a nice hack , Blender’s outliner still needs the standard way of duplicate things, which is by pressing a modifier key (usually ctrl or shift) + clicking and dragging the item…
Even in the viewport we should be able to do that too…