Is there a way to access a collection's name other than through bpy.context so it can be renamed?
2 Answers
$\begingroup$
$\endgroup$
1
Collections are ID objects
In blender any ID object is stored in bpy.data
Objects in bpy.data.objects
meshes in bpy.data.meshes
collections in bpy.data.collections
etc etc
To rename a collection named "Bob" to "Frank"
import bpy
col = bpy.data.collections.get("Bob")
if col:
col.name = "Frank"
Note if there is already a collection named "Frank" then numbers are appended "Frank.001"... as per unique naming convention.
Related
-
$\begingroup$ Thank you, batFINGER. Just what I was looking for. $\endgroup$– no-oneCommented Aug 21, 2020 at 17:59
$\begingroup$
$\endgroup$
Try this:)
import bpy
col_name = "Collection"
new_name = "My Collection"
# Find the collection by name
col = bpy.data.collections.get(col_name)
# Rename the collection
col.name = new_name
# Update the Outliner to reflect the change
bpy.context.view_layer.update()