Hi python/blender users,

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.

Best, Brad Hamilton

  • $\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 '18 at 19:29

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"
  • $\begingroup$ Thank you! This worked but I used batfinger's method to do it in less lines of code. -Brad $\endgroup$ – Brad Hamilton Oct 12 '18 at 1:02
  • $\begingroup$ In case you know the name of the group, that's fine @BradHamilton $\endgroup$ – brockmann Oct 12 '18 at 9:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.