diff --git a/README.md b/README.md new file mode 100644 index 0000000..b2f529b --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +Скрипт для получения и изменения ограничений на рендер кадра рендерера Corona. + +Запуск из командной строки: +python scriptRunner.py {get, set} + +Параметры: +Для get: +-path — куда сохранить файл limits.txt с результатами (по умолчанию сохраняется в папку со скриптом). +Для get: +-p — ограничение на количество пассов; +-n — ограничние по уровню шума; +-t — временное ограничение на рендер кадра. diff --git a/main.py b/main.py index b77a136..2e07f2e 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ import sys +import os sys.path.append(r'C:\Programs\3DS Max\3ds Max Design 2015') import MaxPlus @@ -8,7 +9,7 @@ scriptTimeLimit = 'renderers.current.progressive_timeLimit' -def setCoronaRenderer(): +def set_coronarenderer(): """ Устанавливает Corona Renderer, если был выбран другой движок """ @@ -22,7 +23,7 @@ def setCoronaRenderer(): return False -def getLimits(): +def get_limits(): """ Получает значения всех трех лимитов Corona Renderer'a Возвращает кортеж из них @@ -32,30 +33,61 @@ def getLimits(): MaxPlus.Core.EvalMAXScript(scriptTimeLimit).GetInt64()) -def setLimits(passLim=0, noiseLim=0.0, timeLim=0): +def set_limits(passLim=-1, noiseLim=-1.0, timeLim=-1): """ Устанавливает значения лимитов Несмотря на 'The format is HOURS:MINUTES:SECONDS' из документации, значение timeLimit задается в мс! """ - maxscript = '{0} = {1}\n'.format(scriptPassLimit, passLim) \ - + '{0} = {1}\n'.format(scriptNoiseLimit, noiseLim) \ - + '{0} = {1}\n'.format(scriptTimeLimit, timeLim) - MaxPlus.Core.EvalMAXScript(maxscript) + maxscript = '' + if int(passLim)>=0: + maxscript += '{0} = {1}'.format(scriptPassLimit, passLim) + if float(noiseLim)>=0: + maxscript += '{0} = {1}'.format(scriptNoiseLimit, noiseLim) + if int(timeLim)>=0: + maxscript += '{0} = {1}'.format(scriptTimeLimit, int(timeLim)*1000) # timeLimit в мс + if maxscript: + MaxPlus.Core.EvalMAXScript(maxscript) -def writeLimitsToFile(path, limits): + +def write_to_file(path, limits): f = open(path, 'w') f.write("PassLimit: {}\n".format(limits[0])) f.write("NoiseLimit: {}\n".format(limits[1])) - f.write("TimeLimit: {} (сек)".format(limits[2] / 1000.0)) + f.write("TimeLimit: {} (sec)".format(limits[2] / 1000)) + f.close() + + +def read_params(): + """ + производит чтение параметров из файла. Затем файл удаляется + """ + paramsPath = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'params.txt') + f = open(paramsPath,'r') + data = f.readlines()[1:] #пропускаем команду get/set + f.close() + os.remove(paramsPath) + return data + + +def read_command(): + paramsPath = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'params.txt') + f = open(paramsPath, 'r') + data = f.readline().replace('\n', '') f.close() + return data -if setCoronaRenderer(): - setLimits(1, 2.08, 3000) - limits = getLimits() - writeLimitsToFile(r"C:\Users\dozer\Desktop\result.txt", limits) +command = read_command() +if set_coronarenderer(): + if command=='get': + path = read_params()[0] + limits = get_limits() # получаем текущие значения лимитов + write_to_file(path, limits) # сохраняем результаты в файл + else: + passLim, noiseLim, timeLim = read_params() + set_limits(passLim, noiseLim, timeLim) # устанавливаем новые значения else: print "Corona renderer not found!" \ No newline at end of file diff --git a/maxconnect/__init__.py b/maxconnect/__init__.py index 8755288..f9f2f19 100644 --- a/maxconnect/__init__.py +++ b/maxconnect/__init__.py @@ -1 +1 @@ -from maxconnect import pycharm \ No newline at end of file +from maxconnect import scriptrunner \ No newline at end of file diff --git a/maxconnect/__init__.pyc b/maxconnect/__init__.pyc index cf5d858..a130219 100644 Binary files a/maxconnect/__init__.pyc and b/maxconnect/__init__.pyc differ diff --git a/maxconnect/__pycache__/pycharm.cpython-35.pyc b/maxconnect/__pycache__/pycharm.cpython-35.pyc deleted file mode 100644 index e3cc70d..0000000 Binary files a/maxconnect/__pycache__/pycharm.cpython-35.pyc and /dev/null differ diff --git a/maxconnect/pycharm.py b/maxconnect/scriptrunner.py similarity index 100% rename from maxconnect/pycharm.py rename to maxconnect/scriptrunner.py diff --git a/maxconnect/pycharm.pyc b/maxconnect/scriptrunner.pyc similarity index 66% rename from maxconnect/pycharm.pyc rename to maxconnect/scriptrunner.pyc index c125bab..510f369 100644 Binary files a/maxconnect/pycharm.pyc and b/maxconnect/scriptrunner.pyc differ diff --git a/scriptRunner.py b/scriptRunner.py index 7ef4eab..c37aedc 100644 --- a/scriptRunner.py +++ b/scriptRunner.py @@ -1,10 +1,52 @@ +# coding=utf-8 import os import sys +import argparse -path = os.path.realpath('maxconnect') -sys.path.append(path) +sys.path.append(os.path.realpath('maxconnect')) import maxconnect +parampath = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'params.txt') + + +def get_limits(args): + f = open(parampath,'w') + f.writelines(['get\n', args.path]) + f.close() + + +def set_limits(args): + f = open(parampath, 'w') + f.writelines(['set\n', + str(args.passLimit)+'\n', + str(args.noiseLimit)+'\n', + str(args.timeLimit)+'\n']) + f.close() + + +def read_args(): + """ + производит чтнение аргументов из командной строки + """ + parser = argparse.ArgumentParser() + subparsers = parser.add_subparsers(help='List of commands') + # get parser + getlimits_parser = subparsers.add_parser('get', help='Get the values of limits') + getlimits_parser.add_argument('-path', dest='path', type=str, + help='Path to file with result', + default=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'limits.txt')) + getlimits_parser.set_defaults(func=get_limits) + # set parser + setlimits_parser = subparsers.add_parser('set', help='Set the values of limits') + setlimits_parser.add_argument('-p', '--passLimit', type=int, default=-1, help='Pass limit value') + setlimits_parser.add_argument('-n', '--noiseLimit', type=float, default=-1.0, help='Noise limit value') + setlimits_parser.add_argument('-t', '--timeLimit', type=int, default=-1, help='Time limit value (in seconds)') + setlimits_parser.set_defaults(func=set_limits) + return parser.parse_args() + + +args = read_args() +args.func(args) filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'main.py') cmd = r'python.ExecuteFile @"%s";' % filename -maxconnect.pycharm.run(cmd) \ No newline at end of file +maxconnect.scriptrunner.run(cmd)