Notifications
Clear all

[Closed] rolloutFloater closing/opening issues in macroscript

I’m new to rolloutfloaters and I am having a small issue. This issue doesn’t happen when I comment out the macroscript definition, it only happens when I’m doing this from within a macroscript. I’m using closerolloutfloater to close any existing versions of the UI the same as I would use destroyDialog to close any preexisting versions of a dialog before a script opened another one.

I have 2 rollouts in this rolloutfloater so far. The problem I’m having is that when I execute the macro from a quadmenu or toolbar when a version of the rollout floater is already open, the old one closes but the new one only has one of the rollouts visible in it. The floater is still acting as though the second rollout is there, but it is not visible. The reason I say it’s acting as if it’s there is because I have a function that resizes the floater when the rollouts are rolled up/dn. And it seems to be leaving the correct gap for the “invisible” rollout.
The code for this is 1600+ lines long so it’ll take me quite some time to extract all the relevant bits to be able to post. So I thought I’d just throw it out there to see if someone had a quick answer before spending the time.

Cheers,

Cg.

7 Replies

Does not ring a bell, please try to write a simple case with two rollouts and a floater with the same general layout. The content of the rollouts does not matter.

Thanks for the super quick reply Bobo. I took all the elements of the script that create the UI and I can’t seem to recreate the issue. Looks like I might just have to go through and start comenting parts of the big script out to try to find what’s causing it. I’ll post back when I find the problem.

Cg.

The issue seems to be:

on rlt_TVCBRS_ShotSetup close do setIniSetting uiIniFile "Dialog" "Position" (baseRenderSetupDialog.pos as string)

I think I got that kickass method for saving dialog positions from one of your DVD’s Bobo. I’ve used it for a long time on all of my scripts that use dialogs. Sadly it doesn’t seem to work for rolloutFloaters in the same way that they’ve worked for me with dialogs. Do you have any suggestions on how to implement that kind of thing when I need to use rollable rollouts?

Pretty sure I used the event handler on the rollout close cause I couldn’t find a way to have an event handler for the rollout floater close.

Cheers,
Cg.

It is supposed to work as long as the position is of the TOP rollout.
The Floater lets the top rollout handle its position and resizing events, and it works for me (Krakatoa does that, for example).

So you could also use

on rlt_TVCBRS_ShotSetup moved pos do 
  setIniSetting uiIniFile "Dialog" "Position" (pos as string)

assuming rlt_TVCBRS_ShotSetup is the top rollout.

Can you send the simplified example with the handlers implemented to demonstrate the issue?

Here’s a very cutdown version. I tried swapping the event handler to the top rollout as you mention, but then both rollouts are not visible when I execute the script from a toolbar (when the dialog has already been opened). I haven’t had a chance to try your other suggestion to use the move event handler yet.

