1

I have two large objects on my scene.

CAM = a large cone with four sides, more like a camera, made out of scaling a generic cone
Target = a large rectangular object, made out of scaling a simple 4 sided cube

I am trying to make 5 copies of them. I am running the following scripts -

import bpy

getting the objects

context = bpy.context scene = context.scene tar = bpy.data.objects['Target'] cam =bpy.data.objects['CAM']

for i in range(5): # copying the Target object copied_object = bpy.data.objects.new(str("Target"+str(i)), tar.data) bpy.data.collections["Collection"].objects.link(copied_object)

# copying the CAM object
copied_object2 = bpy.data.objects.new(str("CAM"+str(i)), cam.data)
bpy.data.collections["Collection"].objects.link(copied_object2)

I am expecting to get 5 copies of the Target and 5 copies of the CAM. However, I ended up getting 5 basic cubes and 5 basic cones (4 sides). It's giving me copies of the most basic object I created to recreate "Target" and "CAM". Why I am not getting the exact copies of the current objects?

Sourav
  • 241
  • 2
  • 8

1 Answers1

3

If you want a copy use copy()

To get a copy with same object level properties use

copy = ob.copy()
copy.name = f"Target{i}"

and link that to the collection. It will have the same data linked as the original.

Using question code you were losing all object level properties of the original by simply making a new plain jane default settings object with just the data part of original.

How to duplicate an object in 2.8 via the Python API, without using bpy.ops.object.add_named()

batFINGER
  • 84,216
  • 10
  • 108
  • 233