Notifications
Clear all

[Closed] A "last tool used" script

Hello, I’m still very new to max script, and I’m trying to replicate the function in maya that uses whatever tool that you last used, in max. The only thing I can think of for this, is somehow first enabling the macro recorder and using the most recent command in it. And maybe, to somehow only use the commands that start with macros.run. Unfortunantly, I don’t know how to accomplish any of these.

I did try using-

mrBuffer = macrorecorder as string 
 mrCommands = filterString mrBuffer "
\r" 

Which I found here-
http://forums.cgsociety.org/showthread.php?f=98&t=590040&highlight=macrorecorder
When I use this in the listener after going into extrude mode on a mesh, it returns-

#("macros.run "Editable Polygon Object" "EPoly_Extrude")
 OK

But it doesn’t return me to the extrude mode, which would make sense since, vScourge says that this gives you an array of command strings to manipulate, but I’m not sure how to get the recent command from that array. But I’m not sure if this is even the right way to go for this kind of script, so if anyone could help me, I would greatly appreciate it.

3 Replies
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

--macrorecoder is <WindowStream>. 
str = macrorecoder as string -- it's a string now
commands = filterstring str "
" -- lines of macrorecoder as array in order from first to last
last_commands = commands[commands.count] -- this string is the last line in macrorecoder 
try(execute last_command) catch() -- try to execute last line (might not be executable)
 

Hello, thanks for your reply. I just recently tried your code, and unfortunately it doesn’t seem to work. I tried pasting it in the maxscript editor and evaluating it and the listener says-

"undefined"
#("undefined")
"undefined"
undefined

And pasting it into the listener just says undefined after entering it. Another problem with this, is that when using this as a macro, I think it won’t work because it lists the macro itself being run in the macrorecorde, so you would somehow have to have the macro execute the second to last command, but I could be wrong.

Sorry… I misspelt… Here is it:


 str = macrorecorder as string
 commands = filterstring str "
"
 if commands.count > 0 do last_commands = commands[commands.count]
-- format "%
" last_commands
 try(execute last_command) catch()