2
$\begingroup$

New to Python, got as far as creating a collection with the same name as the selected object, now I just need to create a collection instance from it.

import bpy

selection_names = bpy.context.selected_objects
for i in selection_names:
     print(i.name)
bpy.ops.object.move_to_collection(collection_index=0, is_new=True, new_collection_name=i.name)
$\endgroup$
1
  • $\begingroup$ I believe this scripting for artists video fully covers what you are looking for. $\endgroup$
    – Ratt
    Apr 15 at 19:02

1 Answer 1

1
$\begingroup$

The function you want is bpy.ops.object.collection_instance_add. If, for example you had a collection called "monkeys", you could add it using this command:

bpy.ops.object.collection_instance_add(collection='monkeys', align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))

All of the arguments except the first are optional.

$\endgroup$
3
  • 1
    $\begingroup$ Worked. Now I just need to create a mini addon, so that it can be assigned a shortcut to. $\endgroup$
    – John Nope
    Apr 15 at 20:13
  • 1
    $\begingroup$ Managed to add shortcut with this addon. $\endgroup$
    – John Nope
    Apr 15 at 20:32
  • $\begingroup$ @JohnNope Good job with the other addon. $\endgroup$ Apr 15 at 23:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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