[Closed] How to add a new button by clicking an existed button
[color=white]Hello everyone! I have a question:
I want to create a button that you can click it and then add a new button just like the Multi/Sub-Object[color=blue] material .
I dont know how to make it. [/color]
Anyone could help me?
Thank you!
[/color]
you would have to create a dynamic UI… you can either…
A. Use maxscript UI elements
in which case you’ll have to either…
A.a Build the rollout, as a string, yourself – then evaluate that string and open that new rollout to update your UI
A.b Use the RolloutCreator (see help file) to help you build the rollout and open that new rollout to update your UI
basic example:
global roll_buttons
global build_rollout
fn addAnotherButton = (
roll_buttons_count += 1
counter = roll_buttons_count as string
roll_buttons += "button btn_" + counter + " \"Button " + counter + "\"
"
)
roll_header = "
rollout roll_test \"test\" (
button btn_test \"test\"
on btn_test pressed do (
destroyDialog roll_test
addAnotherButton()
createDialog (buildRollout())
)
"
roll_footer = "
label lbl_test \"test\"
)
"
roll_buttons = ""
roll_buttons_count = 0
fn buildRollout = (
execute (roll_header + roll_buttons + roll_footer)
)
createDialog (buildRollout())
B. Use .NET
.NET gives you the advantage of adding buttons to a UI without having to close/re-open that UI. The disadvantage is that these buttons -have- to be .NET buttons, within a .NET form or other .NET-controls-capable .NET control (e.g. a tab), onto which you cannot place any MaxScript controls.
rollout roll_test "test" width:220 height:220 (
dotNetControl dnc_panel "Windows.Forms.Panel" width:200 height:200
local numButtons = 0
fn clickFunc sender args = (
numButtons += 1
local newButton = (dotNetObject "Windows.Forms.Button")
newButton.text = "Button " + numButtons as string
newButton.top = 24 * numButtons
dnc_panel.controls.add newButton
)
on roll_test open do (
dnc_panel.autoScroll = true -- in case of many buttons
local firstButton = (dotNetObject "Windows.Forms.Button")
firstButton.text = "Hello"
dnc_panel.controls.add firstButton
dotNet.addEventHandler firstButton "click" clickfunc
)
)
createDialog roll_test
You’re so kindhearted.
I’m reading your MAXScript and trying to get it.
Thanks a lot!