0
$\begingroup$

I am trying to use Blender to import and re-organise a large volume of data. The imported data comes in as 1000s of objects with shared meshes/textures, but individual positions/scales/rotations.

I would like to convert all the objects to collection instances whilst keeping their positions/scales/rotations.

This is so I can add some empties and collision mesh data to a master collection without having to change each individual object (there are approx 12000 of them).

See images for what I'm trying to achieve:

Data as it's imported:

before

Each object (a01, a02, etc) is has its own position/scale/rotation.

What I would like it to look like after sorting, with each collection having its own position/scale/rotation:

after

Perhaps there is a simple way to achieve this within Blender, but I'm guessing this will need a Python script. I am very new to Python, and my attempts so far have resulted in everything but what I'm after...

If anyone could help write a simple script for this, or point me in the direction of a similar script, I would be very grateful!!

I've attached a reference blend file here:

Reference File

Thanks

$\endgroup$
2
  • $\begingroup$ So what exactly do you want to do? What do you have and where do you want to put it and how do you have the unique objects and how do you have their positions and other transforms? Could edit the question and explain it a clear manner? Blender part is easy, it's understanding what you want that's difficult here... Your blend file contains trees. So do you want to scatter them in your scene? How? $\endgroup$ Jul 26, 2023 at 17:06
  • $\begingroup$ Sorry perhaps I wasn't completely clear. The imported data contains trees scattered about a scene as individual objects with a shared mesh. Rather than them be individual objects, I wanted them to be collection instances instead. That way I can add empties and additional meshes to each tree without needing to edit each object individually - I can just edit the master collection. I'm quite new to blender so my terminology might not be completely correct! Anyway, I have figured out a script for this now and posted it below. $\endgroup$
    – sixzis
    Jul 26, 2023 at 18:06

2 Answers 2

2
$\begingroup$

You can give multiple object the same mesh information by linking them to an existing object. You select all the objects you want linked and the one you want to copy as the active element and then click on 'link object data' on this menu enter image description here

This copies the vertices but scale, rotation and position are applied after and are still individual to each object:

enter image description here

This is quick if you are not intending to modify the meshes of all those objects afterwards (If only a couple of them then you can unlink them manually). If you are, then a geometry nodes setup would be better since you can apply it to all models quickly. Just create a geonodes modifier on one of the objects and drag the object you want to copy from the outliner into it. Then connect the new objects geometry to the output: enter image description here

This ignores the original objects mesh and used the new one's instead. It can be applied and copied to any other objects just like any modifier

$\endgroup$
1
$\begingroup$

So I figured out a Python script to do what I was after.

It is here if anyone needs to do something similar:

import bpy 

for obj in bpy.context.selected_objects:
#Create new instance of collection and apply location & rotation of original object:
bpy.ops.object.collection_instance_add(collection='Master_Collection_Name', location=obj.location, rotation=obj.rotation_euler)
#Apply scale of original object to new collection instance:
bpy.context.active_object.scale = obj.scale 
#Save the name of the original object:   
object_to_delete = obj.name
#Remove the original object from the scene:
bpy.data.objects.remove(obj, do_unlink=True)
#Rename the new collection instance with the original object name saved earlier:
bpy.context.active_object.name = object_to_delete

You will need to replace 'Master_Collection_Name' with the name of whatever collection you are instancing.

I've added comments to the code for my own understanding, but they might not make complete sense as I'm new to Python!

I hope this helps someone!

$\endgroup$
2
  • $\begingroup$ This will not run as you posted it. You should fix indentation. $\endgroup$ Jul 26, 2023 at 18:50
  • 1
    $\begingroup$ You could also just select all identical objects and make one of them active and then hit ctrl+l and choose data to link data as explained in the long answer. Or you could use geometry nodes... $\endgroup$ Jul 26, 2023 at 18:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .