Making a copy of an object using the Blender Python API

There are two ways to create a copy of an object in a scene:

  1. By calling the duplicate operator,
  2. By using the object’s “copy()” method.

 

Creating a copy of an object using an operator

To make a copy of an object, just call the duplicate operator:

The copied object must be selected and active.

The “linked” parameter specifies which copy to make: full (False) – the new object will be completely independent, or linked (True) – an instance of the object is created, the data of which refers to the data of the original object.

Creating a copy of an object using the “copy()” method

We can make a copy of an object without using operators.

By calling the “copy()” method on the original object, we will get its copy.

Adding a copy of the object to the collection, we will see it in our scene.

Using the “copy()” method, we will get an instance of an object. To make a full copy, we need to call the same “copy()” method for the object data and for the object animation data.

Let’s define a function with the necessary calls:

In the input parameters, we will pass:

  • obj – the object to be copied
  • data and actions – True or False to make a full copy or linked (instance)
  • collection – the collection to place a copy of the object

Now, to create a copy of the currently active object, we just need to call the created function:


* .blend file with a code example for my Patreon subscribers

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comment
Inline Feedbacks
View all comments