1
$\begingroup$

I used to use bpy.ops.import_scene.obj() in my addon. which can import .obj object and set it a selected object.(not active)

But in Blender 4.0. this does not work any more.

I know the code bpy.ops.wm.obj_import() does the similar thing. but this code import an obj and set it active which I do not wish.

So I want to know what is the bpy.ops.import_scene.obj() in Blender 4.0, or is there a way to change the bpy.ops.wm.obj_import() code not import an obj in active mode?

$\endgroup$

1 Answer 1

1
$\begingroup$

On the operator side, I don't think there is a way to get the behavior of the old operator using the new operator which replaces the old one in Blender 4.0. However, I think it's relatively easy to save the active object before running the operator, and restore it after it finishes.

Something like this:

active_object = bpy.context.active_object
# Run bpy.ops.wm.obj_import()
bpy.context.view_layer.objects.active = active_object
$\endgroup$
1
  • $\begingroup$ Thank you!It works! Best!!! $\endgroup$
    – liuran
    Nov 24, 2023 at 1:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .