Calling bpy.ops.mesh.shortest_path_pick from operator code

Hi, all.

Is there any way to use bpy.ops.mesh.shortest_path_pick from my custom operator code? I mean in 3d view it works from my last selected face and to the face I CTRL+click on. How do I achieve this from code, considering I have a field I want to select from and the field I want to select to.

Thanks.

The *_pick() operator requires a cursor location, but there’s another operator that works based on two selected faces:

import bpy
import bmesh
from random import sample

ob = bpy.context.object
me = ob.data
bm = bmesh.from_edit_mesh(me)

a, b = sample(range(len(bm.faces)), 2) # pick two random faces

bpy.ops.mesh.select_all(action='DESELECT')
bm.faces[a].select = True
bm.faces[b].select = True

bpy.ops.mesh.shortest_path_select()

bmesh.update_edit_mesh(me, False, False)

(you can test above script on a grid mesh in edit mode)

Thanks, Codeman, works like magic!