AWS Thinkbox Discussion Forums

Deadline Submitter Log Loading Fail

Hi,
Log function doesn’t work before the deadline submitter is started. I think it’s due to global. How can I overcome this problem?

(
global SMTDSettings
global SMTDFunctions
global SMTD_PerformSanityCheck
global SMTD_MainRollout
global SMTD_UserOptions
	
global SMTD_LogStream = #()	
local SMTD_LogShowTimestamp = true
local SMTD_todaysLogFile = "C:\Users\AdminTest\Desktop\test.txt"


try(destroyDialog SimpleDeadlineSubmitter_Rollout)catch()

rollout SimpleDeadlineSubmitter_Rollout "" --rolledup:true
(

group "Logs" 
	(
		dotNetControl dnc_report "ListView" width:365 height:90 align:#center
		button logla "Logla!"
		
	)

fn initReportWindow lv =
		(
			local layout_def = #(#("",60), #("",400))
			lv.Clear()
			lv.backColor = (dotNetClass "System.Drawing.Color").fromARGB SMTD_ColorPalette.maxBgColor.r SMTD_ColorPalette.maxBgColor.g SMTD_ColorPalette.maxBgColor.b
			lv.View = (dotNetClass "System.Windows.Forms.View").Details
			lv.gridLines = false
			lv.fullRowSelect = true
			lv.checkboxes = false
			lv.hideSelection = false
			lv.HeaderStyle = lv.HeaderStyle.None
			for i in layout_def do lv.Columns.add i[1] i[2]
		)
		
fn getTimeString =
	(
		timeArray = getLocalTime()
		local hour = if timeArray[5] < 10 then (hour = "0" + (timeArray[5] as string)) else (hour = (timeArray[5] as string))
		local minute = if timeArray[6] < 10 then (minute = "0" + (timeArray[6] as string)) else (minute = (timeArray[6] as string))
		local second = if timeArray[7] < 10 then (second = "0" + (timeArray[7] as string)) else (second = (timeArray[7] as string))
		timeString = hour + ":" + minute + ":" + second
	)

fn Ui_report txt LogFileOnly:false AddTimeStamp:true =
		(
			if not LogFileOnly do
			(
				try
				(
					local strStream = txt as StringStream
					local theRange = #()
					local blackColor = (dotNetClass "System.Drawing.Color").fromARGB SMTD_ColorPalette.textColor.r SMTD_ColorPalette.textColor.g SMTD_ColorPalette.textColor.b
					if SMTD_ColorPalette.maxBgColor.v >= 160 then
					(
						--DARK COLORS
						local redColor = (dotNetClass "System.Drawing.Color").fromARGB 192 0 0
						local orangeColor = (dotNetClass "System.Drawing.Color").fromARGB 192 100 0
						local greenColor = (dotNetClass "System.Drawing.Color").fromARGB 0 92 0
						local blueColor = (dotNetClass "System.Drawing.Color").fromARGB 0 0 128
					)
					else
					(
						--LIGHT COLORS
						local redColor = (dotNetClass "System.Drawing.Color").fromARGB 255 128 128
						local orangeColor = (dotNetClass "System.Drawing.Color").fromARGB 255 180 50
						local greenColor = (dotNetClass "System.Drawing.Color").fromARGB 128 255 128
						local blueColor = (dotNetClass "System.Drawing.Color").fromARGB 192 220 255
					)

					local lineCount = 0
					local foreColor = blackColor
					while not eof strStream do
					(
						local aLine = readLine strStream
						if aLine == "" do continue
						lineCount +=1
						local logLevel = #info
						if lineCount == 1 do	--set the color and log level only if this is the first line of a multi-line log block
						(
							case of
							(
								default: (
									foreColor = blackColor
								)
								(matchPattern aLine pattern:"?--*"): (
									foreColor = redColor
									logLevel = #error
								)
								(matchPattern aLine pattern:"--*"): (
									foreColor = redColor
									logLevel = #error
								)
								(matchPattern aLine pattern:"?!!*"): (
									foreColor = orangeColor
									logLevel = #warning
								)
								(matchPattern aLine pattern:"!!*"): (
									foreColor = orangeColor
									logLevel = #warning
								)
								(matchPattern aLine pattern:"?+*"): (
									foreColor = greenColor
									logLevel = #success
								)
								(matchPattern aLine pattern:"+*"): (
									foreColor = greenColor
									logLevel = #success
								)
								(matchPattern aLine pattern:">*"): (
									foreColor = blueColor
									logLevel = #progress
								)
								(matchPattern aLine pattern:"==*"): (
									foreColor = blueColor
									logLevel = #progress
								)
							)
						)
						local theTimeStamp = (if AddTimeStamp then getTimeString() else "")
						append ::SMTD_LogStream #(theTimeStamp, forecolor, logLevel, aLine)
						if findItem ::SMTD_LogFilters logLevel == 0 do
						(
							local li = dotNetObject "System.Windows.Forms.ListViewItem" (if SMTD_LogShowTimestamp then theTimeStamp else "")
							li.forecolor = foreColor
							local subLi = li.SubItems.add aLine
							append theRange li
						)
					)
					dnc_report.Items.AddRange theRange
					if dnc_report.Items.Count > 0 do dnc_report.Items.Item[dnc_report.Items.Count-1].EnsureVisible()
					local autoRes = dotNetClass "System.Windows.Forms.ColumnHeaderAutoResizeStyle"
					dnc_report.AutoResizeColumns autoRes.ColumnContent
					if not SMTD_LogShowTimestamp do dnc_report.Columns.Item[0].Width = 1
					try(windows.processPostedMessages())catch()
				)catch()
			)
			if AddTimeStamp then
				try( format "[%] : %\n" (getTimeString()) txt to:SMTD_todaysLogFile)catch()
			else
				try( format "%\n" txt to:SMTD_todaysLogFile)catch()
		)
		
on SimpleDeadlineSubmitter_Rollout open do 
(
		initReportWindow dnc_report
		SimpleDeadlineSubmitter_Rollout.title = "Render724 Submitter | " + SMTDSettings.username +" | " + getTimeString() 
		Ui_report ("+Logged in ["+ getTimeString() +"]")
)

on logla pressed do 
(
			Ui_report ("+Solution Man from LOGLA ["+ getTimeString() +"]")
)

)--end rollout

createDialog SimpleDeadlineSubmitter_Rollout width:400   style:#(#style_titlebar, #style_border, #style_sysmenu, #style_minimizebox, #style_resizing)
--SMTDFunctions.getMaxVersion()
--SimpleDeadlineSubmitter_Rollout.Ui_report ("+sen kralsin ümit abi ["+ getTimeString() +"]")
)--end script

