How to select the last created object as the active object?

I am very new at scripting and I am pretty lost. I want my script being able to duplicate the selected faces then separate it to a new object using separate-selection, and then make the new object as the active. Thanks for your attention

Try this:

import bpy

actob = bpy.context.active_object



bpy.ops.object.editmode_toggle() = actob


bpy.ops.object.parent_set(type='OBJECT', keep_transform=False)

for actob in actob.children: = True = actob
bpy.ops.object.select_all(action='DESELECT') = True

@Albertofx This is incredible, so smart and simple :smiley:

For anyone that doesn’t code, just slap a bpy.ops.object.mode_set(mode=‘EDIT’, toggle=False) at the end and you have a perfect
extract script.