Skip to main content
added 11 characters in body
Source Link

Your answer is actually wrong.

If your active collection is another as the main collection, when running your script the object will not be removed from this.

import bpy

bpy.ops.mesh.primitive_cube_add()
# our created cube is the active one
obj = bpy.context.active_object
# removeRemove itobject from all collections not used in thea scene
bpy.ops.collection.objects_remove_all()
# add it to our specific collection
bpy.data.collections['MyCollection'].objects.link(obj)

About remove all: https://docs.blender.org/api/blender2.8/bpy.ops.collection.html#bpy.ops.collection.objects_remove_all

Your answer is actually wrong.

If your active collection is another as the main collection, when running your script the object will not be removed from this.

import bpy

bpy.ops.mesh.primitive_cube_add()
# our created cube is the active one
obj = bpy.context.active_object
# remove it from all collections in the scene
bpy.ops.collection.objects_remove_all()
# add it to our specific collection
bpy.data.collections['MyCollection'].objects.link(obj)

About remove all: https://docs.blender.org/api/blender2.8/bpy.ops.collection.html#bpy.ops.collection.objects_remove_all

Your answer is actually wrong.

If your active collection is another as the main collection, when running your script the object will not be removed from this.

import bpy

bpy.ops.mesh.primitive_cube_add()
# our created cube is the active one
obj = bpy.context.active_object
# Remove object from all collections not used in a scene
bpy.ops.collection.objects_remove_all()
# add it to our specific collection
bpy.data.collections['MyCollection'].objects.link(obj)

About remove all: https://docs.blender.org/api/blender2.8/bpy.ops.collection.html#bpy.ops.collection.objects_remove_all

Source Link

Your answer is actually wrong.

If your active collection is another as the main collection, when running your script the object will not be removed from this.

import bpy

bpy.ops.mesh.primitive_cube_add()
# our created cube is the active one
obj = bpy.context.active_object
# remove it from all collections in the scene
bpy.ops.collection.objects_remove_all()
# add it to our specific collection
bpy.data.collections['MyCollection'].objects.link(obj)

About remove all: https://docs.blender.org/api/blender2.8/bpy.ops.collection.html#bpy.ops.collection.objects_remove_all