[Closed] generate ui on rollout open ?
Hello,
is it possible to generate ui-Elemtents on the rollout open Event?
I need to colorize and name thousands of contour lines (really ! this is no fun.).
I select on or more lines click a button and the lines get a specific colour and name.
I have a rollout:
rollout a "Farben zuweisen" width:162 height:563
(
)
rof=newrolloutfloater "rdg_HoehenLinienUtility" 200 200
addrollout a rof
rof.size=[200,300]
and another script, that generates a lot of ui-elements ‘generator.ms’:
minValue=140
maxValue=420
diffValue=maxValue-minValue
numberItems=diffValue/5
out="";
theColor=color 255 6 0
theColorStep=255/numberItems
for i=0 to numberItems do(
currentHeight=i*5+140
labelText=(currentHeight as String)+ "m"
theColor.h=i*theColorStep
theColorPicker = ("colorPicker color"+ (i as String) + " \"\" pos:[10,"+ (((i)*11) as String)+ "] width:20 height:10 color:("+ (theColor as String)+") fieldWidth:48")
theButton = ("button btn"+ ((i) as String) + " \""+ (labelText)+"\" pos:[35,"+ ((i*11) as String)+ "] width:35 height:10")
theButtonAction = ("on btn"+ ((i) as String) +" pressed do(try($.wireColor=color"+ (i as String) +".color; $.name=\""+ (labelText) +"\"; chk1.changed (chk1.checked = true))catch())")
theCheckBox=("checkbox chk"+ ((i) as String) +" \""+ (labelText)+"\" pos:[80,"+ ((i*11) as String)+ "]")
radio
out+=(theColorPicker+"
"+theButton+"
"+theButtonAction+"
")
)
print (out as String)
currently I am executing the gernerator.ms and copy its output to the rollout-definition [1].
Is there an simpler way to do this?
Maybe someone can point me to the maxScript-Help Chapters where this is handled.
And there are also another question:
Is it possible to delegate buttons events to functions?
Currently I have for every button a “on btnXYZ pressed do” with roughly the same content. Is there something like:
on btnXYZ pressed do
(
buttonAction(this.name);
)
buttonAction target(
ident=(substring target 4 (target as String).count
-- get somesubsting(target) to referrnce other elements like checkboxes with the same identifier: btn5 -> 5 -> chkbx5
)
Do you think listview is more appropriate for this kind of task?
Georg
[1] resulting script:
rollout a "Farben zuweisen" width:162 height:563
(
colorPicker color0 "" pos:[10,0] width:20 height:10 color:((color 255 0 0)) fieldWidth:48
button btn0 "140m" pos:[35,0] width:35 height:10
on btn0 pressed do(try($.wireColor=color0.color; $.name="140m"; chk1.changed (chk1.checked = true))catch())
colorPicker color1 "" pos:[10,11] width:20 height:10 color:((color 255 24 0)) fieldWidth:48
button btn1 "145m" pos:[35,11] width:35 height:10
on btn1 pressed do(try($.wireColor=color1.color; $.name="145m"; chk1.changed (chk1.checked = true))catch())
colorPicker color2 "" pos:[10,22] width:20 height:10 color:((color 255 48 0)) fieldWidth:48
button btn2 "150m" pos:[35,22] width:35 height:10
on btn2 pressed do(try($.wireColor=color2.color; $.name="150m"; chk1.changed (chk1.checked = true))catch())
colorPicker color3 "" pos:[10,33] width:20 height:10 color:((color 255 72 0)) fieldWidth:48
button btn3 "155m" pos:[35,33] width:35 height:10
on btn3 pressed do(try($.wireColor=color3.color; $.name="155m"; chk1.changed (chk1.checked = true))catch())
colorPicker color4 "" pos:[10,44] width:20 height:10 color:((color 255 96 0)) fieldWidth:48
button btn4 "160m" pos:[35,44] width:35 height:10
on btn4 pressed do(try($.wireColor=color4.color; $.name="160m"; chk1.changed (chk1.checked = true))catch())
colorPicker color5 "" pos:[10,55] width:20 height:10 color:((color 255 120 0)) fieldWidth:48
button btn5 "165m" pos:[35,55] width:35 height:10
on btn5 pressed do(try($.wireColor=color5.color; $.name="165m"; chk1.changed (chk1.checked = true))catch())
colorPicker color6 "" pos:[10,66] width:20 height:10 color:((color 255 144 0)) fieldWidth:48
button btn6 "170m" pos:[35,66] width:35 height:10
on btn6 pressed do(try($.wireColor=color6.color; $.name="170m"; chk1.changed (chk1.checked = true))catch())
colorPicker color7 "" pos:[10,77] width:20 height:10 color:((color 255 168 0)) fieldWidth:48
button btn7 "175m" pos:[35,77] width:35 height:10
on btn7 pressed do(try($.wireColor=color7.color; $.name="175m"; chk1.changed (chk1.checked = true))catch())
colorPicker color8 "" pos:[10,88] width:20 height:10 color:((color 255 192 0)) fieldWidth:48
button btn8 "180m" pos:[35,88] width:35 height:10
on btn8 pressed do(try($.wireColor=color8.color; $.name="180m"; chk1.changed (chk1.checked = true))catch())
colorPicker color9 "" pos:[10,99] width:20 height:10 color:((color 255 216 0)) fieldWidth:48
button btn9 "185m" pos:[35,99] width:35 height:10
on btn9 pressed do(try($.wireColor=color9.color; $.name="185m"; chk1.changed (chk1.checked = true))catch())
colorPicker color10 "" pos:[10,110] width:20 height:10 color:((color 255 240 0)) fieldWidth:48
button btn10 "190m" pos:[35,110] width:35 height:10
on btn10 pressed do(try($.wireColor=color10.color; $.name="190m"; chk1.changed (chk1.checked = true))catch())
colorPicker color11 "" pos:[10,121] width:20 height:10 color:((color 246 255 0)) fieldWidth:48
button btn11 "195m" pos:[35,121] width:35 height:10
on btn11 pressed do(try($.wireColor=color11.color; $.name="195m"; chk1.changed (chk1.checked = true))catch())
colorPicker color12 "" pos:[10,132] width:20 height:10 color:((color 222 255 0)) fieldWidth:48
button btn12 "200m" pos:[35,132] width:35 height:10
on btn12 pressed do(try($.wireColor=color12.color; $.name="200m"; chk1.changed (chk1.checked = true))catch())
colorPicker color13 "" pos:[10,143] width:20 height:10 color:((color 198 255 0)) fieldWidth:48
button btn13 "205m" pos:[35,143] width:35 height:10
on btn13 pressed do(try($.wireColor=color13.color; $.name="205m"; chk1.changed (chk1.checked = true))catch())
colorPicker color14 "" pos:[10,154] width:20 height:10 color:((color 174 255 0)) fieldWidth:48
button btn14 "210m" pos:[35,154] width:35 height:10
on btn14 pressed do(try($.wireColor=color14.color; $.name="210m"; chk1.changed (chk1.checked = true))catch())
colorPicker color15 "" pos:[10,165] width:20 height:10 color:((color 150 255 0)) fieldWidth:48
button btn15 "215m" pos:[35,165] width:35 height:10
on btn15 pressed do(try($.wireColor=color15.color; $.name="215m"; chk1.changed (chk1.checked = true))catch())
colorPicker color16 "" pos:[10,176] width:20 height:10 color:((color 126 255 0)) fieldWidth:48
button btn16 "220m" pos:[35,176] width:35 height:10
on btn16 pressed do(try($.wireColor=color16.color; $.name="220m"; chk1.changed (chk1.checked = true))catch())
colorPicker color17 "" pos:[10,187] width:20 height:10 color:((color 102 255 0)) fieldWidth:48
button btn17 "225m" pos:[35,187] width:35 height:10
on btn17 pressed do(try($.wireColor=color17.color; $.name="225m"; chk1.changed (chk1.checked = true))catch())
colorPicker color18 "" pos:[10,198] width:20 height:10 color:((color 78 255 0)) fieldWidth:48
button btn18 "230m" pos:[35,198] width:35 height:10
on btn18 pressed do(try($.wireColor=color18.color; $.name="230m"; chk1.changed (chk1.checked = true))catch())
colorPicker color19 "" pos:[10,209] width:20 height:10 color:((color 54 255 0)) fieldWidth:48
button btn19 "235m" pos:[35,209] width:35 height:10
on btn19 pressed do(try($.wireColor=color19.color; $.name="235m"; chk1.changed (chk1.checked = true))catch())
colorPicker color20 "" pos:[10,220] width:20 height:10 color:((color 30 255 0)) fieldWidth:48
button btn20 "240m" pos:[35,220] width:35 height:10
on btn20 pressed do(try($.wireColor=color20.color; $.name="240m"; chk1.changed (chk1.checked = true))catch())
colorPicker color21 "" pos:[10,231] width:20 height:10 color:((color 5.99998 255 0)) fieldWidth:48
button btn21 "245m" pos:[35,231] width:35 height:10
on btn21 pressed do(try($.wireColor=color21.color; $.name="245m"; chk1.changed (chk1.checked = true))catch())
colorPicker color22 "" pos:[10,242] width:20 height:10 color:((color 0 255 18)) fieldWidth:48
button btn22 "250m" pos:[35,242] width:35 height:10
on btn22 pressed do(try($.wireColor=color22.color; $.name="250m"; chk1.changed (chk1.checked = true))catch())
colorPicker color23 "" pos:[10,253] width:20 height:10 color:((color 0 255 42)) fieldWidth:48
button btn23 "255m" pos:[35,253] width:35 height:10
on btn23 pressed do(try($.wireColor=color23.color; $.name="255m"; chk1.changed (chk1.checked = true))catch())
colorPicker color24 "" pos:[10,264] width:20 height:10 color:((color 0 255 66.0001)) fieldWidth:48
button btn24 "260m" pos:[35,264] width:35 height:10
on btn24 pressed do(try($.wireColor=color24.color; $.name="260m"; chk1.changed (chk1.checked = true))catch())
colorPicker color25 "" pos:[10,275] width:20 height:10 color:((color 0 255 90.0001)) fieldWidth:48
button btn25 "265m" pos:[35,275] width:35 height:10
on btn25 pressed do(try($.wireColor=color25.color; $.name="265m"; chk1.changed (chk1.checked = true))catch())
colorPicker color26 "" pos:[10,286] width:20 height:10 color:((color 0 255 114)) fieldWidth:48
button btn26 "270m" pos:[35,286] width:35 height:10
on btn26 pressed do(try($.wireColor=color26.color; $.name="270m"; chk1.changed (chk1.checked = true))catch())
colorPicker color27 "" pos:[10,297] width:20 height:10 color:((color 0 255 138)) fieldWidth:48
button btn27 "275m" pos:[35,297] width:35 height:10
on btn27 pressed do(try($.wireColor=color27.color; $.name="275m"; chk1.changed (chk1.checked = true))catch())
colorPicker color28 "" pos:[10,308] width:20 height:10 color:((color 0 255 162)) fieldWidth:48
button btn28 "280m" pos:[35,308] width:35 height:10
on btn28 pressed do(try($.wireColor=color28.color; $.name="280m"; chk1.changed (chk1.checked = true))catch())
colorPicker color29 "" pos:[10,319] width:20 height:10 color:((color 0 255 186)) fieldWidth:48
button btn29 "285m" pos:[35,319] width:35 height:10
on btn29 pressed do(try($.wireColor=color29.color; $.name="285m"; chk1.changed (chk1.checked = true))catch())
colorPicker color30 "" pos:[10,330] width:20 height:10 color:((color 0 255 210)) fieldWidth:48
button btn30 "290m" pos:[35,330] width:35 height:10
on btn30 pressed do(try($.wireColor=color30.color; $.name="290m"; chk1.changed (chk1.checked = true))catch())
colorPicker color31 "" pos:[10,341] width:20 height:10 color:((color 0 255 234)) fieldWidth:48
button btn31 "295m" pos:[35,341] width:35 height:10
on btn31 pressed do(try($.wireColor=color31.color; $.name="295m"; chk1.changed (chk1.checked = true))catch())
colorPicker color32 "" pos:[10,352] width:20 height:10 color:((color 0 252 255)) fieldWidth:48
button btn32 "300m" pos:[35,352] width:35 height:10
on btn32 pressed do(try($.wireColor=color32.color; $.name="300m"; chk1.changed (chk1.checked = true))catch())
colorPicker color33 "" pos:[10,363] width:20 height:10 color:((color 0 228 255)) fieldWidth:48
button btn33 "305m" pos:[35,363] width:35 height:10
on btn33 pressed do(try($.wireColor=color33.color; $.name="305m"; chk1.changed (chk1.checked = true))catch())
colorPicker color34 "" pos:[10,374] width:20 height:10 color:((color 0 204 255)) fieldWidth:48
button btn34 "310m" pos:[35,374] width:35 height:10
on btn34 pressed do(try($.wireColor=color34.color; $.name="310m"; chk1.changed (chk1.checked = true))catch())
colorPicker color35 "" pos:[10,385] width:20 height:10 color:((color 0 180 255)) fieldWidth:48
button btn35 "315m" pos:[35,385] width:35 height:10
on btn35 pressed do(try($.wireColor=color35.color; $.name="315m"; chk1.changed (chk1.checked = true))catch())
colorPicker color36 "" pos:[10,396] width:20 height:10 color:((color 0 156 255)) fieldWidth:48
button btn36 "320m" pos:[35,396] width:35 height:10
on btn36 pressed do(try($.wireColor=color36.color; $.name="320m"; chk1.changed (chk1.checked = true))catch())
colorPicker color37 "" pos:[10,407] width:20 height:10 color:((color 0 132 255)) fieldWidth:48
button btn37 "325m" pos:[35,407] width:35 height:10
on btn37 pressed do(try($.wireColor=color37.color; $.name="325m"; chk1.changed (chk1.checked = true))catch())
colorPicker color38 "" pos:[10,418] width:20 height:10 color:((color 0 108 255)) fieldWidth:48
button btn38 "330m" pos:[35,418] width:35 height:10
on btn38 pressed do(try($.wireColor=color38.color; $.name="330m"; chk1.changed (chk1.checked = true))catch())
colorPicker color39 "" pos:[10,429] width:20 height:10 color:((color 0 84 255)) fieldWidth:48
button btn39 "335m" pos:[35,429] width:35 height:10
on btn39 pressed do(try($.wireColor=color39.color; $.name="335m"; chk1.changed (chk1.checked = true))catch())
colorPicker color40 "" pos:[10,440] width:20 height:10 color:((color 0 60 255)) fieldWidth:48
button btn40 "340m" pos:[35,440] width:35 height:10
on btn40 pressed do(try($.wireColor=color40.color; $.name="340m"; chk1.changed (chk1.checked = true))catch())
colorPicker color41 "" pos:[10,451] width:20 height:10 color:((color 0 36 255)) fieldWidth:48
button btn41 "345m" pos:[35,451] width:35 height:10
on btn41 pressed do(try($.wireColor=color41.color; $.name="345m"; chk1.changed (chk1.checked = true))catch())
colorPicker color42 "" pos:[10,462] width:20 height:10 color:((color 0 12 255)) fieldWidth:48
button btn42 "350m" pos:[35,462] width:35 height:10
on btn42 pressed do(try($.wireColor=color42.color; $.name="350m"; chk1.changed (chk1.checked = true))catch())
colorPicker color43 "" pos:[10,473] width:20 height:10 color:((color 12 0 255)) fieldWidth:48
button btn43 "355m" pos:[35,473] width:35 height:10
on btn43 pressed do(try($.wireColor=color43.color; $.name="355m"; chk1.changed (chk1.checked = true))catch())
colorPicker color44 "" pos:[10,484] width:20 height:10 color:((color 36 0 255)) fieldWidth:48
button btn44 "360m" pos:[35,484] width:35 height:10
on btn44 pressed do(try($.wireColor=color44.color; $.name="360m"; chk1.changed (chk1.checked = true))catch())
colorPicker color45 "" pos:[10,495] width:20 height:10 color:((color 60 0 255)) fieldWidth:48
button btn45 "365m" pos:[35,495] width:35 height:10
on btn45 pressed do(try($.wireColor=color45.color; $.name="365m"; chk1.changed (chk1.checked = true))catch())
colorPicker color46 "" pos:[10,506] width:20 height:10 color:((color 84 0 255)) fieldWidth:48
button btn46 "370m" pos:[35,506] width:35 height:10
on btn46 pressed do(try($.wireColor=color46.color; $.name="370m"; chk1.changed (chk1.checked = true))catch())
colorPicker color47 "" pos:[10,517] width:20 height:10 color:((color 108 0 255)) fieldWidth:48
button btn47 "375m" pos:[35,517] width:35 height:10
on btn47 pressed do(try($.wireColor=color47.color; $.name="375m"; chk1.changed (chk1.checked = true))catch())
colorPicker color48 "" pos:[10,528] width:20 height:10 color:((color 132 0 255)) fieldWidth:48
button btn48 "380m" pos:[35,528] width:35 height:10
on btn48 pressed do(try($.wireColor=color48.color; $.name="380m"; chk1.changed (chk1.checked = true))catch())
colorPicker color49 "" pos:[10,539] width:20 height:10 color:((color 156 0 255)) fieldWidth:48
button btn49 "385m" pos:[35,539] width:35 height:10
on btn49 pressed do(try($.wireColor=color49.color; $.name="385m"; chk1.changed (chk1.checked = true))catch())
colorPicker color50 "" pos:[10,550] width:20 height:10 color:((color 180 0 255)) fieldWidth:48
button btn50 "390m" pos:[35,550] width:35 height:10
on btn50 pressed do(try($.wireColor=color50.color; $.name="390m"; chk1.changed (chk1.checked = true))catch())
colorPicker color51 "" pos:[10,561] width:20 height:10 color:((color 204 0 255)) fieldWidth:48
button btn51 "395m" pos:[35,561] width:35 height:10
on btn51 pressed do(try($.wireColor=color51.color; $.name="395m"; chk1.changed (chk1.checked = true))catch())
colorPicker color52 "" pos:[10,572] width:20 height:10 color:((color 228 0 255)) fieldWidth:48
button btn52 "400m" pos:[35,572] width:35 height:10
on btn52 pressed do(try($.wireColor=color52.color; $.name="400m"; chk1.changed (chk1.checked = true))catch())
colorPicker color53 "" pos:[10,583] width:20 height:10 color:((color 252 0 255)) fieldWidth:48
button btn53 "405m" pos:[35,583] width:35 height:10
on btn53 pressed do(try($.wireColor=color53.color; $.name="405m"; chk1.changed (chk1.checked = true))catch())
colorPicker color54 "" pos:[10,594] width:20 height:10 color:((color 255 0 234)) fieldWidth:48
button btn54 "410m" pos:[35,594] width:35 height:10
on btn54 pressed do(try($.wireColor=color54.color; $.name="410m"; chk1.changed (chk1.checked = true))catch())
colorPicker color55 "" pos:[10,605] width:20 height:10 color:((color 255 0 210)) fieldWidth:48
button btn55 "415m" pos:[35,605] width:35 height:10
on btn55 pressed do(try($.wireColor=color55.color; $.name="415m"; chk1.changed (chk1.checked = true))catch())
colorPicker color56 "" pos:[10,616] width:20 height:10 color:((color 255 0 186)) fieldWidth:48
button btn56 "420m" pos:[35,616] width:35 height:10
on btn56 pressed do(try($.wireColor=color56.color; $.name="420m"; chk1.changed (chk1.checked = true))catch())
)
rof=newrolloutfloater "rdg_HoehenLinienUtility" 200 200
addrollout a rof
rof.size=[200,300]
I found this in the maxfile:
RolloutCreator Functions
RolloutCreator is a structure of functions for dynamically creating rollouts.
I think this will help. I will try it tomorrow and post the result.
Maybe I had a too “Flash-like”-approach on building guis with maxscript.
Georg
Hello,
RolloutCreator Functions seem to be what I've been looking for.
Why do I need to adjust the spinners on first run, to pass the default values to the generator function? If I just press the button the max-values of the spinner ranges are passed to the function ?
rollout defSet "Configuration" width:162 height:200
(
spinner minVal_spn "min value" pos:[40,20] width:114 height:16 range:[0,170,500] type:#integer
spinner maxVal_spn "max value" pos:[40,45] width:114 height:16 range:[0,420,1000] type:#integer
spinner stepVal_spn "stepping" pos:[40,70] width:114 height:16 range:[0,5,100] type:#integer
GroupBox grp1 "Contour Lines" pos:[5,5] width:173 height:138
button cCol "create Colorizer" pos:[8,151] width:147 height:20
dropDownList units_txt "units" pos:[23,94] width:131 height:40 items:#("m", "in", "ft", "km") selection:1
on cCol pressed do
(
defSet.createCLU minVal_spn.value maxVal_spn.value stepVal_spn.value units_txt.selected
)
fn createCLU minVal maxVal stepping units = (
print minVal
print maxVal
diffValue=maxVal - minVal
numberItems=diffValue/stepping
theColor=color 255 6 0
theColorStep=255/numberItems
-- generate Rollout
rci = rolloutCreator "rdg_CLU" "ContourLinesColorizer"
rci.begin()
for i=0 to numberItems do(
currentHeight=i*stepping+minVal
labelText=(currentHeight as String) + units
theColor.h=i*theColorStep
rci.addControl #colorpicker ("color"+ (i as String)) "" paramStr:(" width:20 height:10 fieldWidth:48 color:"+(theColor as String)+" pos:[10,"+ (((i)*11) as String)+ "]")
)
rci.end()
addrollout rdg_CLU rof
)
)
rof=newrolloutfloater "rdgContourLinesUtilities" 200 200
addrollout defSet rof
Georg
“Is it possible to delegate buttons events to functions?
Currently I have for every button a “on btnXYZ pressed do” with roughly the same content. Is there something like:
on btnXYZ pressed do
(
buttonAction(this.name);
)”
rdg,
Either use wrap the action in a fn or use a similar syntax to this:
on buttonX pressed do buttonY.pressed()
Light
Light,
thank you for your answer.
I also figured out, that I had a typo in my script:
range:[0,170,500] is wrong!
range:[0,500,170] is the right syntax … an now it works as expected.
Georg