A BPY plus module to simplify work with collections.
Collections class
set_active(name, context=bpy.context)
Set collection active by name
Parameters:
name: collection name to set active
context: context pointer
1 2 3 4 5 6 |
from bpy_plus.collections import Collections Collections.set_active(name='scene 1') print(bpy.context.collection) # bpy.data.collections['scene 1'] |
layer_collection(name, context=bpy.context)
Get LayerCollection by collection name
Parameters:
name: collection name
context: context pointer
1 2 3 4 |
from bpy_plus.collections import Collections print(Collections.layer_collection(name='scene 1')) # <bpy_struct, LayerCollection("scene 1") at 0x0000023FE990A258> |
selected()
Returns the list of selected collections
1 2 3 4 |
from bpy_plus.collections import Collections print(Collections.selected()) # (bpy.data.collections['scene'], bpy.data.collections['camera']) |
active(context=bpy.context)
Returns the active collection
Parameters:
context: context pointer
1 2 3 4 5 |
from bpy_plus.collections import Collections print(Collections.active()) # <bpy_struct, Collection("scene") at 0x0000029A37D84D08> |
all(context=bpy.context)
Returns the all scene collection list.
Parameters:
context: context pointer
1 2 3 4 5 |
from bpy_plus.collections import Collections print(Collections.all()) # [bpy.data.collections['camera'], bpy.data.collections['scene'], bpy.data.scenes['Scene'].collection] |
parent(context=bpy.context, collection=None)
Returns parent collection for collection.
Parameters:
context: context pointer
collection: collection to get paretn for. If None – for currently active collection.
1 2 3 4 5 6 7 |
import bpy from bpy_plus.collections import Collections print( Collections.parent(collection=bpy.context.collection) ) # <bpy_struct, Collection("Scene Collection") at 0x0000029A37D85008> |
move(collection, to)
Move the “collection” collection to the “to” collection.
Parameters:
collection : collection to move
to: move to collection
1 2 3 4 5 6 7 |
import bpy from bpy_plus.collections import Collections Collections.move( collection=Collections.active(), to=bpy.data.collections['Collection 3'] ) |
IM looking for code to move a complete collection and children with objects to another object. Doing the link/unlink approach is tedious. If the outliner has the drop function, why isnt there a move function?!
Interesting suggestion, I will think about adding such function to bpy+