-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathresolvedynamictext.py
61 lines (48 loc) · 1.65 KB
/
resolvedynamictext.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
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# This module allows dynamic text replacement in DaVinci Resolve 15 by
# altering the content of Fusion Title and replacing the .settings file.
import os
import sys
class TitleTemplate(object):
def __init__(self):
self.placeholder = '<Token>'
self.genTemplate = 'GenericTemplate_01.txt'
self.templateName = 'TitleTemplate.setting'
def getOS(self):
# Evaluate host's OS.
if sys.platform.startswith('darwin'):
self.templatePath = '/Library/Application Support/Blackmagic Design/DaVinci Resolve/Fusion/Templates/Edit'
elif sys.platform.startswith('win') or sys.platform.startswith('cygwin'):
appData = os.getenv('APPDATA')
self.templatePath = os.path.join(appData, 'Blackmagic Design',
'DaVinci Resolve', 'Fusion', 'Templates','Edit','Titles')
elif sys.platform.startswith('linux'):
sys.exit('Linux support not implemented')
# We'll load the template if exists, replace text string, and save over the original.
def replace(self, newText):
# Open template
try:
with open(self.genTemplate, 'r') as templatefile:
template = templatefile.read()
except IOError:
return False
# Replace string
template = template.replace(self.placeholder, newText)
# Save template
try:
t = os.path.join(self.templatePath, self.templateName)
with open(t, 'w') as templatefile:
templatefile.write(template)
except IOError:
return False
return True
if __name__ == '__main__':
# Create a title instance
title = TitleTemplate()
# Evaluate host OS one time
title.getOS()
# Replace text
myText = 'This is a dynamically replaced title3'
title.replace(myText)