Output colored text to the listener


#1

I’m pretty sure this isn’t possible, but I thought I’d give it a go as I’ve been surprised before :slightly_smiling_face:

I was wondering if there’s some way of specifying the color of the text I print to the listener? I’ve seen the global variable outputTextColor (which changes the text color), however this affects all of the text in the listener, so I can’t just switch back and forth.


#2

Actually it is possible to recolorize the output, but it could be quite slow if it is a lot of text
Can’t share the code cause it depends on my c# dlls. But it is possible to do with mxs only


#3

Wow, that’s pretty cool! When trying to pass inn the raw color-value or the colorMan.getColor etc I get “Unable to convert: dotNetObject:System.Drawing.Color to type: IntegerPtr”. How would I need specify the color?


#4

I used this to convert colors to integer representation

fn colorAsInt clr = ((int clr.r) + (bit.shift (int clr.g) 8) + (bit.shift (int clr.b) 16))

#5

Thanks for sharing this, it’s interesting to see the different (original) ways of doing stuff in max that isn’t clearly documented somewhere :slightly_smiling_face: Just to make sure I’m understanding this correctly, this won’t work if I wanted to print one line in red and the next line in green, right? Because it seems to affect the text by “type”, so all of the print-statements in the listener would change color whenever I use this method, correct?

What I had in mind was that if I could change color on the text line by line, I could make my script outputs a bit easier to read. As an example, in my renaming-script I print the old name and the new name like this:

print (i as string + ": (OLD): " + objarray[i].name)
print (i as string + ": (NEW): " + newName)

It would be cool if I could print these in two different colors, but that’s probably not possible, right?


#6

Each printed character in the listener/mxseditor has a style index assigned that defines which style is used to show it on the screen. Afaik you can’t change that index arbitrarily cause it is the lexer responsibility
And there’s no way to make a custom lexer for max version of scintilla


#7

if you want to colorize your own text (output) maybe it will be easier to use System.Windows.Forms.RichTextBox with text and colors as you like?


#8

Great suggestion Denis , I didn’t know that RichTextBox was that flexible :slight_smile: I don’t think it’s worth using it for all of my various scripts with small info-print statements, but I’ll definitely keep it in mind for later (if I create any script with large amounts of output) :wink:

I wonder (just theoretically of course, as I’m sure it would be difficult), but do you think it would be possible to somehow replace the MXSE Output-window with a “custom” RichTextBox-window? Or are there any large obstacles that would be difficult to work around? Again, I’m not even going to attempt to do this, I’m just curious :laughing:


#9

Sure. You simply hide that output pane control of mxseditor and create a WinForm control with the richtextbox. See MaxForm example in mxs reference
But you’ll have to use SetParent method ( from compiled c# dll or python ) to attach the form to mxseditor window so it will move with the window. I guess there was some examples here