-
Notifications
You must be signed in to change notification settings - Fork 0
/
batch_converter.py
48 lines (39 loc) · 1.69 KB
/
batch_converter.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
#!/usr/bin/env python3
import argparse
import os
import platform
import subprocess
import sys
from pathlib import Path
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser()
parser.add_argument('--out-dir', type=Path, help='Output directory. Defaults to same directory as input file.')
parser.add_argument('--verbose', action='store_true', help='Enable verbose log output')
parser.add_argument('--overwrite', action='store_true', help='Overwrite existing output')
parser.add_argument('files', nargs='+', help='Files to convert')
args = parser.parse_args()
return args
def main() -> None:
args = parse_args()
for f in args.files:
f = Path(f)
out_dir = args.out_dir or f.parent
out_dir.mkdir(parents=True, exist_ok=True)
out_file = out_dir / f.with_suffix('.blend').name
print(f'Converting {f} -> {out_file}')
script = Path(__file__).parent / 'synty_character_fixer.py'
extra_blender_args = []
passthrough_args = [str(f), str(out_file)]
if args.overwrite:
passthrough_args.append('--overwrite')
cmd = ['blender', '--background', '--python', script, *extra_blender_args, '--', *passthrough_args]
try:
subprocess.run(cmd, check=True, stdout=None if args.verbose else subprocess.DEVNULL)
except FileNotFoundError as e:
print('ERROR: Failed to find blender executable. Make sure Blender install is on your PATH.')
if platform.system() == 'Windows':
print(r' For example: setx PATH=%PATH%;C:\Program Files\Blender Foundation\Blender X.XX')
print()
raise
if __name__ == '__main__':
main()