Notifications
Clear all

[Closed] dotnet tab UI code

Hi All,
I’m trying to build a robust skeleton of code to allow the quick, stable building of tabbed dotnet based floater dialog. I want to build a tabbed interface of say 2 rows of 6 (12 in total) tabs which all contain different rollouts within them. I want the code to handle the user clicking between the tabs and updating correctly. Eventually, I want the different tabs to pull in seperate *.ms files so that the individual tabbed rollouts can be individually updated on the server and re-distributed easily. Is this possible? Is this the best approach? I only have the basic so far, can anyone help me any further? Thx. Mike

–DOT NET CONTROL START
rollout MyTestRollout “My Test Rollout” (
dotnetcontrol myTab “System.Windows.Forms.TabControl”
fn setupTabs = (
for x=1 to 6 do (
local tabPge=dotNetObject “System.Windows.Forms.TabPage” (“tab “+x as string)
myTab.Controls.Add tabPge
)
)
on MyTestRollout open do setupTabs()
)
createDialog MyTestRollout width:200 height:200
–DOT NET CONTROL END

5 Replies

Hi Mike,

I usually show the Deadline Submitter as an example of possible tab handling code.
It defines an array of arrays, each sub-array contains one or more rollout definitions.
Then the code manages the creation of the tabs and the adding of the rollouts as sub-rollouts when the tab is clicked.

Here is a slightly expanded version of that code:


(
	global testTabs 
	try(destroyDialog testTabs )catch()
	
	local LastSubRollout = 1
	
	rollout testTabsRollout01 "Rollout 01"
	(
		spinner spn_spinner "Spinner"
	)
	rollout testTabsRollout02 "Rollout 02"
	(
		button btn_button "Button"
	)
	rollout testTabsRollout03 "Rollout 03"
	(
		label lbl_label "This is some text"
	)
	rollout testTabsRollout04 "Rollout 04"
	(
		colorpicker clr_picker "Color Picker"
	)
	rollout testTabsRollout05 "Rollout 05"
	(
		checkbox chk_box "Checkbox"
	)
	
	testTabs_Rollouts = #(
		#("Tab One",#(testTabsRollout01)),
		#("Tab Two",#(testTabsRollout02)),
		#("Tab Three",#(testTabsRollout03)),
		#("Tab Four",#(testTabsRollout04,testTabsRollout05))
	)	
	
	rollout testTabs "Test Tabs"
	(
			dotNetControl dn_tabs "System.Windows.Forms.TabControl" height:20 width:420 align:#center
			subRollout theSubRollout width:420 height:140 align:#center
			
			on dn_tabs Selected itm do
			(
				if LastSubRollout != (itm.TabPageIndex+1) do --do not update if the same tab clicked twice
				(
					for subroll in testTabs_Rollouts[LastSubRollout][2] do
						removeSubRollout theSubRollout subroll
					for subroll in testTabs_Rollouts[LastSubRollout = itm.TabPageIndex+1][2] do	
						addSubRollout theSubRollout subroll
				) 
			)--end tabs clicked		
			
			on testTabs open do
			(
				for aTab in testTabs_Rollouts do
				(
					dn_tabs.TabPages.add aTab[1]
				)
				for subroll in testTabs_Rollouts[1][2] do 
					addSubRollout theSubRollout subroll				
			)
	)

	createDialog testTabs 440 200
)	

Not to step on Bobo’s toes (as I used his Deadline example to learn how to do this to), but yes, eveything you have said is possible.

How you would go about doing this dynamically is another question, but it is possible

Shane

1 Reply
(@bobo)
Joined: 1 year ago

Posts: 0

Well, the way I would do it is
*Create an MS file for each rollout to be shown
*In the MS file, define a global rollout and in the last line, append to the tabsrollout array containing the description of the tabs and their rollouts. (that variable should either be global too or local to the main rollout)
*In the main MS file, either scan for MS files in a specified folder and fileIn() them one by one, or hard-code them and fileIn() them.

