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

4.5 2 votes
Article Rating
Subscribe
Notify of
guest

3 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
Uneconscience UneSource
1conscience0dimension
9 months ago

hi I improved a free script, where I use the info presented there. but copying animation data (and the blender operator does it by default, too) cause a bug in my script. this is logical, because calculating a new location, we need to modify the animation too. I will dig it more later, if I’m able to do it…this is difficult to talk in a foreign language, but I’m surprised by the lack of common projects in blender chats… having several persons on some common projects should accelerate things a lot. a lot of tools are not good enough. I mean even simple tools. I don’t imagine more complicated ones. or later… but maybe advanced programmers are more interested by those ones. here an example of the script I improved https://github.com/1C0D/Blender_InstanceBetween
but adding more tools around circular arrays would be great too.
but in general, no matter what is the tool, if it is useful, it can be improved, in a simple way at first. and with several persons, it’s more easy to find solutions.

Uneconscience UneSource
1conscience0dimension
9 months ago
Reply to  Nikita

thks for your support. your site is so useful too