Unable to automate converting a duplicated and seperated mesh into a curve with python Code:
class CurveCreate(bpy.types.Operator):
    bl_idname = &quot;curve.create_operator&quot;
    bl_label = &quot;Curvecreate&quot;
    bl_description = &quot;Duplicates the selected edges and converts them into curves&quot;
    bl_options = {&quot;REGISTER&quot;}    

    def execute(self, context):
        bpy.ops.mesh.duplicate_move(MESH_OT_duplicate={&quot;mode&quot;:1}, TRANSFORM_OT_translate={&quot;value&quot;:(0, 0, 0), &quot;orient_type&quot;:'GLOBAL', &quot;orient_matrix&quot;:((0, 0, 0), (0, 0, 0), (0, 0, 0)), &quot;orient_matrix_type&quot;:'GLOBAL', &quot;constraint_axis&quot;:(False, False, False), &quot;mirror&quot;:False, &quot;use_proportional_edit&quot;:False, &quot;proportional_edit_falloff&quot;:'SMOOTH', &quot;proportional_size&quot;:1, &quot;use_proportional_connected&quot;:False, &quot;use_proportional_projected&quot;:False, &quot;snap&quot;:False, &quot;snap_target&quot;:'CLOSEST', &quot;snap_point&quot;:(0, 0, 0), &quot;snap_align&quot;:False, &quot;snap_normal&quot;:(0, 0, 0), &quot;gpencil_strokes&quot;:False, &quot;cursor_transform&quot;:False, &quot;texture_space&quot;:False, &quot;remove_on_cancel&quot;:False, &quot;release_confirm&quot;:False, &quot;use_accurate&quot;:False})       
        bpy.ops.mesh.separate(type='SELECTED')
        bpy.ops.object.mode_set(mode='OBJECT')
        bpy.ops.object.convert(target='CURVE')
        bpy.context.object.data.fill_mode = 'FULL'
        bpy.context.object.data.bevel_depth = 0.15
        bpy.context.object.data.bevel_resolution = 3
        bpy.context.object.data.splines[0].use_smooth = True
        
        self.report({'INFO'}, &quot;Curve Created !&quot;)
        return {&quot;FINISHED&quot;}


Question:
This is what I want to do:

What I want the code to do:

Duplicate the selected edges.
Separate the selected edges.
Go back to object mode.
Select the newly separated edges (this is what I cant do).
Convert the selected separated edges into curve.
Adjust some curve settings.

Now the problem is that when Step 3 has been executed that is, going back to object mode I find that the Active object is actually the cube and not the separated edges. Hence the remaining steps get applied to the cube instead. Both the cube and separated edges are already selected when returning to object mode but the cube is the actual Active object.
How do I set the newly separated edges as the Active object in this case?
Assume that you just selected one object to do the procedure:
Then after the separation, the new created object will be &quot;selected&quot; by default, but not active. You can check whether your selected object is not active, then that should be the one you've separated.
# After separation
C = bpy.context # select a correct context first
for obj in [
    o for o 
    in C.selected_objects 
    if o is not C.view_layer.objects.active #remove active object from list
]:
    C.view_layer.objects.active = obj
    # you can do further comparison here to make sure you select the right object
    break # Break before accessing other
# Do the rest of the code