max file watchfolder for render submition.

Hey everyone I am trying to write a script that "watchs" a specified folder for .max files with cameras inside and renders it out.

3dsmax keeps crashing or endless looping on this.
I plan to release this free, so anyone can use it. but I need help to debug it.

take a look and let me know where the error is.

try (destroyDialog renderWatchFolder_tool) catch()
rollout renderWatchFolder_tool "Watch DOG - 4 xewinga Master" width:300 height:160
local printFileCount
local renderType
local renderFolder
local rFolder
local tempMap
local filePath
local renFolder
local doneRender
fn arrayToString arrayIn = (
stringedArray = ""
for i in arrayIn do (
append stringedArray (i as string)
fn fTime =(
glt =getLocalTime()
gltFormatted = (glt[4] as string)+ (glt[2] as string)+ (glt[1] as string)+ "_"+(glt[5] as string)+ (glt[6] as string)
return gltFormatted

fn renderFiles rFolder = ( ---render type NETWORK or LOCAL INTEGER 1 or 2 --- renderFolder is the watchfolder
if (((getFiles (rFolder + "\*.max")).count) > 0) then (
filesToRender = getFiles (rFolder +"\*.max")
for f in filesToRender do (
loadMaxFile f useFileUnits:true quiet:true
fileSerialNumber = timestamp() as string
out_log_file = maxFilePath+ (getFilenameFile maxFileName) + fileSerialNumber + "_ ERROR_LOG.txt"
out_log_file_name = createFile out_log_file
format "The following errors were found and fixed with the default settings: \n" to:out_log_file_name

def_saveDir_frames = (maxfilePath + fileSerialNumber +"_"+ (getFilenameFile maxFileName)+"_frames")
makedir def_saveDir_frames all:true

-----what to do in the file

if (rendSaveFile == false) then(
format "Render Save File not Checked: %\n" rendSaveFile to:out_log_file_name
rendSaveFile = true

fileCams = for c in cameras where (classof c != Targetobject) and (findString "render" != undefined) collect c
print fileCams

if ((fileCams.count) > 0) then (
for cam in fileCams do (
def_savePath_frames = def_saveDir_frames +"\\"+(getFilenameFile maxFileName)+ fileSerialNumber +"_" + +".png"
print def_savePath_frames
---render cam outputFile:def_savePath_frames
---vfbcontrol #saveallimage def_savePath_frames
rendOutputFilename = def_savePath_frames
viewport.setCamera cam

max quick render

for c =1 to fileCams.count do (
def_savePath_frames = def_saveDir_frames +"\\"+(getFilenameFile maxFileName)+"_"+fileSerialNumber+"_"+ fileCams[c].name +".png"
print def_savePath_frames
---rendOutputFilename = def_savePath_frames
render fileCams[c] outputFile:def_savePath_frames


close out_log_file_name

doneRender =(rFolder + "\_rendered")
renderedFile = (doneRender +"\\" + (getFilenameFile maxfilename) +"_"+ fileSerialNumber +"_Rendered.max" )
saveMaxFile renderedFile useNewFile:true

resetMaxFile #noPrompt

deleteFile f



global theTimer = dotNetObject "System.Windows.Forms.Timer"

checkbutton bt_watch "START WATCHING!" width:250 height:60 checked:false tooltip:"Starts Watching!"
group "Directory to Watch:"
editText watch_path "Location:" labelOnTop:true text:"F:\_TRASHRENDER"
button btn_browse "Browse..."

on btn_browse pressed do
filePath = getSavePath caption:"my title" initialDir:"F:\_TRASHRENDER"
watch_path.text = filePath
makedir (watch_path.text + "_rendered")
on bt_watch changed state do (

if state == true then(
renFolder = watch_path.text
makedir (renFolder + "\_rendered")
fn renderingTheFiles = (renderFiles renFolder)
dotNet.addEventHandler theTimer "Tick" renderingTheFiles
theTimer.interval = 1000
print "on"

bt_watch.text = "WATCHING BITCH"
else (
print "off"


createdialog renderWatchFolder_tool