[Closed] dotNetObject "contextMenu" in CA Def
I think I just worked my self into a corner. Can a contextMenu be used inside of a CA def? It pops up just fine but I can’t get the event handlers to fire.
Any suggestions?
the only solution that i found is a timer: http://forums.cgsociety.org/showpost.php?p=7189958&postcount=13
By the looks of it this is that same old issue where it is not possible to add the event handlers. I have just tried with buttons as well and it doesn’t appear to be working.
Here is some test code.
def=attributes test
(
fn btMouseDown sender arg=
(
print sender.text
)
fn addButtons parent=
(
for i = 1 to 10 do
(
bt=dotNetObject "button"
bt.width=parent.width-10
bt.text="Test"+(i as string)
parent.controls.add bt
dotnet.addEventHandler bt "mouseDown" btMouseDown
)
)
rollout testR "Test"
(
dotNetControl flow "flowLayoutPanel" height:300
on testR open do
(
addButtons flow
)
)
)
ah=emptyModifier()
b=box()
select b
addModifier b ah
max modify mode
custAttributes.add ah def
That works but isn’t very useful as you need a global being executed from some where. I need this all contained in the rig that I’m building so that nothing is loading other then the file.
Not sure that I follow Denis. Once I have added the def to a modifier anything executed in the Def is local to it. Can you show me a working example of the event handlers firing without using a global timer?
why am i asking about the CA? if you CA global to you can define the timer in same place as you define the CA. probably it should be some startup script or stdscript.
i cound’t find a way to use local timer. do you have any global structure? you can add the timer to it.
Thanks Denis everything needs to be contained in the CA def in the modifier. I can’t have anything loading at start up as it will be used in many places and possibly by students.
Thanks for the help, I tried everything to get a global to work from within the Def and it just doesn’t work any way that I have tried. There is definitely some strange scope issue with the modifier panel.
Plan B!
the another problem that you will meet (or already met) is redrawing issue. Some .net combined controls (listview, combobox, etc.) placed in plug-in or CA rollout stop redraw its children.
and only the global timer helps me to solve this problem.
Global timer? I resolved it with a simple Max timer in the past where I fire the timer in the rollout open event, fire the timer and draw the dotNet a 10 after the open. Does that not work for you? Maybe you have a slightly different issue that you are having to resolve.
in plug-in or CA the .net form timer looses it event handlers the same as all other controls. so the timer fired from CA rollout has not to work.
yep… you can force invalidating the controls with a max timer… but unfortunately it doesn’t set even handlers… so, only global timer works for me.
Hey Paul,
I have always used the max timer trick with dotnet – but I gave up a long time ago with trying to make everything handle correctly within a CA. My quick solution is to build menus from buttons/checkboxes with pop up menus. But I have also implemented this with a simple custom control. In your case this would be inheriting the flowlayout panel and adding the buttons and handlers in a method that declares the eventhandlers within the assembly. The only caveat would be that as you are making a composite control, you would have to write a custom event that would pass the button object as an argument to the usercontrol so that it can be raised in the CA Def. Its a pain and i’d only do it if i was certain i couldn’t get there with standard controls.
Pete,
do i understand you correct? you make an assembly composite control with its own events and use it in mxs as dotnetcontrol in CA rollout, don’t you?
Sounds like a pain Pete and then you need an external file to be loaded so that your custom control shows up. I can’t have that in this instance. Has to be all built into the Max file. I guess I could do it run time but I have a work around already for everything. Just using a treeView instead of nice buttons and what not.
Hey Denis,
Yes, that’s exactly right. I have used it in cases when I need to generate dynamic button interfaces. One example was a control that would look for xml character pose presets. All the control did was have a public method to scan a folder, create a button for each file, register each button.click handler to a method that raised the custom event. This event held the button instance object and a path string to the xml preset. You can also handle the command panel refresh issue by using a timer within the user control to force a refresh. This worked well with ca defs and was my solution generally before we had setlifetimecontrol.
if you are trying to avoid external dependencies, and an inherited control isn’t that complicated to embed into a runtime string. But If I’m honest, I my first port of call is an ownerdraw listview or something similar as mostly my time is limited to develop custom controls these days…