Script to resolve group name collisions when linking objects?

I am working with some linked objects that need to end up in the proper group when linked into a scene.

Let’s say I have a Main file that has Group X in it. I also have an asset file, which has a group called Char1. Char1 is made up of several objects, and one of those objects is also in a group called Group X.

If I link Char1 into the Main file, it’s component object that was in Group X is not part of the Group X that was already in the main file. You end up with two different groups that are both called Group X. It is difficult to determine exactly what is going on, as you cannot interact with linked groups very well.

What I want is to make a script that takes all objects that are in linked Group X and adds them to the original Group X.

My scripting knowledge is not very advanced, so I wanted to check if anybody had any pointers, or had already tackled this issue? Thanks!

(See here for the wider problem I’m trying to solve: http://blender.stackexchange.com/questions/73284/linking-objects-groups-and-freestyle)

Select your linked objects and run the script.



import bpy


group_name = "Group X"


for o in bpy.context.selected_objects:
    if o.library:
        group = [i.name for i in o.users_group if i.name == group_name]
        if group:
            bpy.data.groups[group_name].objects.link(o)


Thank you! I’ve experimented with this and found the following:

If I link a single object and use this, it works. The Object will show up as in Group X and linked Group X.

If I have linked in the group Char1 that contains an object that also is inside Group X, it doesn’t work. I assume this is because the linked group is, well, a group and not an object. We need to somehow effect the objects within the group.

Is it possible to do this?

Also, I want this to be able to resolve for multiple groups. So if the group Char1 had 3 objects, with groups X, Y, and Z, I’d want it to add them each into the group in the new file of the same name.

Thanks!