1
$\begingroup$

I’m working with Blender and have a particular workflow where I want to make sure that newly created objects are NOT automatically added to a certain target collection, even when that collection is currently selected or active in the Outliner.

Context: We are creating collection and adding objects to it as part of our add-on code. When the add-on is deactivated, the collection and objects are destroyed as per design. When user activates the add-on and if selects the created collection and adds objects they get added to this collection. We want this to be preventable, even if user has selected the collection inadvertently.

I understand that Blender by default adds new objects to the active collection, but I want to:

  • Keep that target collection selected or active (for other reasons),
  • But prevent new objects from being linked to it automatically.

Is there a way to "lock" or "protect" a collection from receiving new objects? Or any workflow, setting, or scripting solution that prevents this? I’m open to Python scripting solutions, UI tricks, or addon recommendations.

$\endgroup$
7
  • $\begingroup$ By default, we are adding few objects in that collection however it's not required collection to be selected/active if we are able select objects of that collection in viewport. $\endgroup$ Commented Sep 3 at 6:36
  • $\begingroup$ We have requirement that only certain objects only added to specific collection and those we are adding on activating our add-on $\endgroup$ Commented Sep 3 at 6:37
  • 1
    $\begingroup$ for sure this can be solved with an add-on - but i am also pretty sure you won't find it because i think this is a very very rare use case. So maybe it would be better to ask on blenderartists.org under paid jobs and open there a topic. $\endgroup$ Commented Sep 3 at 7:24
  • $\begingroup$ No collection has to be selected nor active for objects in it to be selectable in the 3-D Viewport. The collection just has to be unhidden, which they always are by default. $\endgroup$ Commented Sep 3 at 15:10
  • $\begingroup$ We are creating collection and adding objects to it as part of our add-on code. When the add-on is deactivated, the collection and objects are destroyed as per design. When user activates the add-on and if selects the created collection and adds objects they get added to this collection. We want this to be preventable, even if user has selected the collection inadvertently. $\endgroup$ Commented Sep 5 at 5:37

1 Answer 1

0
$\begingroup$

It's quite easy to do:

  1. Create object
  2. Unlink object from the active collection*

*in Blender there is always an active collection: either user one or 'Scene Collection'

HERE:

import bpy
add_object = bpy.ops.mesh.primitive_cube_add

add_object()
context = bpy.context
ob = context.object
collection = context.collection
context.collection.objects.unlink(ob)

Note! When object is not presented in any collection - it is not visible on scene: to make it visible - link the object to collection of your choice (to custom one or to 'Scene Collection')

collection.objects.link(ob)
$\endgroup$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.