6
$\begingroup$

I'm trying to apply physics properties to multiple objects using following script:

for obj in bpy.data.objects:
     bpy.ops.rigidbody.object_add(type='ACTIVE')

but physics is applied only to the last object. Do you have any suggestions? I know how to copy physics using 'Copy from Active' but i need script.

$\endgroup$

2 Answers 2

3
$\begingroup$

Setup one object as template then the following code will set the template object as active object and select all objects. Finally bpy.ops.rigidbody.object_settings_copy() copies all attributes as the 'Copy from Active' button would do.

import bpy

scene = bpy.context.scene
scene.objects.active = bpy.data.objects["template"]  
for obj in scene.objects:
    if obj.type == 'MESH':
        obj.select = True


#bpy.ops.object.constraints_copy()
bpy.ops.rigidbody.object_settings_copy()
$\endgroup$
4
$\begingroup$

This should also do the trick:

import bpy

bpy.ops.rigidbody.object_add()

bpy.ops.rigidbody.object_settings_copy()

It adds rigid body to the active object and then copies the rigid body setting to all other selected objects

This will also make rigid body all the selected objects:

import bpy

bpy.ops.rigidbody.objects_add(type='ACTIVE')
$\endgroup$

You must log in to answer this question.

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