Skip to content
Merged
Changes from all commits
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
9 changes: 6 additions & 3 deletions korman/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from contextlib import contextmanager
import math
from typing import *
from uuid import uuid4

@contextmanager
def bmesh_from_object(bl):
Expand Down Expand Up @@ -62,12 +63,14 @@ def __exit__(self, type, value, traceback):
@contextmanager
def TemporaryCollectionItem(collection):
item = collection.add()
# Blender may recreate the `item` instance as the collection grows and shrink...
# Assign it a unique name so we know which item to delete later on.
name = item.name = str(uuid4())
try:
yield item
finally:
index = next((i for i, j in enumerate(collection) if j == item), None)
if index is not None:
collection.remove(index)
index = collection.find(name)
collection.remove(index)

class TemporaryObject:
def __init__(self, obj, remove_func):
Expand Down