3
$\begingroup$

I would like to rename every collection and object I currently have selected. enter image description here

Code:

import bpy

selection = bpy.context.selected_objects
for x in selection:
    x.name = 'test_' + x.name
    x.data.name = 'test_' + x.data.name

But the variable selection does not have any collections in it.

$\endgroup$

1 Answer 1

3
$\begingroup$

Only renames active collection and selected objects:

import bpy

def testFunction():
    selection = bpy.context.selected_objects
    for x in selection:
        x.name = 'test_' + x.name
        x.data.name = 'test_' + x.data.name
    collection = bpy.context.view_layer.active_layer_collection.collection
    if collection.name == 'Master Collection':
        return
    collection.name = 'test_' + collection.name

if __name__ == '__main__':
    testFunction()
$\endgroup$
0

You must log in to answer this question.

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