-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
operators.py
176 lines (138 loc) · 5.47 KB
/
operators.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# SPDX-License-Identifier: GPL-2.0-or-later
import bpy
from bpy.types import Operator
from bpy.props import IntProperty, StringProperty
from bpy_extras.io_utils import ImportHelper
import csv, shutil, zipfile, os, glob, fnmatch
class ISN_OT_import_zip(Operator, ImportHelper):
"""Imports Syncsketch's notes (Maya greasepencil zip) as camera background sequence."""
bl_idname = 'isn.import_zip'
bl_label = 'Import Syncsketch Notes'
bl_options = {'PRESET', 'UNDO'}
filename_ext = '.zip'
filter_glob: StringProperty(
default='*.zip',
options={'HIDDEN'}
)
def execute(self, context):
zipFile = self.filepath
zipName = os.path.basename(zipFile).split('/')[-1]
zipPath = os.path.dirname(os.path.abspath(zipFile))
blendPath = bpy.path.abspath("//")
notesTarget = blendPath + 'SyncsketchNotes\\' + os.path.splitext(zipName)[0]
print(f'imported file (full): {zipFile}')
print(f'imported file name: {zipName}')
print(f'imported file path: {zipPath}')
print(f'blend path: {blendPath}')
print(f'target notes path: {notesTarget}')
with zipfile.ZipFile(self.filepath, 'r') as zip_ref:
zip_ref.extractall(notesTarget)
for file in os.listdir(notesTarget):
if fnmatch.fnmatch(file, '*.png'):
noteFile = file
notePath = notesTarget + '\\' + noteFile
print(f' Notes Files: {noteFile}')
break
else:
self.report({'WARNING'}, f'No sketches found in {notesTarget}')
return {'FINISHED'}
cam = bpy.context.scene.camera
for bgi in cam.data.background_images:
if bgi.image and bgi.image.name == 'SyncsketchNotes':
bpy.data.images.remove(bpy.data.images["SyncsketchNotes"])
cam.data.background_images.remove(bgi)
cam.data.background_images.update()
break
img = bpy.data.images.load(notePath)
img.source = 'SEQUENCE'
img.name = 'SyncsketchNotes'
cam.data.show_background_images = True
bg = cam.data.background_images.new()
bg.image = img
bg.image_user.frame_duration = bpy.context.scene.frame_end
bg.image_user.frame_start = 1
bg.frame_method = 'CROP'
bg.display_depth = 'FRONT'
bg.alpha = 1
cam.data.background_images.update()
return {'FINISHED'}
class ISN_OT_jumpToFrame(Operator):
"""Tooltip"""
bl_idname = "isn.jump_to_frame"
bl_label = "Jump to frame"
bl_options = {'REGISTER', "UNDO"}
frameJump: IntProperty()
def execute(self, context):
bpy.context.scene.frame_set(self.frameJump)
return {'FINISHED'}
class ISN_OT_import_csv(Operator, ImportHelper):
"""Imports Syncsketch's notes (Maya greasepencil zip) as camera background sequence."""
bl_idname = 'isn.import_csv'
bl_label = 'Import Syncsketch Comments'
bl_options = {'PRESET', 'UNDO'}
filename_ext = '.csv'
filter_glob: StringProperty(
default='*.csv',
options={'HIDDEN'}
)
def execute(self, context):
csvFile = self.filepath
csvName = os.path.basename(csvFile).split('/')[-1]
csvPath = os.path.dirname(os.path.abspath(csvFile))
blendPath = bpy.path.abspath("//")
commentsTarget = blendPath + 'SyncsketchNotes\\' + os.path.splitext(csvName)[0]
print(f'imported file (full): {csvFile}')
print(f'imported file name: {csvName}')
print(f'imported file path: {csvPath}')
print(f'blend path: {blendPath}')
print(f'target notes path: {commentsTarget}')
shutil.copy2(csvFile, commentsTarget)
for txt in bpy.data.texts:
if txt.name == 'SyncsketchComments':
bpy.data.texts.remove(bpy.data.texts["SyncsketchComments"])
txt = bpy.data.texts.load(csvFile)
txt.name = 'SyncsketchComments'
return {'FINISHED'}
class ISN_OT_delete_notes(Operator):
bl_idname = 'isn.delete_notes'
bl_label = 'Deletes Syncsketch Notes'
bl_options = {'PRESET', 'UNDO'}
def execute(self, context):
cam = bpy.context.scene.camera
for bgi in cam.data.background_images:
if bgi.image and bgi.image.name == 'SyncsketchNotes':
bpy.data.images.remove(bpy.data.images["SyncsketchNotes"])
cam.data.background_images.remove(bgi)
cam.data.background_images.update()
break
return {'FINISHED'}
class ISN_OT_delete_comments(Operator):
bl_idname = 'isn.delete_comments'
bl_label = 'Deletes Syncsketch Comments'
bl_options = {'PRESET', 'UNDO'}
def execute(self, context):
for txt in bpy.data.texts:
if txt.name == 'SyncsketchComments':
bpy.data.texts.remove(bpy.data.texts["SyncsketchComments"])
break
return {'FINISHED'}
classes = (
ISN_OT_import_zip,
ISN_OT_jumpToFrame,
ISN_OT_import_csv,
ISN_OT_delete_notes,
ISN_OT_delete_comments,
)
def register():
from bpy.utils import register_class
for cls in classes:
register_class(cls)
def unregister():
from bpy.utils import unregister_class
for cls in classes:
unregister_class(cls)
try:
import os
os.remove(os.path.join(os.path.expanduser("~"), "temp.txt"))
except:
pass