Create an instance of an object using mesh data block?

Hi
I have a small script in production that I need to optimise for cycles. There will be a lot of copies in the scene, so I want to make them instances.
I have not found a way to:

a) select only one object, make it active and then use: bpy.ops.object.duplicate_move_linked() (the less elegant approach, I think)
is there a select “none” or deselect all, instead of select_all(‘TOGGLE’)

b) create a mesh and exchange its linked datablock.

Summary: I want to create an empty mesh and replace it’s Mesh Datablock with an existing one.
Thanks for your support

I think I found the right data:
ob.data.vertices.id_data , but it seems to be read-only
I can print it, returns right name, but if I want to e.g.
dat = ob1.data.vertices.id_data
ob2.data.vertices.id_data = dat
returns
Traceback (most recent call last):
File “<blender_console>”, line 1, in <module>
AttributeError: bpy_prop_collection: attribute “id_data” not found
so how do I change the id_data?

1 Like
  1. action for select_all() can be: ‘TOGGLE’, ‘SELECT’, ‘DESELECT’ or ‘INVERT’

  2. duplicate an object, using same data block (linked):

me = bpy.data.objects['Cube'].data # input mesh

ob = bpy.data.objects.new('Duplicate_Linked', me) # params are object name, mesh data (we re-use an existing one, which will effectively create a duplicate-linked object)

bpy.context.scene.objects.link(ob) # add new ob to current scene
bpy.context.scene.update()

# more code if you want...
ob.location = (2,2,2) # place it somewhere else...
1 Like

Thank, you that worked well