You are missing the definition of the global variable SMTD_LogFilters, so the log fails with an error in the line
if findItem ::SMTD_LogFilters logLevel == 0 do
which is handled by the try()catch() and ends up doing nothing.

In the beginning in your script, you should use

( 
global SMTDSettings 
global SMTDFunctions 
global SMTD_PerformSanityCheck 
global SMTD_MainRollout 
global SMTD_UserOptions 

global SMTD_LogStream = #()
global SMTD_LogFilters = #()  --> NEW LINE!

The SMTD_LogFilters is used to control which log lines are displayed and which are filtered out. It defaults to an empty array #(), so nothing gets filtered.

If you wanted to debug this yourself, you could have remarked the --try and the --catch from the Log function, and you would have seen this:

-- Error occurred in anonymous codeblock; filename: ; position: 4285; line: 125
-- MAXScript Rollout Handler Exception:
-- No ""findItem"" function for undefined

However, I did not need to debug that way, I was reading on my cell phone while at a Disney On Ice show with my kid. I just run the code through my head and saw that the variable SMTD_LogFilters was not defined. :sunglasses:

Note that since the variable is prefixed with double colon in the code, it remains a global variable and does not create a local variable when the script is first evaluated. For that reason, if you would set the value of the variable to #() after the script was run unsuccessfully, pressing the button will work correctly without reevaluating the script!

2 Likes

Ohh great this problem solved. Have fun with the children. Have a nice holiday :slight_smile:

Hi @Bobo.
I wanted to run after months but it doesn’t work.
Very thanks =)

