[Closed] Making custom buttons persistent
If I want to create a custom button say, on a custom attribute modifier, that opens another window, say,(or whatever) how can I make it persist in its function from one saved session of max to another without having to run the mxs?
If it is a custom attribute then all the code in the ca def is already persistent in the scene.
Exactly what have you tried and what exactly are you trying to do?
Thanks for the reply. I have a script that that creates buttons on a ca of a spline. The eventhandler for the button is a long rollout defintion that is defined elsewhere in the mxs, so it works fine when first run, but the eventhandler is not part of the ca so of course it’s lost after I save the file, so next time I press on the button nothing happens. I guess I could place the eventhandler rollout definition on the ca itself but I’m not sure how this works. The other thing is the buttons are generated dynamically as an executed string , so I can’t just create a custom modifier either.
Coud you force the script to run on opening a max file? I’m sorry,it’s a tough one – not sure what the answer is.
first of all the event-handler definition has to be a part of CA.
after that you can use CA create or attachtonode, and load events to apply when construct
(change handlers) or register any other type of event handling (General Callbacks, Node Event Callback, Time Change Callback, Viewport Redraw Callback …)
Thanks Denis. I tried to make the rollout definition part of the CA but the listener gave an error…it accepts functions tho so I guess I’ll try that. attachtonode…? Not sure how that will work…will research…can I refer to the CA definition within the button eventhandler without getting into a dependency loop? Thanks again sir.
give me a basic idea what your CA has to do… maybe you can show a part of your code that localizes the problem…
i will make a snippet to show how to use CA events to initialize some data or bind parameters with the scene on CA creation and attaching, and file loading.
That would be tremendous Denis …thnx…Here is some test code…In the real app, the button is generated via a string but you get the general idea…
fn someFunction param =
(
try(form.close())catch()
maxHandlePointer=(Windows.GetMAXHWND())
sysPointer = DotNetObject "System.IntPtr" maxHandlePointer
maxHwnd = DotNetObject "MaxCustomControls.Win32HandleWrapper" sysPointer
form=dotNetObject "form"
form.Show (maxHwnd)
theImage = dotNetClass "System.Drawing.Image"
graph=dotNetObject "label"
showproperties graph
graph.bounds=dotNetObject "system.drawing.rectangle" 40 40 400 400
form.controls.add graph
form.show()
form.size=dotNetObject "system.drawing.size" 500 500
form.backColor=(dotNetClass "system.drawing.color").fromArgb 100 100 100
form.text="Non Linear Morph Control"
)
rollout dummyRollout ""
(
local param
timer tim interval:5 active:on
on tim tick do if param != undefined do
( someFunction param
destroyDialog dummyRollout
)
)
att = attributes "testAtt"
(
rollout attRol ""
(
button runFn "runFn"
on runFn pressed do
(
createDialog dummyRollout pos:[-2000,-2000]
dummyRollout.param = 800
)
)
)
myBox = box isSelected:on
custAttributes.add myBox att
By the way, I can’t find any reference to attachtonode in the documentation…is it deprecated or…
do you generate .net form controls via script?
By the way, I can’t find any reference to attachtonode in the documentation…is it deprecated or…
the event is called attachedtonode… but it doesn’t work for CA. my bad. it works only for scripted modifiers and materials. so this event is useless in our case.
but in your sample i don’t see any event handlers… are you talking about UI control events?
yes the dotnet forms are produced via the scripted functon as in example. Well, yes I guess I mean the UI button control event…wrong term, sorry…in my mind, button pressed is termed an event handler…well in actionsript it is at any rate…
hmm… i don’t know what to say. here is no really problem. i already showed a sample: http://forums.cgsociety.org/showpost.php?p=7189958&postcount=13
popup dialog is defined in the body of CA. it fires and catches all events. what’s wrong with using of this setup?
Thanks Denis. Unfortunately I’m not in a place where I can apply your script in max , also my dotnet knowledge is minimal and my maxscript quite basic.
On a cursory reading, I’m a little confused about why the button needs to be a dotnet event handler button…
However I think I can adapt the ideas in your script and see what I can do when I am able to boot up max. (Why is executeTimer call commented out?)
My question was not really a dotnet question – but many thanks…I have enough to go on, I feel.