1
$\begingroup$

I am trying to duplicate a mesh object using python. After duplication I try to change the duplicated object's mesh, but the original object's mesh also changes.

Seem like both objects have the same mesh. How can I also duplicate the mesh?

Here is some Code:

>>> obj1 = bpy.data.objects['Cube']
>>> obj2 = obj1.copy()
>>> bpy.context.collection.objects.link(obj2)
>>> obj1.location = Vector((3,0,0))
>>> obj2.animation_data_clear()
>>> ve = obj2.data.vertices[0]
>>> ve.co = ve.co*2

enter image description here

$\endgroup$
0

1 Answer 1

1
$\begingroup$

You should copy object data.

obj1 = bpy.data.objects['Cube']
data = obj1.data.copy()
obj2 = obj1.copy()
obj2.data = data
bpy.context.collection.objects.link(obj2)
obj1.location = Vector((3,0,0))
obj2.animation_data_clear()
ve = obj2.data.vertices[0]
ve.co = ve.co*2
$\endgroup$
3
  • $\begingroup$ That works for the mesh. Now the modifiers and vertex groups get lost, when copying. How can I solve this problem? $\endgroup$
    – Lars
    Jan 21, 2021 at 14:28
  • $\begingroup$ I have updated my answer $\endgroup$ Jan 21, 2021 at 16:43
  • $\begingroup$ Thank you for the help! $\endgroup$
    – Lars
    Jan 22, 2021 at 9:54

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