Hi,
I’ve gotten batch scripts working before through subprocess from a live instance of Maya, but I’m having trouble finishing this process off for this mayabatch.
GOAL:
double click .bat to open Command Prompt and run that .bat
the .bat asks user input
the .bat opens maya no UI (mayabatch.exe currently)
the .bat runs a python script
py script gathers list of files to iterate over
monitor progress through output
interruptible at end of each cycle (setup using a temp hotkey nameCommand)
[abbreviated versions of scripts]
My .bat loads mayabatch.exe with command to run python script:
@ECHO off
CHCP 65001 >NUL
TITLE Batch Processing FBX Shaders
ECHO Starting Batch Process of FBX Shaders from Shader List File...
@ECHO ┌─────────────MAYA VERSION────────────────▄
@ECHO │Choices: █
@ECHO │ █
@ECHO │ 1. 2022 █
@ECHO │ 2. 2023 █
@ECHO │ █
@ECHO └▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄█
@SET /p userinpVersion=Type the number of your choice:
@SET userinpVersion=%userinpVersion:~0,1%
@IF "%userinpVersion%"=="1" SET mayaVersion=2022
@IF "%userinpVersion%"=="2" SET mayaVersion=2023
::%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
::more userinput requests here but cutting them out for this sample
::%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@ECHO on
"%ProgramFiles%\Autodesk\Maya%mayaVersion%\bin\mayabatch.exe" -log "C:/Users/%username%/AppData/Local/Temp/logFile.mel" -command "python(\"import assetsTools.scriptFile as scriptFile ^; print('COMMAND IS RUNNING')^; scriptFile.batchProcessFromList('%assetSource%'^,'%libraryCategory%'^,True)\")"
PAUSE
The things that do output to Command Prompt (prints from userSetup when maya loads) do record to Log file.
RE-WRITTEN below for clarity:
import assetsTools.scriptFile as scriptFile
print('COMMAND IS RUNNING') # debug purposes only
scriptFile.batchProcessFromList(assetSource,libraryCategory,True)
Runs this function successfully.
Doesn’t output the prints from WITHIN the batchProcessFromList.
It does print ‘COMMAND IS RUNNING’ to the Command Prompt though.
When I test batchProcessFromList in Script Editor it DOES print to output of Script Editor.
def batchProcessFromList(source, batchSource, missingOnly=True):
print('Started batch process...')
fileList = readDataFile()
percentDone = 0
percentIncrement = 100/(len(fileList))
print( 'Percent completed: '+str(percentDone)+'%')
for file in fileList:
processFile(file)
percentDone += percentIncrement
print( 'Percent completed: '+str(percentDone)+'%')
# there's a check here to see if a user had pressed a certain hotkey during this cycle to kill the process
print('Finished processing files.')
def processFile(file):
print('Processing the file: '+file)
NONE of the prints above in batchProcessFromList and processFile, print to Command Prompt.
I originally tried this as mayabatch calling a python script (to iterate through the files) calling a subprocess calling mayastandalone calling a python script. That felt ridiculous to me so I simplified it to this.
HELP:
How do I get these prints in the Command Prompt?
Any help would be greatly appreciated! Thanks!