Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion databpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import bpy
from .addon import register, unregister
from .utils import centre, lerp
from .collection import create_collection
from .collection import create_collection, move_objects
from .attribute import (
named_attribute,
store_named_attribute,
Expand Down
18 changes: 18 additions & 0 deletions databpy/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,21 @@ def create_collection(
parent.children.link(coll)

return coll

def move_objects(objs, target_collection: bpy.types.Collection) -> None:
Comment thread
kolibril13 marked this conversation as resolved.
Outdated
"""Move one or many objects into a target collection.

objs: list[bpy.types.Object] or a single object
Comment thread
kolibril13 marked this conversation as resolved.
Outdated
"""
# Allow single object
if isinstance(objs, bpy.types.Object):
objs = [objs]

for obj in objs:
# Unlink from all current collections
for c in obj.users_collection:
c.objects.unlink(obj)

# Link to target collection
target_collection.objects.link(obj)

Comment thread
kolibril13 marked this conversation as resolved.
Outdated
Loading