-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathzync_c4d_scene_settings.py
123 lines (96 loc) · 3.17 KB
/
zync_c4d_scene_settings.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
""" Contains C4dSceneSettings class. """
from importlib import import_module
import re
from zync_c4d_take_settings import C4dTakeSettings
import zync_c4d_utils
zync_threading = zync_c4d_utils.import_zync_module('zync_threading')
main_thread = zync_threading.MainThreadCaller.main_thread
c4d = import_module('c4d')
win_drive_letter_regex = re.compile('^[a-zA-Z]:$')
class C4dSceneSettings(zync_threading.MainThreadCaller):
"""
Implements various scene-related operations using C4D API.
:param zync_threading.MainThreadExecutor main_thread_executor:
:param c4d.documents.BaseDocument document:
"""
def __init__(self, main_thread_executor, document):
zync_threading.MainThreadCaller.__init__(self, main_thread_executor)
self._document = document
@main_thread
def get_all_assets(self):
"""
Returns all scene assets.
:return Iterable[str]:
"""
return c4d.documents.GetAllAssets(self._document, False, '')
@main_thread
def get_all_take_settings(self):
"""
Returns a list of take settings for all takes in the scene.
:return list[C4dTakeSettings]:
"""
take_settings = []
take_data = self._document.GetTakeData()
def _traverse(take, depth):
take_settings.append(
C4dTakeSettings(self._main_thread_executor, take, take_data, depth,
self._document))
for child_take in take.GetChildren():
_traverse(child_take, depth + 1)
_traverse(take_data.GetMainTake(), 0)
return take_settings
@main_thread
def get_fps(self):
"""
Returns FPS of the scene.
:return int:
"""
return self._document.GetFps()
@main_thread
def get_scene_name(self):
"""
Returns name of the scene.
:return str:
"""
return self._document.GetDocumentName()
def get_scene_name_without_extension(self):
"""
Returns name of the scene without extension.
:return str:
"""
return re.sub(r'\.c4d$', '', self.get_scene_name())
@main_thread
def get_scene_path(self):
"""
Returns the path of the scene.
:return str:
"""
return self._maybe_fix_windows_path(self._document.GetDocumentPath())
@staticmethod
def _maybe_fix_windows_path(path):
# When path is just a drive letter on Windows, it has no trailing \ character and such path
# can't be merged correctly with file name, because on Windows C:\directory is different thing
# than C:directory and both are valid paths. This method appends missing \ character.
if zync_c4d_utils.is_windows():
if win_drive_letter_regex.match(path):
path += '\\'
return path
@main_thread
def has_the_same_document(self, document):
"""
Checks if the provided document is the same as the one with which this instance was initialized.
:param c4d.documents.BaseDocument document:
:return bool:
"""
try:
return document == self._document and document.GetDocumentPath() == \
self._document.GetDocumentPath()
except ReferenceError:
return False
@main_thread
def is_saved(self):
"""
Checks if the scene is saved.
:return bool:
"""
return self.get_scene_path() != '' and not self._document.GetChanged()