GetRepositoryPath using maxscript

I was wondering if this was still the most efficient way of finding the deadline repository path using pure maxscript… The below script outputs this:

C:\DeadlineRepository10\submission\3dsmax\main\SubmitMaxToDeadline_Functions.ms

Maxscript Code:

global SMTDSettings
global SMTDFunctions

fn get_deadline_bin = 
(
    local repo = systemTools.getEnvVariable( "DEADLINE_PATH" )
    if repo == undefined do
        return ""
    return repo
)

fn get_deadline_repo =
(
    local deadline_bin = get_deadline_bin()
    if not doesFileExist deadline_bin do 
    (
        format "Deadline Repository does not exist: %\n" deadline_bin
        return False
    )
        
    local submitOutputFile = sysInfo.tempdir + "submitOutput.txt"
    local submitExitCodeFile = sysInfo.tempdir + "submitExitCode.txt"
    
    local theCommandLine = "\""+deadline_bin+"\\deadlinecommandbg.exe\" -outputfiles \"" + submitOutputFile + "\" \"" + submitExitCodeFile + "\" -getrepositoryroot"
    hiddenDosCommand theCommandLine
    
    local theFileHandle = openFile submitOutputFile
    local theNetworkRoot = readLine theFileHandle
    close theFileHandle
    theNetworkRoot
)

fn setDeadlindeSettings chunksize:1 suspended:False limits:"" =
(
    local dl_script = pathconfig.appendpath (get_deadline_repo()) @"submission\3dsmax\main\SubmitMaxToDeadline_Functions.ms"
    local local_script = pathconfig.appendpath (getDir #userscripts) "SubmitMaxToDeadline_Functions.ms"
    format "Deadline Script: %\n" dl_script
)

/* Begin */
clearlistener()
setDeadlindeSettings()

Here is a longer, in-memory version of the same function, as used in the actual SMTDFunctions code:

fn CallDeadlineCommandInMemory argument multiLine:false throwOnExitCode:false timeOut:3600 =
(
	local resultMsg = ""
	local exitCode = 0
	try (
		local p = dotnetobject "system.diagnostics.process"
		p.StartInfo.FileName = SMTDPaths.DeadlineExec
		p.StartInfo.Arguments = argument
		p.StartInfo.RedirectStandardOutput = true
		p.StartInfo.RedirectStandardError = true
		p.StartInfo.UseShellExecute = false
		p.StartInfo.CreateNoWindow = true
		p.Start()
		if multiLine then
			local cmdOutput = p.StandardOutput.ReadToEnd() --multiple line output
		else
			local cmdOutput = p.StandardOutput.ReadLine() --single line output
		p.WaitForExit(timeOut)
		if p.ExitCode == 0 then
			resultMsg = cmdOutput
		else
		(
			-- Print stderr if any is captured
			local cmdError = p.StandardError.ReadToEnd()
			if cmdError != "" do print cmdError
			print cmdOutput
			exitCode = p.ExitCode
		)
		p.Dispose()
		p = undefined
	)catch(
		local ex = getCurrentException()
		print "The following error occurred while calling Deadline Command:"
		print ex
	)
	if throwOnExitCode and exitCode != 0 then
		throw ("Deadline command returned exit code: " + (exitCode as string))
	resultMsg
)

theRepo = CallDeadlineCommandInMemory @"-getrepositorypath submission\3dsmax\Main"
if doesFileExist theRepo do theRepo += @"\SubmitMaxToDeadline_Functions.ms"

Note I did not write this. I think Mike Owen did, but I could be wrong.
Its benefit is that it does not write files to disk. Might be better for very long multi-line output like getting Slave info.

do you know if this is possible to do with python?

I would assume so since most of the other applications deadline supports uses python. That would actually be more ideal now that i think about it.

The Python code can be found in the various integrated submitters found in the respective Client folders, for example take a look at the Nuke or Houdini plugins…