What's wrong with my code? The buttons on the toolbar keep flashing after execution. Please help me


#1

01 Thank you

fn ti_model =

(
if selection.count > 0 do

(
if (classOf $ == Editable_Poly or classOf $ == PolyMeshObject) do

(
	macros.run "Modifier Stack" "Modify_Mode"
if subobjectLevel != 0 then 
( 
	max toggle keyboard shortcuts
	)

else

  max toggle keyboard shortcuts

)

)
)
registerRedrawViewsCallback ti_mode ; clearListener()


#2

You toggle the keyboard overrides button each time viewport gets redrawn and that’s why it flashes all the time.

-- works only if button exists on toolbar
Keyboard_Shortcut_Override_Toggle_ICustButton = ((dotNetClass "Autodesk.Max.GlobalInterface").Instance.CUIFrameMgr.GetICustButton 30761)

Keyboard_Shortcut_Override_Toggle_ICustButton.IsChecked -- state of the button
Keyboard_Shortcut_Override_Toggle_ICustButton.SetCheck true -- set state of the button

#3

Hi, serejah, thank you for your reply. I used your code, but after execution, the shortcut keys of standard mode and sub object mode collided. I don’t know why

fn ti_model =
(
if selection.count > 0 do

(
if (classOf $ == Editable_Poly or classOf $ == PolyMeshObject) do

(
	-- works only if button exists on toolbar
   Keyboard_Shortcut_Override_Toggle_ICustButton = ((dotNetClass "Autodesk.Max.GlobalInterface").Instance.CUIFrameMgr.GetICustButton 30761)
	Keyboard_Shortcut_Override_Toggle_ICustButton.IsChecked -- state of the button
	macros.run "Modifier Stack" "Modify_Mode"
if subobjectLevel != 0 then 
( 
	
    Keyboard_Shortcut_Override_Toggle_ICustButton.SetCheck true -- set state of the button
	)

else

  Keyboard_Shortcut_Override_Toggle_ICustButton.SetCheck false

)

)
)
registerRedrawViewsCallback ti_model ;-- clearListener()


#4

You could replace .SetCheck call with the original command (max toggle keyboard shortcuts) and see if it makes any difference.
Why do you use viewport redraw callback for this? There’re plenty other more appropriate callbacks listed in the mxs reference


#5

I don’t know MAXscript very well. I can only do some simple scripts. Can you give me an example? Thank you very much!!


#6

If you need to enable overrides for a particular modifier and certain subobjectlevels it could be achieved like this:
Read on the differences between NodeEventCallback system and General Event Callbacks system in mxs help to choose which one suits your task the best

In this example keyboard overrides are only active for Edit Poly modifier in Vertex and Face subobject level modes

Keyboard_Shortcut_Override_Toggle_ICustButton = ((dotNetClass "Autodesk.Max.GlobalInterface").Instance.CUIFrameMgr.GetICustButton 30761)

-- #1
global test_handler = undefined
gc light:true

fn OnEvent ev nodes =
(	
	local _modifier = modPanel.getCurrentObject()
	
	if isKindOf _modifier Edit_Poly do
	(
		if subObjectLevel == 1 or subObjectLevel == 4 then
		(
			if not Keyboard_Shortcut_Override_Toggle_ICustButton.IsChecked do
			(
				Keyboard_Shortcut_Override_Toggle_ICustButton.SetCheck true				
			)				
		)
		else
		(
			Keyboard_Shortcut_Override_Toggle_ICustButton.SetCheck false			
		)
		
		format "Edit_Poly - subObjectLevel:%\n" subObjectLevel
	)		
	
)

test_handler = NodeEventCallback subobjectSelectionChanged:OnEvent

delete objects
gc()
clearListener()
addModifier (box isselected:true) (Edit_Poly())


-- #2
/*
callbacks.removeScripts id:#test_keyboard_overrides
	
fn OnEvent =
(	
	local data = callbacks.notificationParam()
	format "SubObjectLevel	prev:%	current:%\n" data[2] data[1]
	
	local _modifier = modPanel.getCurrentObject()
	
	if isKindOf _modifier Edit_Poly do
	(
		if subObjectLevel == 1 or subObjectLevel == 4 then
		(
			if not Keyboard_Shortcut_Override_Toggle_ICustButton.IsChecked do
			(
				Keyboard_Shortcut_Override_Toggle_ICustButton.SetCheck true				
			)				
		)
		else
		(
			Keyboard_Shortcut_Override_Toggle_ICustButton.SetCheck false			
		)
		
		format "Edit_Poly - subObjectLevel:%\n" subObjectLevel
	)		
	
)
callbacks.addScript #ModPanelSubObjectLevelChanged "OnEvent();" id:#test_keyboard_overrides
*/

#7

I don’t inject memory detection, but directly run the following code,

Keyboard_Shortcut_Override_Toggle_ICustButton = ((dotNetClass “Autodesk.Max.GlobalInterface”).Instance.CUIFrameMgr.GetICustButton 30761)
Keyboard_Shortcut_Override_Toggle_ICustButton.IsChecked – state of the button
Keyboard_Shortcut_Override_Toggle_ICustButton.SetCheck true – set state of the button

Rresult,Shortcut keys are also conflicting and confusing. Therefore, I think the problem lies in the above code. Is there any other way to achieve this. thanks


#8

I see no other options.