-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnames.py
46 lines (36 loc) · 1.04 KB
/
names.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
# Nikita Akimov
#
# GitHub
# https://github.com/Korchy/bpy_plus
import re
class Names:
""" Static class for managing names
"""
@staticmethod
def clear(name: str):
""" Return a clear name (without .001, .002 postfix)
:param name: name of the object/material/etc.
:type name: str
:return: clear name without postfix
:rtype: str
"""
regexp = re.compile(r'(\.\d{3}$)')
return regexp.split(name)[0]
@staticmethod
def increase(name: str):
""" Increase name index .001 -> .002
:param name: name of the object/material/etc.
:type name: str
:return: name with increased index
:rtype: str
"""
regexp = re.compile(r'\.(\d{3}$)')
spl_name = regexp.split(name)
if len(spl_name) == 1:
# no index
name += '.001'
else:
# already indexed
name = spl_name[0] + '.' + str(int(spl_name[1]) + 1).zfill(3)
return name