MAXScript listener black output color when print from .Net callback method


#1

I noticed that when format or similar methods that print to the listener are called from .net method the output is black instead of default blue color.
Is there any workaround to keep output colors consistent?
example:

t = dotNetObject "system.windows.forms.timer"
t.interval = 1000

fn OnTick sender args =
(
	format "\n"
	showInterface UIAccessor
	
	sender.Stop()
)

dotNet.addEventHandler t "Tick" OnTick
t.start()

clearListener()
format "\n"
showInterface UIAccessor

-- t.dispose()


#2

ok, for those who don’t mind some scintilla hacking there’s a workaround.
to define more styles use SCI_STYLESETFORE, SCI_STYLESETBACK and others

fn ListenerPrintStyledString str style =
(
	local bytes = (dotNetClass "system.text.encoding").unicode.getbytes str
	local styled_bytes = #()

	for i = 1 to bytes.count by 2 do
	(
		append styled_bytes bytes[ i     ]
		append styled_bytes bytes[ i + 1 ]
		append styled_bytes style
		append styled_bytes 1
	)

	bytes = dotnet.ValueToDotNetObject styled_bytes (dotNetClass "system.byte[]")
	local m = (dotNetClass "System.Runtime.InteropServices.Marshal")

	local ptr = m.AllocHGlobal bytes.Length
	m.Copy bytes 0 (dotNetObject "System.IntPtr" ptr) bytes.Length

	local hwnd = (dotNetClass "Autodesk.Max.GlobalInterface").Instance.thelistener.EditBox
	windows.sendMessage hwnd (SCI_ADDSTYLEDTEXT = 2002) (str.count * 2) ptr

	m.FreeHGlobal (dotNetObject "System.IntPtr" ptr)
	ok
)

ListenerPrintStyledString "stylin...\n" -1 -- 0: black, 1: blue, 2: red


Output colored text to the listener