hello i want to replace every instances of my asset with a 2.79duppligroup / 2.8CollectionInstance, with the same roientation and scale but i found no way to do this !? ctrl L dont work, = am i missing something ?

if there is actually no way to do this trough blender, could someone teach me a line of code that can help me resolve my problem ?

thank you

  • $\begingroup$ I want to do this as well. Did you find a working method? The script below has no instructions. $\endgroup$ – Coby Randal Mar 16 at 2:42

here'sa code that do that .. the api may change in the future i tested on 300 instances of suzannes its working great

theres just a missing part at the end of the code, i need to hide "newcoll", my original object of every instances from displaying in render, because the obj need to stay in X=0 Y=0 Z=0

import bpy

#Copy and past for later move to newcoll code
context = bpy.context
scene = context.scene
debut = context.object

def find_collection(context, item):
    collections = item.users_collection
    if len(collections) > 0:
        return collections[0]
    return context.scene.collection

def make_collection(collection_name, parent_collection):
    if collection_name in bpy.data.collections:
        return bpy.data.collections[collection_name]
        new_collection = bpy.data.collections.new(collection_name)
        return new_collection

#naming preference of created layer system 
pref = "%s Instancer " % debut.name
name = "%s" % (pref)

#nomme first select asset as basic, dupplicate it, name new newcoll, reset loc,rot,sca on newcoll
basic = bpy.context.object
bpy.ops.object.duplicate_move_linked(OBJECT_OT_duplicate={"linked":True, "mode":'TRANSLATION'})
newcoll = bpy.context.object
newcoll.location[0] = 0
newcoll.location[1] = 0
newcoll.location[2] = 0
newcoll.rotation_euler[0] = 0
newcoll.rotation_euler[1] = 0
newcoll.rotation_euler[2] = 0
newcoll.scale[0] = 1
newcoll.scale[1] = 1
newcoll.scale[2] = 1

#move newcoll dans collection appart
newcoll_collection = find_collection(bpy.context, newcoll)
new_collection = make_collection(name , newcoll_collection)

#create a temporary instance, first create empty...
bpy.ops.object.empty_add(type='PLAIN_AXES', view_align=False, location= cursor)
bpy.context.object.name = "%s Instance " % debut.name
bpy.context.object.instance_type = 'COLLECTION'
bpy.context.object.instance_collection = bpy.data.collections[name]

instance = bpy.context.selected_objects[0]
bpy.context.view_layer.objects.active = debut

#selectionne tout instances sauf temporary instance, and newcoll

#for every obj in selection, create an empty, copy collection of obj,create instance collection, then delete obj to enterely replace selection by empty 
for obj in bpy.context.selected_objects :
    bpy.ops.object.empty_add(type='PLAIN_AXES', view_align=False, location= obj.location, rotation = obj.rotation_euler)
    bpy.context.object.name = "%s Instance " % newcoll.name
    empty = bpy.context.view_layer.objects.active
    bpy.context.view_layer.objects.active = obj
    empty.scale = obj.scale
    empty.instance_type = 'COLLECTION'
    empty.instance_collection = instance.instance_collection
    bpy.context.object.show_instancer_for_viewport = False

    bpy.data.objects.remove(obj, do_unlink=True)

#Delete temporary instances
bpy.data.objects.remove(instance, do_unlink=True)

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.