0
$\begingroup$

What is the non context depended way for adding physics to blender scene ?

at the moment i`m forced to select a scene and then use the ops function:

bpy.context.window.scene = bpy.data.scenes['Some_Scene']

bpy.ops.rigidbody.world_add()

thank you.

$\endgroup$
2

1 Answer 1

2
$\begingroup$

No, there isn't. world_add ends up calling a C routine BKE_rigidbody_create_world that is not otherwise exposed through the bpy API.

You would have to select a scene even if the C routine had a Python interface, because the rigid body world is attached to a specific scene, and the caller of the C routine would have to know which one.

If you wanted to add a rigid body world to a specific scene and didn't want to change the context, you could use a context override:

override = {
    'scene' : bpy.data.scenes['Scene']
}

bpy.ops.rigidbody.world_add(override)

replacing 'Scene' with the name of the scene you wanted to add the world to.

3.2 Update

Context overrides are deprecated in Blender 3.2 and are scheduled to be removed in Blender 3.3 The replacement is temp_override. The manual has examples of how to use the new function.

$\endgroup$
5
  • $\begingroup$ Thanks mate, I can reference the scene as object - why it should be active ? and if i must,it brings me to write this question blender.stackexchange.com/questions/265266/… Do you think blender guys will change this design limitations in the future ? $\endgroup$
    – barakooda
    Jun 1, 2022 at 15:17
  • $\begingroup$ It doesn't always have to be active. You might be able to use a context override in the call. Not every bpy op allows context overrides, but this one might. $\endgroup$ Jun 1, 2022 at 15:23
  • $\begingroup$ Same None :-( or maybe i do somthing wrong. using bpy.context.copy() gives {...'window': None, 'window_manager': bpy.data.window_managers['WinMan'], ... } $\endgroup$
    – barakooda
    Jun 1, 2022 at 15:26
  • 1
    $\begingroup$ @barakooda I updated the answer to show how to do it with an override. $\endgroup$ Jun 1, 2022 at 15:37
  • $\begingroup$ Thanks mate! This override trick really helps ! will use it more. $\endgroup$
    – barakooda
    Jun 1, 2022 at 15:53

You must log in to answer this question.

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