Enabling and disabling collections by object

We can enable or disable a collection that contains a specific object using the Blender Python API with a simple script. For example, let’s turn off the collection in which the currently selected object is.

First we need to get a pointer to the collection in which our object lies.

Since an object can reside in more than one collection, we get a list of pointers.

Let’s go through the resulting list in a loop and turn off all collections. We can turn off the scene collection (monitor icon) with the following code.

To turn off a collection on a view layer, we need to get a pointer to the view layer collection. We can use the following function for this:

Having a pointer to the view layer collection, we can turn its visibility on and off (checkbox and eye icons):

Full code:

In order to return the collection by object back using the same script, we just need to replace True with False.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments