MaxScript: Outputting arrays to dotNet Textboxes

I’m trying to output a group of arrays to a dotNet Textbox, and I can only seem to output either a single entry in the array, or text in quotations. Put the below together to demonstrate the issue. Does anyone know of the correct way to do this, or a better way to output all the entries in an array without having my user open the Listener?

fn arrayPopulate =
(
selected = $selection
theArray
theArray = selected as array
return theArray
)

theArray = arrayPopulate()

try destroyDialog test catch()
rollout test " .NET Textbox" width:500 height:900
(
    dotNetControl dncText "System.Windows.Forms.Textbox" width:480 height:880 align:#center

    on test open do
    (
        dncText.Font = dotNetObject "System.Drawing.Font" "MS Sans Serif" 8 ((dotNetClass "System.Drawing.FontStyle").Regular)
            dncText.BorderStyle = (dotNetClass "System.Windows.Forms.BorderStyle").FixedSingle
            dncText.BackColor = (dotNetClass "System.Drawing.Color").fromARGB (((colorMan.getColor #background) * 255)[1] as integer) (((colorMan.getColor #background) * 255)[2] as integer) (((colorMan.getColor #background) * 255)[3] as integer)
            dncText.ForeColor = (dotNetClass "System.Drawing.Color").fromARGB (((colorMan.getColor #text) * 255)[1] as integer) (((colorMan.getColor #text) * 255)[2] as integer) (((colorMan.getColor #text) * 255)[3] as integer)
            dncText.MultiLine = true
            dncText.WordWrap = false
            dncText.ScrollBars = (dotNetClass "System.Windows.Forms.ScrollBars").Vertical
            dncText.Text =
				(
					for i = 1 to theArray.count do
						(
							print theArray[i]
						)
				)
    )
)
createDialog test

I don’t have any experience with .Net forms (or .Net in general, really), so this might be a silly/ignorant suggestion, but wouldn’t you be able to use

dncText.Text +=    //instead of just =

I’ve been doing that with stock maxscript rollouts, but I’m not sure how applicable that would be to .Net textboxes.

It outputs the same error as if I used just a regular “=”

-- Error occurred in test.open(); filename: C:\Program Files\Autodesk\3ds Max 2012\stdplugs\stdscripts\; position: 1337; line: 31
--  Frame:
>> MAXScript Rollout Handler Exception:
-- Unable to convert: OK to type: String <<
true

Using “dncText.Text = theArray as string” will output the array into the dotNet textbox, but it prints the whole array to one line.

Build up a stringStream with the proper formatting and then write it once to the .Text property.

Building a stringStream is something that is very helpful when write large amounts of text.

Ah, right, my bad. Yeah, building up the string first before assigning it to the .Text should work. I haven’t used much of stringStream, but I’ll typically build a temp variable with, for example, "
" appended to the end of each item. Then after that,

dncText.Text = theTempVariable

[QUOTE=LoTekK;12477]Ah, right, my bad. Yeah, building up the string first before assigning it to the .Text should work. I haven’t used much of stringStream, but I’ll typically build a temp variable with, for example, "
" appended to the end of each item. Then after that,

dncText.Text = theTempVariable

[/QUOTE]

When concatenating a large number of items into a single string you should always use a stringStream in MXS. It’s vastly more memory efficient to do so. I answered Matt’s question in IM. This was what I gave him:

fn format_output header in_array = (
   out_str = stringStream ""
   format "%
" header to:out_str

   for ln in in_array do (
      format "	%
" ln to:out_str
   )

   out_str = out_str as string
   trimRight out_str

   return out_str
)

Ah, I hadn’t realised that. Thanks for the clarification and code, Jeff! :slight_smile: