So I'm importing an obj file that comes in as hundreds of separate meshes in the default collection.
Many of the meshes are imported with a similar name, but with a different ID number added in brackets at the end.
I would like to cycle through the default collection to find meshes with these similar names and add them to a new collection named after them.
My end goal would be to have these separated collections and be able to edit one objects materials and the ability to link all at once without scrolling through the long list that is default with the import.
import bpy
"""
Input: Objects in Collection named "Collection"
Output: Like Named objects in separate collections with the same name
"""
"Initial setup; gets number of objects in Collection to cycle through"
Object_number=500;
"Compares one selected object from the outliner to another next to it"
for i in range(0,Object_number+1):
a=bpy.context.object.name[0:10]
bpy.ops.collection.objects_remove(collection="Collection")
bpy.ops.outliner.select_walk(direction='DOWN')
bpy.ops.outliner.item_activate(extend=False, deselect_all=True)
b=bpy.context.object.name[0:10]
bpy.ops.collection.objects_remove(collection="Collection")
print(a)
print(b)
if a = b:
bpy.ops.collection.create(name = a)
bpy.ops.outliner.select_walk(direction='UP')
bpy.ops.collection.object_add_active(collection = a)
else
i=i+1
My initial code scrolled through the outliner and compared the names of two adjacent objects. If the first 10 characters of the string were the same then it would attempt to add both to the collection of the same 10 character name.
Incredibly new to all this and would appreciate the knowledge behind scripting in blender!