1
$\begingroup$

Is there a way to access a collection's name other than through bpy.context so it can be renamed?

$\endgroup$

2 Answers 2

4
$\begingroup$

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

How to rename objects with python?

$\endgroup$
1
  • $\begingroup$ Thank you, batFINGER. Just what I was looking for. $\endgroup$
    – no-one
    Commented Aug 21, 2020 at 17:59
1
$\begingroup$

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()

$\endgroup$

You must log in to answer this question.

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