Notifications
Clear all

[Closed] Interesting challenge for MaxScripter

macroScript TEST_MacroDialog
	category:"TESTS"
	buttonText:"MacroDialog"
	toolTip:"MacroDialog"
	silentErrors:off
(
	rollout mcrrol "Macro Dialog" width:200
	(
		label lb "This is a test dialog" align:#center
	)
	
	on isChecked do (mcrrol.open)
	on execute do
	(
		if mcrrol.open then destroydialog mcrrol else createdialog mcrrol
		updatetoolbarbuttons()
	)
)

This is a “classic” macro script with a dialog inside.
You check the corresponding button to open the dialog and uncheck the button to close it. If you manually or programmatically close the dialog, the button sets to unchecked.

Great…

But the next time you run (execute from the editor or the listener) this macro script (let’s say you’re working on its code), how do you automatically close an already open dialog while doing so?

Condition: Cannot use additional global variables

16 Replies

I get this one prospective

macroScript TEST_MacroDialog
category:"TESTS"
buttonText:"MacroDialog"
toolTip:"MacroDialog"
silentErrors:off
(
	rollout mcrrol "Macro Dialog" width:200
	(
		label lb "This is a test dialog" align:#center
		on mcrrol close do updateToolbarButtons()
	)
	on isChecked do 
	(
		if GetDialogSize testCloseRollout == [0,0] then createDialog testCloseRollout else destroyDialog testCloseRollout
	)
	on isVisible do if testCloseRollout.open do destroyDialog testCloseRollout
	on execute do()
)
isneedfound = true
for i = 1 to actionMan.numActionTables-1 where isneedfound do 
(
	atbl = actionMan.getActionTable i
	for j = 1 to atbl.numActionItems do
	(
		aitm = atbl.getActionItem j
		aitm.getDescription &desc 
		if desc == "MacroDialog" do
		( 	
			aitm.isVisible
			isneedfound = false
		)
	)
)
1 Reply
(@denist)
Joined: 10 months ago

Posts: 0

by the way… it doesn’t close the opened dialog.
but like I said, the direction is right.

Excellent! You’re heading in the right direction. Now we just need to place everything inside the body of the macro definition.

using the #isVisible handler is probably too “hack”.

maybe different from os , in Chinese os , I can’t trigger the closeDialogs handler (maybe this was canceled secretly), but with isVisible , i can close correct ,the demo code should ensure there’s only one action’s description was “MacroDialog”

I tested it ,1st I wrote wrong roullout name , 2cd the close should be before mcr defined , and we couldn’t createdialog in isChecked handle , as it will trigger again and again when we change active viewport
so define script should be what you post ,and isVisible to close , run actionMan to close before redefine

 MZ1
macroScript TEST_MacroDialog
Category:"TESTS"
buttonText:"MacroDialog"
toolTip:"MacroDialog"
(
	rollout mcrrol "Macro Dialog" width:200
	(
		label lb "This is a test dialog" align:#center
		on mcrrol close do
		(
			mcrrol.visible = false
			updatetoolbarbuttons()
		)
	)
	on isChecked do mcrrol.visible
 	on execute do if mcrrol.visible then DestroyDialog mcrrol else CreateDialog mcrrol
)
 MZ1

The macro can be anywhere, menus , right-click context menu, … So searching toolbar doesn’t work.

First, the #visible property is new for rollout (2021+).

In any case, using #visible property instead of #open does not solve the problem.

We are trying to solve how to close the currently open dialog in a macro script when we redefine the macro (for example, when manually evaluating the code).

if we put create and close in ischecked like what i post, it really only work with toolbar , put them in execute ,it will be fine with menu or quat menu , the only bug is state of button wasn’t change untill click in viewport some times

Page 1 / 2