Notifications
Clear all

[Closed] 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!

8 Replies

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!!

…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.)

Yup in my world, “out the box” directly translates as VS IDE has set it explicitly

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.

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"

( … 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!

1 Reply
(@zeboxx2)
Joined: 11 months ago

Posts: 0

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

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.

Thanks for the tips, dudes!!!