By doing this, each MS file will be evaluated in the global scope and will add its rollout to the list of tabs/rollouts to display. To add a new tab, simply create another MS file in the dedicated folder containing a rollout and an append statement and restart the main script to rescan and rebuild the tabbed dialog.

Here is the code of the master script:


(
	global testTabs 
	try(destroyDialog testTabs )catch()
	
	local LastSubRollout = 1
	global testTabs_Rollouts = #()
	
	local theSourceFolder = getDir #scripts + "\\TabTest"
	local theRolloutFiles = getFiles (theSourceFolder + "\\*.ms")
	for f in theRolloutFiles do fileIn f
	

	rollout testTabs "Test Tabs"
	(
			dotNetControl dn_tabs "System.Windows.Forms.TabControl" height:20 width:420 align:#center
			subRollout theSubRollout width:420 height:140 align:#center
			
			on dn_tabs Selected itm do
			(
				if LastSubRollout != (itm.TabPageIndex+1) do --do not update if the same tab clicked twice
				(
					for subroll in testTabs_Rollouts[LastSubRollout][2] do
						removeSubRollout theSubRollout subroll
					for subroll in testTabs_Rollouts[LastSubRollout = itm.TabPageIndex+1][2] do	
						addSubRollout theSubRollout subroll
				) 
			)--end tabs clicked		
			
			on testTabs open do
			(
				for aTab in testTabs_Rollouts do
				(
					dn_tabs.TabPages.add aTab[1]
				)
				for subroll in testTabs_Rollouts[1][2] do 
					addSubRollout theSubRollout subroll				
			)
	)

	createDialog testTabs 440 200
) 

I saved 4 .MS files under “C:\Program Files\Autodesk\3ds max 2008\scripts\TabTest” which looked like this:

File “rollout01.ms”:

	rollout testTabsRollout01 "Rollout 01"
	(
		spinner spn_spinner "Spinner"
	)
	append testTabs_Rollouts #("Rollout 01 From File", #(testTabsRollout01))

File “rollout02.ms”:

	rollout testTabsRollout02 "Rollout 02"
	(
		button btn_button "Button"
	)
	append testTabs_Rollouts #("Rollout 02 From File", #(testTabsRollout02))

File “rollout03.ms”:

	rollout testTabsRollout03 "Rollout 03"
	(
		label lbl_label "This is some text"
	)
	append testTabs_Rollouts #("Rollout 03 From File", #(testTabsRollout03))

File “rollout04.ms”:

	rollout testTabsRollout04 "Rollout 04"
	(
		colorpicker clr_picker "Color Picker"
	)
	rollout testTabsRollout05 "Rollout 05"
	(
		checkbox chk_box "Checkbox"
	)	
	append testTabs_Rollouts #("Rollout 04", #(testTabsRollout04,testTabsRollout05))

After running the master script, I got the same result as with the previous code, but now I can add more tabs by just adding MS files to the folder…

Thanks Bobo.

Extremely useful examples.
Can I suggest putting these examples into the Maxscript reference *.chm?

Looking further into what I want to achieve, a couple of additional factors cropped up…if anyone is free to lend a hand…?

  1. The ability to have coloured tabs (like Render Pass Manager by Grant A) and the ability to display clearly which tab is selected.
  2. I am going to have quite a few tabs, so will need to have 2 or maybe even 3 lines of tabs within the main UI. Is this possible? If so, does anyone know how to achieve this using the code Bobo has already supplied?
  3. Finally, are nested tabs possible which contain multiple different rollouts? ie: Can one of the tabbed windows contain an additional set of tabbed pages?

Thanks again,

Mike

1 Reply
(@bobo)
Joined: 1 year ago

Posts: 0

You will have to ask Grant which control he is using, it could be a custom one.

Most formatting questions are related to what DotNet can do with Tabs, there are a bunch of DotNet properties and methods to be tried out to find out how to change the colors, appearance, layout etc.
http://www.scriptspot.com/bobo/mxs9/dotNet/dotNetObject_System.Windows.Forms.TabControl.html

I don’t see why you wouldn’t be able to have a rollout containing another set of tabs and their own subrollouts, you will have to duplicate the tab management logic in that rollout’s code.