-
Notifications
You must be signed in to change notification settings - Fork 0
/
MrRenderMan.py
176 lines (140 loc) · 5.37 KB
/
MrRenderMan.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# -*- coding: utf-8 -*-
# import stuff...
import ctypes
import os, sys
from sys import argv, executable
import subprocess
from subprocess import Popen, PIPE, CREATE_NEW_CONSOLE
import time
from tkinter import Tk, filedialog
from tkinter.filedialog import askopenfilename
#set console width and heigth
os.system("mode con cols=70 lines=40")
#clear console
clear = lambda: os.system('cls')
clear()
#define variable, has the same value as cols, this is all just to center the text
consolewidth = 70
# behave as worker
# check if there is an argument to the script call and if, use this as filein
if len(sys.argv) == 2:
ctypes.windll.kernel32.SetConsoleTitleW("Mr. Render Man: Worker")
filein = sys.argv[1]
os.chdir ("C:\Program Files\Adobe\Adobe After Effects CC 2018\Support Files")
#error and render switches
rrender = 1
while rrender == 1:
rrender = 0
#start aerender, outs and errors go to pipe for further analysing
aerender = subprocess.Popen(["aerender.exe", "-project", filein],stdout=PIPE, stderr=subprocess.STDOUT)
# poll is true as long as aerender is running
while aerender.poll() == None:
# read out pipe line by line
aeoutmsg = aerender.stdout.readline()
#replace unicode escapes for better look
aeoutmsg = aeoutmsg.replace(b"\x1b[1m\x1b[0m", b"")
aeoutmsg = aeoutmsg.replace(b"\r\n", b"")
# print pipe in console, convert bytestring to unicode for umlauts
print (aeoutmsg.decode('iso8859-1'))
# analysis: if the word fehler appears, restart aerender to finish render process
if str(aeoutmsg).find("Fehler") >= 0:
rrender = 1
#behave as caller
#input file, name is empty, and while the name is empty, script keeps asking to set input file, Tk Mainwindow is hidden and afterward destroyed to get the focus back to console
else:
while True:
ctypes.windll.kernel32.SetConsoleTitleW("Mr. Render Man")
print ("\n")
print (str.center("*** Mr. Render Man ***", consolewidth))
print (str.center("*** Version 1.04 ***", consolewidth))
print ("\n")
print ("Fenster schließen zum Beenden.")
print ("\n")
filein = ""
while filein == "":
input ("Enter drücken um AFX-Projekt zu öffnen ...")
root = Tk()
root.withdraw()
filein = askopenfilename(filetypes=[('Adobe After Effects-Projekt','*.aep')])
#if there has been an argument passed, while loop will not entered and therefor root will not be definded - catch this error event and go on
try:
root.destroy()
except NameError:
root = None
print ("\n")
print ("Folgendes Projekt wird gerendert:")
print (filein)
print ("\n")
# auto shutdown input
sd = input ("Computer nach dem Rendern herunterfahren? [j/n]: ")
print ("\n")
while sd != "j" and sd != "n":
sd = input("Bitte 'j' oder 'n' drücken! Computer nach dem Rendern herunterfahren? [j/n]: ")
print ("\n")
if sd == "j":
print ("Automatisches Herunterfahren ist AKTIV!")
print ("\n")
# set workers
worker = input ("Wieviele Worker sollen gestartet werden? [1-8]: ")
while worker < "1" or worker > "8":
print ("\n")
print ("Nein! Nein! Nein! Nein! Nein! Nein! Nein! Nein! Nein!")
print ("\n")
worker = input ("Wieviele Worker sollen gestartet werden? [1-8]: ")
print ("\n")
print ("Starte " + worker + " Worker ...")
print ("\n")
worker = int(worker)
i = 0
while i < worker:
# check if file extension is .py or .exe... because I'm sick of changing this code all the time when ruinning pyinstaller
exe_or_py = sys.argv[0]
if exe_or_py.split(".")[1] == "py":
wrk = subprocess.Popen([sys.executable, sys.argv[0], filein], creationflags=CREATE_NEW_CONSOLE)
else:
wrk = subprocess.Popen([sys.argv[0], filein], creationflags=CREATE_NEW_CONSOLE)
print ("Worker " + str(i+1) + " gestartet.")
print ("\n")
i+=1
time.sleep (30)
while wrk.poll() == None:
print ("Rendervorgang läuft ...")
print ("\n")
time.sleep (30)
print ("Rendervorgang abgeschlossen!")
print ("\n")
print ("\n")
#auto shutdown exec
if sd =="j":
#check if another worker is running
tasks = str(subprocess.check_output('tasklist /fo csv'))
taskrun = tasks.find("AfterFX.com")
while taskrun != -1:
print ("Weiteren Rendervorgang entdeckt! Herunterfahren wird um 5 Minuten verzögert ...")
print ("\n")
time.sleep (300)
tasks = str(subprocess.check_output('tasklist /fo csv'))
taskrun = tasks.find("AfterFX.com")
print ("Alle Renderaufgaben sind beendet. Computer wird in 20 Sekunden heruntergefahren.")
print ("\n")
os.system("shutdown /s /t 20")
sda = input ("Herunterfahren abbrechen? [a]: ")
while sda != "a":
print ("\n")
print ("Automatisches Herunterfahren ist noch AKTIV!")
print ("\n")
sda = input ("Bitte 'a' drücken um Herunterfahren abzubrechen.")
if sda == "a":
os.system("shutdown /a")
print ("\n")
print ("Computer wird nicht heruntergefahren.")
print ("\n")
print ("Fenster schließen zum Beenden")
print ("\n")
input ("Enter drücken um weiteres Projekt zu rendern.")
clear()
if sd == "n":
print ("Fenster schließen zum Beenden")
print ("\n")
input ("Enter drücken um weiteres Projekt zu rendern.")
clear()