Script to store name of selected object / curve, so that I can select again I'm looking for a way to store selected object / curve name so that I can reference it in a script.

The idea is to select a curve (with the mouse), then copy another object to its location(with a script). I would also need to reference the original object so I can fill in some modifiers. Problems I'm having now: In order to duplicate that "other" object, I need to select it... which causes me to lose focus from the currently selected original object.

rough code is...

bpy.context.selected_objects 

bpy.data.objects['OBJ1'].select = True #select an already created object

bpy.ops.object.duplicate() #duplicate OBJ1

# move duplicated object to same place as originally selected.
# figure out a way to copy location info from original selection.
bpy.data.objects.new.location 

bpy.ops.object.modifier_add(type='ARRAY')
bpy.context.object.modifiers["Array"].fit_type = 'FIT_CURVE'

#curvename would be the original thing selected
bpy.context.object.modifiers["Array"].curve = bpy.data.objects[curveName]


Thank you very much for your help.
for the selection part of things: Why not simply make the user select both items in a specific order? Blender stores the objects in selection order in this property:

bpy.context.selected_objects


That means, if you first select a cube, then a sphere, then a circle, the property content will be:

[bpy.data.objects['Cube'], bpy.data.objects['Sphere'], bpy.data.objects['Circle']]


To access them, you could use the index:

bpy.context.selected_objects[0]  # = first selected object
bpy.context.selected_objects[1]  # = second selected object
bpy.context.selected_objects[-1]  # = last selected object


Also, the last selected object will be the active one:

bpy.context.active_object