Notifications
Clear all

[Closed] Get value from element in other DotNet Tab

Hi there!

I’m currently writing some script which uses DotNet to creaty a tabbed Dialog.

Here’s te Code:

	testTabs_Rollouts = #(
 		#("Source",#(rigRollout)),
 		#("Projectile",#(typeRollout, propertiesRollout, physicsRollout, impactEventRollout)),
 		#("Target",#(targetRollout)),
 		#("Animation",#(animationRollout))
 	)	
rollout mainTabs "EasyShooter 0.1a"
 	(
 			dotNetControl dn_tabs "System.Windows.Forms.TabControl" height:20 width:420 align:#center
 			subRollout theSubRollout width:420 height:560 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 mainTabs clicked		
 			
 			on mainTabs 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 mainTabs 440 600 pos:[50,50]

Now the Problem is as follows: I know I can access UI elements in another Tab/Rollout by typing rolloutname.property.
And I’m doing that, BUT: I need a value from a Spinner which I set at the Point the Rollout is created (logically). So when I call this value from another Rollout and didnt have the rollout with the value contained open before, it didnt get created and the value returns 0.

How tell the DotNet Dialog to “precreate” all rollouts and not create them at the point where i click the coresponding Tab?

11 Replies

You could save the values in a global variable.

Nah, the Problem is rather that those values arent created until I first open the rollout, which is not neccassarily the case.

Guy this is really important. I “recreate” the rollouts everytime I press another Tab. Is there any way to NOT do this?

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

do it other way:


try(destroydialog tabRols) catch()
rollout tabRols "Tab Rolls"
(
	rollout source_01 "Source Rollout"
	(
		label lb "Source"
	)
	rollout project_01 "Project1 Rollout"
	(
		label lb "Project1"
	)
	rollout project_02 "Project2 Rollout"
	(
		label lb "Project2"
	)
	rollout target_01 "Target Rollout"
	(
		label lb "Target"
	)

	local tab_rollouts = 
	#(
		 #("Source",#(source_01)),
		 #("Project",#(project_01, project_02)),
		 #("Target",#(target_01))
	 )	

	dotNetControl tabs "System.Windows.Forms.TabControl" height:20 width:420 align:#center
	subRollout subRol_0 width:420 height:560 align:#center pos:[10,30]
	subRollout subRol_1 width:420 height:560 align:#center pos:[10,30] visible:off
	subRollout subRol_2 width:420 height:560 align:#center pos:[10,30] visible:off
	
	local sub_rollouts = #(subRol_0, subRol_1, subRol_2)
	
	on tabs Selected e do
	(
		for k=0 to tabs.TabPages.count-1 do sub_rollouts[k+1].visible = (k == e.TabPageIndex)
	)
	
	on tabRols open do
	(
		for k=1 to tab_rollouts.count do 
		(
			tabs.TabPages.add tab_rollouts[k][1]
			for r in tab_rollouts[k][2] do addSubRollout sub_rollouts[k] r
		)
	)
)
createDialog tabRols 440 600 pos:[50,50]

No, I had the same problem in mr Options. Create a global array or something containing the default values.

 JHN

Why not just create all rollouts offscreen/offdialog. As you have noticed a rollout gets reinitialized when it’s created. So you can never get good values from the rollouts decleration state when it’s not added to a subRollout or called by createDialog. The only way is to initialize the rollouts in a subRollout control and move that control offscreen. What I do when I need a value injected into a new to open rollout is to define a unique global variable and in the rollout open handler call that global variable and propagate the vars to where I need them to be. I think Kameleon means the same thing.

My 2 cents,
-Johan

Thanks, DenisT! I’ll try that out!

At other replies: I’m not so very familiar with maxScript and I head to “avoid” globals because they “pollute” max’s global space or sth, is that right?

Edit: Yay, works perfectly, many Thanks! :bowdown:

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

the using of globals are absolutely normal practice. sometimes there is no other way than use globals. the better practice is to put all data necessary for your tool in one structure with an original name.
i’ve never had any problems using custom global data, and don’t feel shame on myself for that.

 JHN

Jups, for every rollout that is a tool, I have at least one global to be able to access the rollout from whatever other tool needs it, and for the try destroyDialog in the beginning of the script.
I have a naming convention for my globals
Say I have a tool that does materialLibrary stuff:


 global JHN_roMyMaterialLibTool
 try destroyDialog JHN_roMyMaterialLibTool catch()
 
 rollout JHN_roMyMaterialLibTool "Fancy tool name here"
 (
   fn someNiceToolIwantTocall = print "hello world"
 )
 createDialog JHN_roMyMaterialLibTool
 
 JHN_roMyMaterialLibTool.someNiceToolIwantTocall()
 

So globals are at least needed for rollouts imho, but also for passing around data. I’ll alwas prefix a global with my handle JHN and then a long description of what the variable is, then I know, there’s never going to be a collision ever.

-Johan

Great solution Denis as always… I just didnt get the sub_rollouts[k+1].visible = (k == e.TabPageIndex) part… arent you overriding the k in the for loop? why just not sub_rollouts[k+1].visible = e.TabPageIndex ?

Cheers!

Forget about it, I’ve got it, didnt know that you could do a comparision in that form… it returns true or false if k is equal to the current tab, simple yet brilliant