Skip to main content
Tweeted twitter.com/StackBlender/status/1089719967069671425
deleted 1 character in body
Source Link
johnzero7
  • 369
  • 1
  • 3
  • 11

Is there a way to change the "active" collection? I can check witch collection is currently selected with this code:

>>> bpy.context.collection
bpy.data.collections['My Collection']

But I can't change it using this property because is read-only. Is there a way to do that?


EDIT

After some research I found out part of the solution. I can use this code to get and set the active layer collection.

# Get the current active layer collection and store it in x
x = bpy.context.view_layer.active_layer_collection
# Select another layer collection from the outliner,
# then use this code to restore x as active
bpy.context.view_layer.active_layer_collection = x

the new problem is that x is not a Collection object, is a LayerCollection and we can't pass any collection created with the method:

myColl = bpy.data.collections.new('My Collection')
bpy.context.scene.collection.children.link(myColl)

So the refined question is: How to obtain a LayerCollection of for a particular Collection to change the Active Collection?

Is there a way to change the "active" collection? I can check witch collection is currently selected with this code:

>>> bpy.context.collection
bpy.data.collections['My Collection']

But I can't change it using this property because is read-only. Is there a way to do that?


EDIT

After some research I found out part of the solution. I can use this code to get and set the active layer collection.

# Get the current active layer collection and store it in x
x = bpy.context.view_layer.active_layer_collection
# Select another layer collection from the outliner,
# then use this code to restore x as active
bpy.context.view_layer.active_layer_collection = x

the new problem is that x is not a Collection object, is a LayerCollection and we can't pass any collection created with the method:

myColl = bpy.data.collections.new('My Collection')
bpy.context.scene.collection.children.link(myColl)

So the refined question is: How to obtain a LayerCollection of for particular Collection to change the Active Collection?

Is there a way to change the "active" collection? I can check witch collection is currently selected with this code:

>>> bpy.context.collection
bpy.data.collections['My Collection']

But I can't change it using this property because is read-only. Is there a way to do that?


EDIT

After some research I found out part of the solution. I can use this code to get and set the active layer collection.

# Get the current active layer collection and store it in x
x = bpy.context.view_layer.active_layer_collection
# Select another layer collection from the outliner,
# then use this code to restore x as active
bpy.context.view_layer.active_layer_collection = x

the new problem is that x is not a Collection object, is a LayerCollection and we can't pass any collection created with the method:

myColl = bpy.data.collections.new('My Collection')
bpy.context.scene.collection.children.link(myColl)

So the refined question is: How to obtain a LayerCollection for a particular Collection to change the Active Collection?

added 819 characters in body
Source Link
johnzero7
  • 369
  • 1
  • 3
  • 11

Is there a way to change the "active" collection? I can check witch collection is currently selected with this code:

>>> bpy.context.collection
bpy.data.collections['My Collection']

But I can't change it using this property because is read-only. Is there a way to do that?


EDIT

After some research I found out part of the solution. I can use this code to get and set the active layer collection.

# Get the current active layer collection and store it in x
x = bpy.context.view_layer.active_layer_collection
# Select another layer collection from the outliner,
# then use this code to restore x as active
bpy.context.view_layer.active_layer_collection = x

the new problem is that x is not a Collection object, is a LayerCollection and we can't pass any collection created with the method:

myColl = bpy.data.collections.new('My Collection')
bpy.context.scene.collection.children.link(myColl)

So the refined question is: How to obtain a LayerCollection of for particular Collection to change the Active Collection?

Is there a way to change the "active" collection? I can check witch collection is currently selected with this code:

>>> bpy.context.collection
bpy.data.collections['My Collection']

But I can't change it using this property because is read-only. Is there a way to do that?

Is there a way to change the "active" collection? I can check witch collection is currently selected with this code:

>>> bpy.context.collection
bpy.data.collections['My Collection']

But I can't change it using this property because is read-only. Is there a way to do that?


EDIT

After some research I found out part of the solution. I can use this code to get and set the active layer collection.

# Get the current active layer collection and store it in x
x = bpy.context.view_layer.active_layer_collection
# Select another layer collection from the outliner,
# then use this code to restore x as active
bpy.context.view_layer.active_layer_collection = x

the new problem is that x is not a Collection object, is a LayerCollection and we can't pass any collection created with the method:

myColl = bpy.data.collections.new('My Collection')
bpy.context.scene.collection.children.link(myColl)

So the refined question is: How to obtain a LayerCollection of for particular Collection to change the Active Collection?

Source Link
johnzero7
  • 369
  • 1
  • 3
  • 11

Change active collection

Is there a way to change the "active" collection? I can check witch collection is currently selected with this code:

>>> bpy.context.collection
bpy.data.collections['My Collection']

But I can't change it using this property because is read-only. Is there a way to do that?