Macroscript not jumping to Object's baseobject (modpanel)

Hey guys, after a lot of writing / testing / deleting, I seem to have arrived where I wanted to - a script which toggles a "jump" down to an objects lowest modifier, on a selection change, and when used in a toolbar with visual feedback whether this mode is active. When using my base-jump function on its own, it works fine.. in conjunction with the macro, nothing happens when active (despite my debug messages saying everything works). Does anybody have an idea what might be wrong?

(I'm no scripting wiz as is apparent - I'm rather sure it's to do with the callbacks somehow?)

Thanks in advance for any answers!

macroScript ModifierAutoSelectToggle
	category: "MyTools"
	toolTip: "Visualize AutoModSel Toggle"
(
	ModAutoSelectActive == true
	on isChecked return (ModAutoSelectActive)
	global ModAutoSelectNoUi
 
	function ModAutoSelectNoUi = (
		objSel = getCurrentSelection()	
		if objSel.count == 1 do (
			max modify mode
			modPanel.setCurrentObject objSel[1].baseobject
			format "Stack of % jumped to % \n" objSel[1] objSel[1].baseobject
		)
	)
 
	on execute do (
		if ModAutoSelectActive == true then (
			ModAutoSelectActive = false
			format "ModAutoSelectActive set to: % \n" ModAutoSelectActive
			callBacks.removeScripts id:#ModAutoSelectNoUiCallback
			format "Callback removed \n"
		)
		else (
			ModAutoSelectActive = true
			format "ModAutoSelectActive set to: % \n" ModAutoSelectActive
			callbacks.addScript #selectionSetChanged "ModAutoSelectNoUi()" id:#ModAutoSelectNoUiCallback
			format "Callback added \n"
		)
	)
)

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jahman's picture

.

imagine that we want to go to the baseobject level to add some modifier to multiple instance nodes at once
we select these nodes
set baseobject as current level
modPanel.setCurrentObject selection[1].baseobject
buuut... we have a problem now. selection is changed to single node

here is another way

case selection.count of
(
	0 : ()
	1 : ( max modify mode; modPanel.setCurrentObject selection[1].baseobject )
	default: 
	(
		max modify mode
		base = makeUniqueArray (for s in selection collect s.baseobject)
 
		if base.count == 1 do ( -- only if all nodes share same baseobject
 
			while modPanel.getCurrentObject() != base[1] do 
			(			
				max prev mod
			)
 
		)
 
	)	
 
)
mistyrian's picture

First floor

I'm a script beginner too , the Script "Modifier auto-select" in the website is invalid in max 2019 . I feel depressed that no one answered your question . so I spent a few days to study some relative content .

I think the porblem may be on #selectionSetchanged , in this case selectionchanged is better , but I don't find it in General event callback Mechanism of MAXScript Help , so I use #modPanelObjPostChange instead Here is my script ,I only tested it a few times , There are may be some problems .

macroScript bms_toggle
category:"All MyScripts"
tooltip:"bms toggle"
buttontext:"bms toggle"
(
global bms
function bms =
(
if selection.count==1 then (
callbacks.removeScripts #modPanelObjPostChange id:#bms
max modify mode
modPanel.setCurrentObject $ -- open on base object
callbacks.addScript #modPanelObjPostChange "bms()" id:#bms
)
else
(
print "empty selection"
)

)

cb = false

on execute do
(
if cb then
(
callbacks.removeScripts #modPanelObjPostChange id:#bms
print "callbacks removed"
cb=false
)
else
(
callbacks.addScript #modPanelObjPostChange "bms()" id:#bms
cb = true
)
)

on isChecked do cb

)

mistyrian's picture

another one

this one is very simple and original ,My knowledge are very limited. it is a very low-end approach.but it works better

AttachmentSize
bt_toggle.zip 1.19 KB

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.