[Closed] Close windows on file close
How do I get a dotnet window to close when I close the associated file in max?
what is the ‘assoicated file’ in max? you mean when you close a .max scene?
yes. I want these windows to close when the max file/scene closes …
Since there isn’t a callback for a max file closing, you will need to register callbacks for #filePreOpen, #systemPreNew and #systemPreReset, in which you will simply call close() on the form.
Ok thanks…but bear with me for a sec…take the code which creates a form and also registers a callback to close the form on the opening of a new file:
form=dotNetObject "form"
form.show()
callbacks.addScript #filePreOpen "form.close()"
this generates an ‘undefined’ error(the form)…not sure why as it is well defined by the first line…
Have you tried to use something like this.
fn maxHW = (dotNetObject "maxCustomControls.win32HandleWrapper" (dotNetObject "System.IntPtr" (windows.getMaxHWND())))
newform = dotNetObject "form"
newform.ShowInTaskbar = false
----------rest of the code-----------------
newform.Show (maxHW())
This code allows winform to stay inside max and close with it.
The code snippet you posted works. In your actual script you may not be defining the form in global scope.
But the point is Io, I will have several forms open generated on the fly , and I can’t give them all global scope ‘form’…Do I have to generate unique names for each form?
i would give all my specific windows opened for max session some common title text…
like “The CA Controller”, “The CA Manager”, “The CA Generator”, etc.
or i would add some combination of invisible characters to the end of all titles.
using this method i can find all my opened windows for this specific session, and close them, store sizes and positions, etc. if i need it.
i don’t need to store all names of my windows (globally or locally). i would use a function getWindowByPattern to find all opened windows (hwnds) and do with them whatever i want.
here is a sample…
i made a plugin. let’s say a modifier. the modifier allows pop-up not modal dialog to control its parameters. so technically i can have multiple opened dialogs. When I close the scene I have to close all these dialogs because they don’t make sense anymore. It’s much easier to find them by specific name (pattern).