Outliner showing duplicate entries for same object after python script parenting I am having an issue with Blender 2.82a regarding collections when parenting an object in python.

"tv" is the parent to which I am adding "newBar".

The below code parents the object fine:

bpy.ops.mesh.primitive_plane_add(location = tv.location, rotation = tv.rotation_euler)
newBar = bpy.context.active_object

tv.select_set(True)
newBar.select_set(True)     #select the object for the 'parenting'
bpy.context.view_layer.objects.active = tv    #the active object will be the parent of all selected object
bpy.ops.object.parent_set(keep_transform=False)


The problem comes in when I look at the Outliner afterwards:



The new object was added as "Plane" but it is in 2 places!

I only want it shown under "TV" but the Plane object there looks darker and fake?

I don't really understand why this is happening or even how to search for this issue as google came up with no one having this issue (I'm new to the blender API).
bpy.ops.mesh.primitive_plane_add(location = tv.location, rotation = tv.rotation_euler)


creates the plane in the currently active collection (which seems to be the root here).

As an object can be in several collections, you'll need to unlink it from root or from its current collection:

newBar.users_collection[0].objects.unlink(newBar)


Then link it to the tv (first) collection:

tv.users_collection[0].objects.link(newBar)