Assigning a LayerCollection (with "Exclude From ViewLayer" on), to ViewLayer active_layer_collection NotWorking

While “Exclude from View Layers” is on:-

XD = bpy.context.view_layer.active_layer_collection.children['Collection']
XD.collection # prompts-back "bpy.data.collections['Collection']"

When I do
bpy.context.view_layer.active_layer_collection = XD
(With “Exclude From View Layers” ON) It Doesn’t Work. The active_layer_collection is not changed
Neither does this:-
bpy.context.view_layer.active_layer_collection = bpy.context.view_layer.active_layer_collection.children['Collection']

Why? How am I able to assign something that’s excluded from View Layer to XD while I can’t Assign to bpy.context.view_layer.active_layer_collection

I Know that active_layer_collection Can’t be a NONE Value

But the XD varible is getting assigned bpy.context.view_layer.active_layer_collection, which makes me feel like, It should work what I am trynna do…

Welcome to the forum :slight_smile:

An excluded collection cannot be the active layer collection.

But The XD Varible is Getting Assigned bpy.context.view_layer.active_layer_collection

Not really, you assigned XD from a children of the active layer collection, not the active layer collection itself.

1 Like

Thanks for the reply… I am new to Scripting :sweat_smile:

Sorry, I mistakenly wrote that… But the confusion that I am in is, when a new Blender is loaded, active_layer_collection isn’t the “Master Collection”, instead it is the Default Children Collection of Master Collection that Blender Gives Us. If someone Just Presses the “Exclude Button” for the Default Collection in ViewLayer, active_layer_collection suddenly changes to Master Collection. Then why was it made like that for the Default Blender File? Why isn’t Master Collection The Default active_layer_collection?

I don’t really understand you. But the reasoning behind Blender’s default is no longer a Python question I guess :slight_smile:

1 Like