macroScript TVC_baseRenderSetup
 category:"CgRay"
 (
 	clearlistener ()
 
 	global baseRenderSetupDialog,rlt_TVCBRS_Settings,rlt_TVCBRS_ShotSetup
 	
 	try (closerolloutfloater baseRenderSetupDialog )
 	catch (format"error closing stuff
")	
 
 	local uiIniFile = getDir #plugcfg + @"\baseRenderSetupUI.ini"
 
 	fn autoFloaterHeight =
 	(
 		spacer = 4
 		theHeight = 45
 		if rlt_TVCBRS_ShotSetup.open do
 		(
 			theHeight += rlt_TVCBRS_ShotSetup.height
 			theHeight += spacer
 		)
 		if rlt_TVCBRS_Settings.open do
 		(
 			theHeight += rlt_TVCBRS_Settings.height
 			theHeight += spacer
 		)
 		baseRenderSetupDialog.size.y = theHeight
 	)
 
 	
 	rollout rlt_TVCBRS_Settings "Settings"
 	(
 		on rlt_TVCBRS_Settings rolledUp state do autoFloaterHeight()
 	)
 	
 	rollout rlt_TVCBRS_ShotSetup "Shot Setup"
 	(
 		on rlt_TVCBRS_ShotSetup close do setIniSetting uiIniFile "Dialog" "Position" (baseRenderSetupDialog.pos as string)
 		on rlt_TVCBRS_ShotSetup rolledUp state do autoFloaterHeight()
 	)
 	
 	baseRenderSetupDialogPos = execute (getIniSetting uiIniFile "Dialog" "Position")
 	if baseRenderSetupDialogPos == OK do baseRenderSetupDialogPos = [100,100]
 
 	baseRenderSetupDialog = newRolloutFloater "Iloura_TVC_baseRenderSetup_280" 395 218
 
 	baseRenderSetupDialog.pos = baseRenderSetupDialogPos
 
 	addrollout rlt_TVCBRS_Settings baseRenderSetupDialog rolledUp:true border:true
 	addrollout rlt_TVCBRS_ShotSetup baseRenderSetupDialog rolledUp:false border:true
 )
 
 

Cheers,

Cg.

That’s an easy fix.
Just move the closeRolloutFloater() call JUST BEFORE the newRolloutFloater() line.
Other than DestroyDialog which MUST be called BEFORE redefining the rollout variables, closeRolloutFloater() should be called AFTER the rollouts have been redefined.

The logic goes something like this:
createDialog() changes the display mode of a rollout. It is the ROLLOUT that becomes a dialog, and if you redefine the variable holding the rollout before the dialog is closed, you will lose the pointer to it and won’t be able to ever access it.

newRolloutFloater() makes a new floater object which is host of the rollouts. It uses a pointer at the original rollout definition itself, not the variable holding it. So when you run the script the first time, you can ask after that

baseRenderSetupDialog.rollouts[1] == rlt_TVCBRS_Settings
-->true

As you can see, the rollout defined and pointed at from rlt_TVCBRS_Settings is the same as the rollout living in (and pointed at) the floater.
If you call closeRolloutFloater() now, the rollout floater closes, but IT STILL EXISTS, and is still pointing at that rollout!

try (closerolloutfloater baseRenderSetupDialog )catch()	
-->OK
baseRenderSetupDialog.rollouts
-->#(Rollout:rlt_TVCBRS_Settings, Rollout:rlt_TVCBRS_ShotSetup)
baseRenderSetupDialog.rollouts[1] == rlt_TVCBRS_Settings
-->true
baseRenderSetupDialog.rollouts[2] == rlt_TVCBRS_ShotSetup
-->true

Now if you redefine the rollouts, you get new rollout objects stored in the variables, but the old closed floater still holds pointers at the old rollouts. You now have two rollouts – the floater holds the old one hostage, the global variable holds the newly defined one:


baseRenderSetupDialog.rollouts
-->#(Rollout:rlt_TVCBRS_Settings, Rollout:rlt_TVCBRS_ShotSetup)
baseRenderSetupDialog.rollouts[1] == rlt_TVCBRS_Settings
-->false

I am not sure what exactly goes wrong at this point, but creating a new rollout floater into the same variable seems to confuse MAXScript when inside a MacroScript body. It works nicely without the MacroScript around it (as you reported). I suspect that something does not get updated internally until the whole MacroScript body has finished executing, and somehow the new floater thinks the second rollout is still being used in the previously closed but still existing rollout. Since a rollout cannot be displayed in more than one floater, it does not add.

So if you redefine the two rollouts before closing the floater, this magically fixes the problem.

I could be wrong, but that’s what I know about it.
Try changing the code to

 	try (closerolloutfloater baseRenderSetupDialog )catch (format"error closing stuff
")	
 	baseRenderSetupDialog = newRolloutFloater "Iloura_TVC_baseRenderSetup_280" 395 218

and see how it goes…

Fantastic. Problem solved by moving 2 lines of code. Thanks so much for taking the time to explain all that when you could have ended the post at the second line. You are truly a generous being.

Cheers,

Cg.