-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathadd_text_to_storage.py
63 lines (52 loc) · 1.82 KB
/
add_text_to_storage.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Nikita Akimov
#
# GitHub
# https://github.com/Korchy/BIS
import bpy
from .TextManager import TextManager
from bpy.props import PointerProperty, StringProperty, BoolProperty
from bpy.types import Operator, PropertyGroup, WindowManager
from bpy.utils import register_class, unregister_class
class AddTextToStorage(Operator):
bl_idname = 'bis.add_text_to_storage'
bl_label = 'AddTextToStorage'
bl_description = 'Add text to BIS'
bl_options = {'REGISTER', 'UNDO'}
text_name: StringProperty(
name='textName',
description='Add text with current name',
default=''
)
show_message: BoolProperty(
default=False
)
def execute(self, context):
if self.text_name:
current_text = bpy.data.texts[self.text_name]
else:
current_text = context.area.spaces.active.text
rez = TextManager.to_bis(
context=context,
text=current_text,
tags=context.window_manager.bis_add_text_to_storage_vars.tags
)
if rez['stat'] == 'OK':
context.window_manager.bis_add_text_to_storage_vars.tags = ''
if self.show_message:
bpy.ops.bis.messagebox('INVOKE_DEFAULT', message=rez['data']['text'])
return {'FINISHED'}
class AddTextToStorageVars(PropertyGroup):
tags: StringProperty(
name='Tags (comma separated)',
description='Add some tags to describe this text',
default=''
)
def register():
register_class(AddTextToStorage)
register_class(AddTextToStorageVars)
WindowManager.bis_add_text_to_storage_vars = PointerProperty(type=AddTextToStorageVars)
def unregister():
del WindowManager.bis_add_text_to_storage_vars
unregister_class(AddTextToStorageVars)
unregister_class(AddTextToStorage)