I make an addon that open a new clean file, but after i open the new file, i get an error after the code try to run this line: bpy.ops.import_scene.fbx(filepath = path)
here is the error that i get: RuntimeError: Operator bpy.ops.object.mode_set.poll() Context missing active object
Thx, i know that i should avoid ops, but i dont think i can in this caseâŚ
I will try to use the context override, but i dont understand why it should help in this case?
if i try to run this code without open a new file, its work fine, but after i open the new file its not work anymore, so i try to understand what are the different in the context before and after the new file was open
Your error makes it sound like you have to have an active object for this script to work, and Iâm guessing your new scene doesnât have an active object
If youâre using Blender 3.2+, try using temp_override() instead.
import bpy
for w in bpy.context.window_manager.windows:
s = w.screen
for a in s.areas:
if a.type == "VIEW_3D":
with bpy.context.temp_override(window=w, area=a):
bpy.ops.import_scene.fbx(filepath="D:\\Assets\\untitled.fbx")
break
Itâs odd. As I discovered in this thread, the older context override API donât seem to not work anymore. I wonder if they get officially deprecated, starting Blender 3.2 and after.
Youâre right that if I read his code and understand it, it could help me. but I also want to have the ability to use his code only by using the ops command. Most of the time the ops command for this command is working, but my problem was that after I open a new file it stop working anymore (and not only this ops, all the ops donât have context so they donât work after thatâŚ)
1first: you must verify if this io_scene_fbx addon is present and if is activated before to use this ops.
2nd:
so Itâs that you donât answer his last question: Blender answer something!
No, you must respect the context to use this ops. If you open a new file, you must return on a clean context.
Example: when you import a fbx file, blender 3.2 return automatically this:
bpy.ops.object.select_all(action=âDESELECTâ)
I tryed to import 3x FBX files and I had no problem.