2
$\begingroup$

I was wondering if anyone knows a simple python command that allows me to rename the selected group. I am working on a script that requires a renaming mid operator. I found one to rename the selected objects but not a group specifically.

$\endgroup$
1
  • 1
    $\begingroup$ If there is a group named "Group" then bpy.data.groups["Group"].name = "Frank" will change its name to "Frank". Not sure as to which is the active group guess is ob.users_group[0] $\endgroup$
    – batFINGER
    Sep 29, 2018 at 19:29

1 Answer 1

2
$\begingroup$

Using Object.users_group returns a list of all groups the object is assigned to. Decide which group of the list you'd like to rename and assign a new name to GroupData.name property.

import bpy

obj = bpy.context.object
obj_group = next(iter(obj.users_group), None)

if obj_group:
    grp = bpy.data.groups.get(obj_group.name)
    grp.name += "_special"
$\endgroup$
3
  • $\begingroup$ Thank you! This worked but I used batfinger's method to do it in less lines of code. -Brad $\endgroup$ Oct 12, 2018 at 1:02
  • $\begingroup$ In case you know the name of the group, that's fine @BradHamilton $\endgroup$
    – brockmann
    Oct 12, 2018 at 9:09
  • 1
    $\begingroup$ No longer an orphan. $\endgroup$
    – batFINGER
    Jul 30, 2021 at 3:50

You must log in to answer this question.

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