Maxscript Job Submission Function

Hi,

I’m working on submitting jobs to deadline without the UI, So I’ve followed the Custom Maxscript Submission Tutorial and I got a script working that will submit a job to Deadline with custom details. I want to add it to a library of functions that I run at startup but I seem to be having trouble when I first load it up. I keep getting the same error.

-- Error occurred in SubmitDeadline(); filename: C:\Program Files (x86)\Autodesk\3ds Max 2008\scripts\startup\ZSL_Scripts\SL_Functions.ms; position: 1209 -- Frame: -- initialArgs: undefined -- JobInfoFile: undefined -- SubmitInfoFile: undefined -- result: undefined -- renderMsg: undefined -- SMTDPaths: undefined -- JobSettings: #("Test Comment", 10, "Test Pool", "Test Department") -- maxFileToSubmit: undefined -- Unknown property: "tempdir" in undefined

The line it errors on is “local maxFileToSubmit = SMTDPaths.tempdir + maxFileName”

Once I’ve re-evaluated the script after Max has started up it seems to work again.

The file is in my scripts/startup folder. I wondered if my functions were being evaluated at startup before the SMTD stuff and so it wasn’t finding the SMTD variables but that installs to UI/Macroscripts which I believe evaluates first on startup?

The functions code is below, I’ve split the connection and submission into two functions because I’m submitting multiple jobs at the same time. To execute the functions I’m running:

[code]SubmitSettings=#(“Test Comment”,10,“Test Pool”,“Test Department”)
sl_smtd.CONNECTDEADLINE()

sl_smtd.SUBMITDEADLINE SubmitSettings[/code]

[code]global SL_SMTD

struct SL_SMTD
(

fn ConnectDeadline =
(
	global SMTDSettings
	global SMTDFunctions

	local theResultFile=getDir #temp + "\\_result.txt"
	local theCommandLine=("deadlinecommand.exe -getrepositoryroot > \""+theResultFile +"\"")
	hiddenDosCommand theCommandLine startpath:"c:\\"
	local theFileHandle=openFile theResultFile
	local theNetworkRoot=readLine theFileHandle 
	close theFileHandle

	local remoteScript=theNetworkRoot+@"\submission\3dsmax\SubmitMaxToDeadline_Functions.ms"
	local localScript=getDir #scripts + "\\SubmitMaxToDeadline_Functions.ms"
	if doesFileExist remoteScript then
	(
		if SMTDFunctions == undefined do
		(
			deleteFile localScript
			copyFile remoteScript localScript
			fileIn localScript
		)

	)
	else format "Failed to find [SubmitMaxToDeadline_Functions.ms] in the Repository!\n"
),

fn SubmitDeadline JobSettings =
(
	SMTDFunctions.loadSettings()
	SMTDSettings.Comment = JobSettings[1]
	SMTDSettings.Priority = JobSettings[2]
	SMTDSettings.poolname=JobSettings[3]
	SMTDSettings.Department=JobSettings[4]

	local maxFileToSubmit = SMTDPaths.tempdir + maxFileName
	SMTDFunctions.SaveMaxFileCopy maxFileToSubmit

	local SubmitInfoFile = SMTDPaths.tempdir + "\\max_submit_info.job"
	local JobInfoFile = SMTDPaths.tempdir + "\\max_job_info.job"
	SMTDFunctions.CreateSubmitInfoFile SubmitInfoFile
	SMTDFunctions.CreateJobInfoFile JobInfoFile 

	local initialArgs = "\""+SubmitInfoFile+"\" \""+JobInfoFile+"\" \""+maxFileToSubmit+"\" " 
	local result = SMTDFunctions.waitForCommandToComplete initialArgs SMTDSettings.TimeoutSubmission
	local renderMsg = SMTDFunctions.getRenderMessage() 
	SMTDFunctions.getJobIDFromMessage renderMsg

	if result == #success then 
		(
			format "Submitted successfully as Job %.\n\n%\n\n" \
			SMTDSettings.DeadlineSubmissionLastJobID renderMsg
		)
	else 
	format "Job Submission FAILED.\n\n%" renderMsg 

)--end script

)[/code]

Any help or suggestions anyone might be able to offer would be greatly appreciate.

Nick

Hi,

You will have to pre-declare the variable SMTDPaths as global, OR you can prefix the SMTDPaths with a double-colon to force it to look in the global scope.
The SMTD stuff is generally not loaded when you start Max. It CAN be pre-loaded due to a special caching code in the Submit To Deadline launcher (if you read the tutorial about Private Sanity Check extensions, it is explained there), but you should assume that none of the SMTD structs are pre-declared when your code is running to be completely safe.

You are already pre-declaring global variables global SMTDSettings and global SMTDFunctions - I would suggest moving them out of the function and adding SMTDPaths next to them, in other words,

global SL_SMTD, SMTDSettings, SMTDFunctions, SMTDPaths struct SL_SMTD ( fn ConnectDeadline = ( local theResultFile=getDir #temp + "\\_result.txt" local theCommandLine=("deadlinecommand.exe -getrepositoryroot > \""+theResultFile +"\"") hiddenDosCommand theCommandLine startpath:"c:\\" ...

This will ensure that if your script is launched before any SMTD stuff was ever loaded, those global variables will be already pre-declared and any later loading of the SubmitMaxToDeadline_Functions.ms library will write into them, allowing your own functions to see the correct variable data.

Thanks for the quick response. I’ve done as you suggested and it works perfectly now.