/
nodetree_source_library_items.py
48 lines (38 loc) · 1.49 KB
/
nodetree_source_library_items.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Nikita Akimov
# interplanety@interplanety.org
#
# GitHub
# https://github.com/Korchy/blender_nodetree_source
import bpy
from bpy.app.handlers import persistent
from bpy.props import CollectionProperty, StringProperty, IntProperty
from bpy.types import PropertyGroup, WindowManager
from bpy.utils import register_class, unregister_class
from .nodetree_source_library import NodeTreeSourceLibrary
class NODETREE_SOURCE_lib_items(PropertyGroup):
name: StringProperty()
@persistent
def _init_library_items(*args):
# init library
if bpy.context:
NodeTreeSourceLibrary.init_library_items(
context=bpy.context
)
def register():
register_class(NODETREE_SOURCE_lib_items)
WindowManager.nodetree_source_lib_items = CollectionProperty(type=NODETREE_SOURCE_lib_items)
WindowManager.nodetree_source_lib_active_item = IntProperty(
name='active item',
default=0
)
NodeTreeSourceLibrary.init_library_items(context=bpy.context)
# re-init library with scene reload
if _init_library_items not in bpy.app.handlers.load_post:
bpy.app.handlers.load_post.append(_init_library_items)
def unregister():
if _init_library_items in bpy.app.handlers.load_post:
bpy.app.handlers.load_post.remove(_init_library_items)
NodeTreeSourceLibrary.clear_library_items(context=bpy.context)
del WindowManager.nodetree_source_lib_active_item
del WindowManager.nodetree_source_lib_items
unregister_class(NODETREE_SOURCE_lib_items)