I would like to use this method, but I totally stucked.
A.py
myPath=r"C:\tem\B.py"
text = bpy.data.texts.load(myPath)
ctx = bpy.context.copy()
ctx['edit_text'] = text
bpy.ops.text.run_script(ctx)
B.py
import bpy
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_mode(type="FACE")
When I call A.py, bpy.ops.mesh.select_mode(type="FACE")
say,
"RuntimeError: Operator bpy.ops.mesh.select_mode.poll() failed, context is incorrect"
When I call B.py from text editor directly, it is fine. So, I'm really confusing.
---Edit and add explanation--------------------
When the object is "object mode", I run B.py directly and it run correct. When the same situation, I run A.py to run B.py, B.py say, "bpy.ops.mesh.select_mode.poll() failed".
B.py has bpy.ops.object.mode_set(mode='EDIT') difinitely, and changed the select mode correctly. But the "mesh.select_mode" is failed, if B.py is called from A.py.
bpy.ops.object.mode_set(mode='EDIT')
difinitely, and changed the select mode correctly. But the "mesh.select_mode" is failed, if B.py is called from A.py. $\endgroup$