[Closed] Avoiding multiple dialog copies in a struct tool
One common maxscript technique that I’ve never been able to do correctly
is the destroydialog method of avoiding multiple copies of my dialogs:
if mydialog != undefiend then destroydialog mydialog
The idea is pretty clear to me, but I have consistently failed to scope things in a way that lets this work.
here’s an typical example of one of my tools
struct myTool
(
ro,
dialog,
fn defineRollout=
(
this.ro= rollout ro "myTool"
(
button btn "button"
on btn pressed do(MessageBox("buttonPressed."))
)
),
fn show=(
this.defineRollout()
if ro !=undefined then destroydialog ro --never seems to work!
gdialog=createdialog this.ro modal:false
)
)
myTool=myTool()
myTool.show()
how can I code this so that it will only ever spawn one dialog?
you are creating new structure instance in place of all. so you lose the information about previously created rollout.
because your structure will be global anyway the solution could be (that is usually the i do):
global TheTool
(
struct ToolStruct
(
dialog = rollout dialog "Dialog"
(
local owner = if owner != undefined do owner
label info_lb align:#center
on dialog open do info_lb.text = timestamp() as string
),
fn destroy = try(destroydialog TheTool.dialog) catch(),
fn show =
(
destroy()
createdialog dialog
),
on create do
(
destroy()
dialog.owner = this
)
)
TheTool = ToolStruct()
ok
)
TheTool.show()
I dont do much of maxscript now, but what I used to do earlier is search for the window using the title or window name. Its a part of windows programming to search for Handle windows etc. HWND is the keyword if you type in maxscript documentation.
If I still have the code I will share it with you. so what you do is search for the child windows of 3ds max to have the name of your dialog box. eg you give your dialog box a name/title of : “Struct Tool”. If there is any such window dont show the new window else show the new window.
Below options might help!
UIAccessor.GetChildWindows :
-Videep
Let me please to revive this thread.
I have two (or more) questions:
- Does it have sense to include inside a struct a plugin definition (for example a modifier extension)? If yes, why and how?
- When you distribute this code, for internal or external use, what shall users do to open the rollout? I mean, how do you assign the rollout to an UI button? Do you need/use an additional script to call the “show” function or do you just run everytime the whole struct definition and then the last command to call the function?
Thanks in advance.
I never use plug-in definitions so i cannot speak to those.
- When you distribute this code, for internal or external use, what shall users do to open the rollout
Here’s how I do things
[ul][li]each struct tool script file ends with a tool.show() call, so if you run the script it will show the tool.
[/li][li]I create a macroscript for each tool that runs the tool via filein
[/li][li]I build a menu system via menuman such that each menu item runs the macroscript for its tool
[/li][/ul]
Thanks Logan.
So, it’s what I said: each time you click the menu item, you read all the struct definition.
I supposed that one of the avantages of structs was to just call ‘TheTool.show() ’ when you click the menu item. But, for that, the only way I imagine is to read the struct at the start-up sesion and create an instance of the struct.
Buff! I really still can’t find the structs utility/functionality!