-- Error occurred in anonymous codeblock; filename: ; position: 725; line: 29
-- MAXScript Rollout Handler Exception:
-- Unknown property: "maxBgColor" in undefined
-- MAXScript callstack:
--	thread data: threadID:6192
--	------------------------------------------------------
--	[stack level: 0]
--	In initReportWindow(); filename: ; position: 726; line: 29
--	member of: Rollout:SimpleDeadlineSubmitter_Rollout
--		Parameters:
--			lv: dotNetControl:dnc_report:System.Windows.Forms.ListView
--		Locals:
--			layout_def: #(#("", 60), #("", 400))
--			SMTD_ColorPalette: undefined
--			lv: dotNetControl:dnc_report:System.Windows.Forms.ListView
--		Externals:
--			SimpleDeadlineSubmitter_Rollout: Rollout:SimpleDeadlineSubmitter_Rollout
--			owner: Rollout:SimpleDeadlineSubmitter_Rollout
--	------------------------------------------------------
--	[stack level: 1]
--	called from SimpleDeadlineSubmitter_Rollout.open(); filename: ; position: 5233; line: 149
--	member of: Rollout:SimpleDeadlineSubmitter_Rollout
--		Locals:
--		Externals:
--			SimpleDeadlineSubmitter_Rollout: Rollout:SimpleDeadlineSubmitter_Rollout
--			SMTDSettings: Global:SMTDSettings : undefined
--			getTimeString: getTimeString()
--			owner: Rollout:SimpleDeadlineSubmitter_Rollout
--			initReportWindow: initReportWindow()
--			Ui_report: Ui_report()
--			dnc_report: RolloutControl:dnc_report in rollout:SimpleDeadlineSubmitter_Rollout : dotNetControl:dnc_report:System.Windows.Forms.ListView
--	------------------------------------------------------
--	[stack level: 2]
--	called from anonymous codeblock; filename: ; position: 5574; line: 161
--		Locals:
--			SimpleDeadlineSubmitter_Rollout: Rollout:SimpleDeadlineSubmitter_Rollout
--			SMTD_LogShowTimestamp: true
--		Externals:
--	------------------------------------------------------
--	[stack level: 3]
--	called from top-level

It seems that SMTD_ColorPalette isn’t set. Are you pulling it in with global as the other parts of SMTD? This may be a bad guess on my part.

This is totally correct Edwin, the SubmitMaxToDeadline_Functions.ms must be loaded before any of its structs can be accessed, including the SMTD_ColorPalette which deals with adjusting the UI colors of the submitter to the color palette of 3ds Max.

One can either fileIn() the SubmitMaxToDeadline_Functions.ms from the Repository\submission\3dsmax\main, or open the real SMTD submitter once to initialize everything. After that, a copy of all relevant scripts would be added to the startup folder of 3ds Max, so a fresh session should have all relevant back end variables and structs pre-initialized before any custom scripts are run.

If this was a fresh install of 3ds Max where SMTD was never run before, then no startup script copies would be found and the error would occur.

Going a bit deeper, notice that the variable SMTD_ColorPalette is listed in the error report as local. This means that the script looked through all scopes including the global scope, did not find the global variable defined by the Functions script because it was not loaded yet, and ended up creating a local undefined version of it which then caused the error. If the script must use this variable and the actual loading of the Functions script from the Repository is expected to happen within the functions of the custom submitter, then the variable can be pre-declared as global on top of the script’s local scope, e.g.

global SMTD_ColorPalette 

or it could be referenced via ::SMTD_ColorPalette in the code to ensure it is always using the global scope even if the value has not been set yet.

it worked @Bobo slight_smile:

Very thanks @Bobo and @eamsler

Privacy | Site terms | Cookie preferences