python duplicate_move and snap_selected_to_cursor fails; context is incorrect I'm new to blender and python.  I thought I'd duplicate a cube I have at (-1, 0, 0 ) and snap it to my 3d cursor, which is at world origin.  Using the scripting view, I created commands found from the console
object = bpy.data.objects[&quot;MyCube&quot;]
object.select_set(True)
selectedObject = bpy.context.selected_objects
print( &quot;selectedObject = &quot; + str(selectedObject))

bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY', center='MEDIAN')

bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={&quot;linked&quot;:False, &quot;mode&quot;:'TRANSLATION'}, TRANSFORM_OT_translate={&quot;value&quot;:(0, 0, 0), &quot;orient_type&quot;:'GLOBAL', &quot;orient_matrix&quot;:((1, 0, 0), (0, 1, 0), (0, 0, 1)), &quot;orient_matrix_type&quot;:'GLOBAL', &quot;constraint_axis&quot;:(False, False, False), &quot;mirror&quot;:True, &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, &quot;use_automerge_and_split&quot;:False})

context = bpy.context.area.type
print(&quot;Area Type = &quot; + str(context))

bpy.ops.view3d.snap_selected_to_cursor(use_offset=False)

which outputs:
selectedObject = [bpy.data.objects['MyCube']]
Area Type = TEXT_EDITOR
Traceback (most recent call last):
  File &quot;D:\BlenderWork\Projects\TestOrWork\Cube20.blend\Text&quot;, line 38, in &lt;module&gt;
  File &quot;C:\Program Files\Blender Foundation\Blender 2.91\2.91\scripts\modules\bpy\ops.py&quot;, line 132, in __call__
    ret = _op_call(self.idname_py(), None, kw)
RuntimeError: Operator bpy.ops.view3d.snap_selected_to_cursor.poll() failed, context is incorrect

I'm assuming that this is happening because my area type is TEXT_EDITOR, which is where my script is running, NOT the 3dview.
Apparently more is needed then simply 'doing stuff' in the 3dview and copy/pasting commands into a script.
How do I fix this?  Thanks in advance
Figured it out - I needed to add
bpy.context.area.type = 'VIEW_3D'
to switch from the text editor to the 3dview, before snap_selected_to_cursor.