How to get the name of a DotNetControl in rollout?

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  12 December 2008
How to get the name of a DotNetControl in rollout?

Hi, guys! I'm starting to take a look at .NET. I want to do a bone selector window for my rig, so no need to show the bones on the viewport for selecting them. The basic code for the button is this:

dotnetcontrol btn_headFK "System.Windows.Forms.Button" pos:[80,8] width:32 height:32


OK, so here comes the thing: since for the moment my rig is name dependant (I'll change this on the near future), I'm thinking about making a general function for selecting the parts on the rig. I mean that instead of having a list of 31 'on this button click do blah', I can use a function that takes the name of the control (that 'btn_headFK' part) and do something like:

for i = 1 to myRollout.controls.count do
 (	
 	on myRollout.controls[i] click do
	(
 		execute ("select $" + theSelectedChar + "_" + myRollout.controls[i].name
 ...


The problem is that 'myRollout.controls[i].name' does not return 'btn_headFK' but "ControlAxSourcingSite". I can change the name later, or use another property to work with (for example, 'AccessibleName'), but I can't define that property during the dotNetControl definition on the rollout (it's just ignored).

So to sum up I want to access the name of the control, and I can't figure out how to do it when using dotNetControl (no problem with 'standard' controls).

Any help?

Thanks!
__________________
The Lady and the Reaper, Oscar-nominated animated short, here
 
  12 December 2008
Hi Iker,

Im not sure this is the best way of doing this but it's a method that works! In Visual Studio, when you instantiate a control on a windows form, it automatically names the control. In maxscript this doesn' t appear to be happening. So one option would be to provide the control with a name property and use the sender argument in the event handler to feed a function with a case statement.

rollout ch "" width:82 height:44
 (
 	fn clickhandler sender args = 
 	(
 		case sender.name of 
 		(
 		"btn_headFK":print "btn_FK pressed"
 		"btn_other":print "btn_other"
 		default:print "boo"			
 		)		
 	)
 	
 	dotNetControl btn_headFK "Button" pos:[45,5] width:32 height:32
 	dotNetControl btn_other "Button" pos:[5,5] width:32 height:32	
 
 	on ch open do
 	(
 		btn_headFK.name = "btn_headFK"
 		btn_other.name = "btn_other"
 	)
 	
 	on btn_headFK click sender args do clickhandler sender args
 	on btn_other click sender args do clickhandler sender args
 	
 )
 createdialog ch


if you were creating something like this in VS, the sender.name property would work out the box, in MXS it seems that dotnetcontrol needs you to provide it. If nayone has found an alternate way of doing this i'd be grateful to know!

waheey!!
__________________
Regards,
Pete

Read my technical blog - lonerobot.net
 
  12 December 2008
Originally Posted by LoneRobot: ...if you were creating something like this in VS, the sender.name property would work out the box...


..depends on what you mean by 'out of the box'. The VS IDE has set it explicitly, albeit automatically. ( in the Formxxx.Designer.vb , InitializeComponent() method.)
 
  12 December 2008
Yup in my world, "out the box" directly translates as VS IDE has set it explicitly :-P

With a custom control you can provide your own designer file to work out exactly what properties VS specifies when you add the control to a form, or just add the properties after the initializecomponent() call in a new() sub.
__________________
Regards,
Pete

Read my technical blog - lonerobot.net

Last edited by LoneRobot : 12 December 2008 at 04:24 PM.
 
  12 December 2008
how quaint that it should change name as soon as the rollout's created as an UI.. anyway


rollout test "test" (
	dotnetcontrol btn_headFK "System.Windows.Forms.Button" pos:[80,8] width:32 height:32
)
Rollout:test
test.controls[1].name
"btn_headFK"
createDialog test
true
test.controls[1].name
"ControlAxSourcingSite"
(filterString (test.controls[1] as string) ":")[2]
"btn_headFK"
 
  12 December 2008
Originally Posted by LoneRobot: Yup in my world, "out the box" directly translates as VS IDE has set it explicitly :-P


( .. offers wrist for slapping ..) If you've got a lot of controls, would it be safe to do something like this, then?

  	 on ch open do
  	 (
  		for ctrl in ch.controls do(
  			if classof ctrl == dotNetControl then(
  				split = filterString (ctrl as string) ":" 
  				ctrl.name = split[2]
  			)			
  		)
  	 )



EDIT: sorry, ZB, crossed posts!
 
  12 December 2008
Originally Posted by drdubosc: EDIT: sorry, ZB, crossed posts!

Great minds and all that

You don't really have to check whether it's a dotnetcontrol, however - the standard (non-.net) controls will happily work with [2] as well, making it a relatively robust method of getting the name of either
 
  12 December 2008
Good stuff Dr, Ze, a tip in stereo and another one for the method library!

I noticed that on a maxform rather than a MXS rollout, you have to also set the name of the dotnetobject but if you don't, it yields an empty string "" rather than "ControlAxSourcingSite" I need to correct something I said earlier, on inspection the IDE seems to keep track of the control names, and declares this in the form's designer file, not the actual control's, so setting this in the control's new sub is inneffective.
__________________
Regards,
Pete

Read my technical blog - lonerobot.net
 
  12 December 2008
Thanks for the tips, dudes!!!
__________________
The Lady and the Reaper, Oscar-nominated animated short, here
 
  12 December 2008
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 08:39 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.