-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathomReplaceName.py
executable file
·73 lines (64 loc) · 1.81 KB
/
omReplaceName.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
#MenuTitle: Replace Name in Masters and Exports
# -*- coding: utf-8 -*-
# Code by Olli Meier, January 2022
__doc__="""
Rename your font by replacing name parts in different locations like various custom parameters.
"""
from GlyphsApp import *
font_obj = Glyphs.font
old_name = 'Compact'
new_name = 'Compressed'
def replace_name(obj):
if not isinstance(obj, str):
return
print('old object name: ', obj)
new = obj.replace(old_name, new_name)
print('new object name: ', new)
return new
#change area 'Font'
r = replace_name(font_obj.familyName)
if r is not None:
font_obj.familyName = r
r = replace_name(font_obj.compatibleFullName)
if r is not None:
font_obj.compatibleFullName = r
r = replace_name(font_obj.description)
if r is not None:
font_obj.description = r
r = replace_name(font_obj.trademark)
if r is not None:
font_obj.trademark = r
r = replace_name(font_obj.copyright)
if r is not None:
font_obj.copyright = r
r = replace_name(font_obj.license)
if r is not None:
font_obj.license = r
for master in font_obj.masters:
r = replace_name(master.name)
if r is not None:
master.name = r
for instance in font_obj.instances:
r = replace_name(instance.name)
if r is not None:
instance.name = r
r = replace_name(instance.styleMapStyleName)
if r is not None:
instance.styleMapStyleName = r
r = replace_name(instance.styleMapFamilyName)
if r is not None:
instance.styleMapFamilyName = r
r = replace_name(instance.familyName)
if r is not None:
instance.familyName = r
r = replace_name(instance.preferredFamily)
if r is not None:
instance.preferredFamily = r
#print('instance.fileName: ', instance.fileName())
r = replace_name(instance.variableStyleName)
if r is not None:
instance.variableStyleName = r
for CP in instance.customParameters:
r = replace_name(CP.value)
if r is not None:
CP.value = r