I would like to duplicate a mesh object, but on a particular object. Right now this is working:

import bpy 

for i in range (0,5):

The way I want it to do it though is that the script should only duplicate a particular object in the scene that I enter through as a string name. ATM its just duplicating the 1st object and duplicating the duplicates of the duplicates.


The operator bpy.ops.object.duplicate() will duplicate the selected objects and then make the new duplicate objects selected while de-selecting the original objects. The operator is designed for user interaction which actually leaves the user moving the new duplicates when it is done (when started through the gui).

A better way to create a copy of an object by script is to use the copy() method available to most datablocks and then link it the the scene with scene.objects.link(). Note that the new object will use the same mesh datablock as the original, you can duplicate that as well while you are creating copies, you may also want to consider other data such as particle systems and materials. Instead of starting with the active object you can also specify an exact object with src_obj = bpy.data.objects['Cube']

import bpy

scn = bpy.context.scene
src_obj = bpy.context.active_object

for i in range (0,5):
    new_obj = src_obj.copy()
    new_obj.data = src_obj.data.copy()
| improve this answer | |
  • $\begingroup$ this does not copy the rigidbody $\endgroup$ – sliders_alpha May 8 '18 at 21:26
  • 1
    $\begingroup$ @sliders_alpha Actually the rigid body setting do get copied, but the new object doesn't get added to the rigid body group. Try adding bpy.data.groups['RigidBodyWorld'].objects.link(new_obj) inside the loop. $\endgroup$ – sambler May 9 '18 at 5:48

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