0

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.

Mrfas
  • 47
  • 6
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – TheLabCat Sep 25 '22 at 02:58
  • 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.

    – Mrfas Sep 25 '22 at 09:21

1 Answers1

0

The answer to the linked question is from 2015 and the method to overwrite a context just changed with Blender 3.3.

In Blender 3.3, you have to change the last three lines of A.py to

import bpy

myPath=r"C:\tem\B.py"

text = bpy.data.texts.load(myPath)

with bpy.context.temp_override(edit_text=text): bpy.ops.text.run_script()

Blunder
  • 13,925
  • 4
  • 13
  • 36
  • I update my blender 3.1->3.3 and your script and B.py goes fine. Thank you! (I don't know actually, but I feel 3.1 had a bit weird action) – Mrfas Sep 25 '22 at 13:20