2
$\begingroup$

I'm trying to write a script to add rigid body objects to all objects in the scene. I found this question helpful: How do I add a rigidbody to an object with python?

But when I try the solutions I get a 'context is incorrect' error. I have tried changing the context: bpy.context.area.type = "VIEW_3D" but I still get the error. What is the correct context?

$\endgroup$
  • $\begingroup$ Which operator is giving the error? You need to have a context.object or context.selected_objects to use rigidbody.object(s)_add $\endgroup$ – batFINGER Oct 21 '15 at 17:40
  • $\begingroup$ bpy.ops.rigidbody.world_add.poll() failed. I am unclear as to what I need to do with the context in order to add the rigid body world and the rigid body objects, and the documentation I've read has been confusing. $\endgroup$ – elu Oct 22 '15 at 23:11
  • $\begingroup$ You might find the script in my question helpful: blender.stackexchange.com/questions/49290/… I am stuck in a different place there, but adding a rigid_body works. $\endgroup$ – Amelse Etomer Mar 22 '16 at 20:42
1
$\begingroup$

This worked for me:

candidate_list = [item.name for item in bpy.data.objects if item.type == "MESH"]
for object_name in candidate_list:
    bpy.data.objects[object_name].select = True
bpy.ops.rigidbody.objects_add(type='ACTIVE')

In the loop it selects all the objects that you want to add rigid_body to. Then add them in one go.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.