Message 1 of 9
Macros Running In Secret?
Not applicable
09-15-2009
02:02 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Ok, so I've got this macro I made that replaces max's own isolate selection. It basically just hides everything that isn't selected and stores them in a selection set. If you run it and the selection set exists, then it knows it should unhide the objects instead. This has worked fine for a few years and still does (zero issues encountered).
...But I thought I'd add some visual feedback. My idea was to implement the "on isChecked" handler in the macroscript. This way the user could choose if they wanted visual feedback or not by simply putting the macro in a toolbar, that way it would appear pressed when in "isolation mode". This didn't take long to implement and works a charm ...kind of and this is where the problems begin.
It seems that macros or this macro is run every now and then. Like when after you've created created an object and rightclick (wtf), or when you maximize/minimize a viewport and so on. This is very visible to the user due to the nature of the script, hiding and unhiding objects. Furthermore when the macro is invoked in this way it appears to be running "silently" or in a special scope, because none of the print statements work. The macro is toggled on at max startup which might hint at the problem. If all macros are evaluated at startup they have to be done so in a special way, so that tons of dialogs aren't opened and objects created or whatever. I guess this is where the "on execute" handler comes in to play? How do you use it properly as things seem to work quite well without it.
I'd be very greatful if someone could explain this to me as I just can't figure out what is going on by simply looking at the code.
Below you will find the two versions of the script.
Version 1, no toggling, works fine.
Version 2, toggling enabled, serious problems. It needs to be in a toolbar to work at all.
Thanks in advance :)
...But I thought I'd add some visual feedback. My idea was to implement the "on isChecked" handler in the macroscript. This way the user could choose if they wanted visual feedback or not by simply putting the macro in a toolbar, that way it would appear pressed when in "isolation mode". This didn't take long to implement and works a charm ...kind of and this is where the problems begin.
It seems that macros or this macro is run every now and then. Like when after you've created created an object and rightclick (wtf), or when you maximize/minimize a viewport and so on. This is very visible to the user due to the nature of the script, hiding and unhiding objects. Furthermore when the macro is invoked in this way it appears to be running "silently" or in a special scope, because none of the print statements work. The macro is toggled on at max startup which might hint at the problem. If all macros are evaluated at startup they have to be done so in a special way, so that tons of dialogs aren't opened and objects created or whatever. I guess this is where the "on execute" handler comes in to play? How do you use it properly as things seem to work quite well without it.
I'd be very greatful if someone could explain this to me as I just can't figure out what is going on by simply looking at the code.
Below you will find the two versions of the script.
Version 1, no toggling, works fine.
--###########################################
MacroScript IsolateSelectionImproved
Category:"Benzie"
ToolTip:"Isolate Selection Improved"
buttontext:"IsoSel"
(
with redraw off(
if selectionSets!= undefined then
(
unhide selectionSets
deleteItem selectionSets "IsoSelTemporaryHidden"
)else
(
local tmpInvSelection = for obj in objects where (not (obj.ishiddenInVpt or obj.isSelected)) collect obj
selectionSets = tmpInvSelection
hide selectionSets
)
)
)--end macro
--################################################
Version 2, toggling enabled, serious problems. It needs to be in a toolbar to work at all.
--################################################
MacroScript Benzie_IsolateSelectionImproved
Category:"Benzie"
ToolTip:"Isolate Selection Improved"
buttontext:"IsoSel 2"
-- START MACRO
(
fn benzieIsolateSelection isolate:true =(
with redraw off(
if isolate == false then(
unhide selectionSets
deleteItem selectionSets "IsoSelTemporaryHidden"
)else(
local tmpInvSelection = for obj in objects where (not (obj.ishiddenInVpt or obj.isSelected)) collect obj
selectionSets = tmpInvSelection
hide selectionSets
)
)--end redraw
)--end fn
on execute do(
--I don't want to do anything but execute is needed for ischecked to work
print "in execute do"
)
on isChecked do(
if selectionSets== undefined then(
benzieIsolateSelection isolate:true
return true
)else (
benzieIsolateSelection isolate:false
return false
)
)--end is checked
)--END MACRO
--##########################################################
Thanks in advance :)