here’s my script :
[color=Lime]/*
script: assigns the given shortcut to the given macro script
the function takes 3 arguments the hotkey the macro script name and the category of the macro script
on failure the function returns 0 else 1
-- by Charles Bary
*/[/color]
(
fn Assign_Hotkey user_hotkey macro_name macro_category =
(
--Load The current keyboard shortcuts into memory
local filename = actionman.getkeyboardfile() as string,
File_handle = openFile filename mode:"a+",
File_line,
Formated_String = #(),
index_value =0,
mod_keys = #(),
ascii = #(),
i = 0
while not eof File_handle do
(
i+=1
File_line = readline File_handle
Formated_String = filterstring File_line "= "
try
(
if formated_string[formated_string.count] == "647394" do
index_value = formated_string[1] as integer + 1
mod_keys[i] = Formated_String[2] as integer
ascii[i] = Formated_String[3] as integer
if ascii[i] < 93 and ascii[i] > 64 do
ascii[i] = ascii[i] + 32
)
catch()
)
--Generate The Output Data for the hotkey from the input
user_hotkey = tolower user_hotkey
local formated_key = filterstring user_hotkey "+",
user_mod_k= 0,
user_ascii = 0,
j = 1
for j = 1 to formated_key.count do
(
case formated_key[j] of
(
"ctrl": user_mod_k = bit.or user_mod_k 11
"alt": user_mod_k = bit.or user_mod_k 19
"shift": user_mod_k = bit.or user_mod_k 7
default: user_ascii = bit.charasint formated_key[j]
)
)
--Check For conflict with existing hotkeys
local flag = 0
for j = 1 to i do
(
if user_mod_k == 0 then
if (ascii[j] == user_ascii) do
flag = 1
else
if ((mod_keys[j] == user_mod_k) And (ascii[j] == user_ascii)) do
flag = 1
)
-- Assign the shortcut to the specified macro
if flag == 0 then
(
format "%=% % %`% 647394
" index_value user_mod_k (user_ascii-32) macro_name macro_category to:file_handle
--format "%=% % %`% 647394
" index_value user_mod_k user_ascii macro_name macro_category
actionman.loadkeyboardfile filename
print "Hotkey assigned successfully!"
close File_handle
return 1
)
else
(
close File_handle
print "Hotkey already assigned choose another"
return 0
)
)
-- function call
Assign_hotkey "shift+ctrl+alt+c" "book_rigger" "my_scripts"
)
Enjoy!
Very nice! I’ll have a closer look at the script tomorrow, but I’m sure that it’ll work fine.
Thanks very much for your help!
And then there was me, arrogantly thinking it couldn’t be done, this is really great! Thanks for sharing!
-Johan
sure, no problemo! but the script is far from complete for instance it cannot assign keys other than the combination of alphanumeric characters and the modifier keys also it does not check if the macro supplied is installed or not, may be i will implement these features and post
cheers!
I’ve had a look at the script and started implementing functionality to replace hotkeys from the mainUI (0) and ‘user’ (647394) group.
Now the interesting thing is, if you just remove a line for the keyboard file, right in the middle of a sequence, max copes with it just fine. In fact, when it saves the file itself, all indices are fixed again.
Having to fix all the indices manually could be quite a pain, so I’m thinking, how much of a sin would it be do just do it the ugly way by cutting out a line and leaving it at that?
( )
:hmm: when you execute the command
actionman.loadkeyboardfile()
it fixes the indices in the .kbd file so i dont think its necesarry to fix the indices your self even i havent done that in my script … i dont really like this way of coding as there is no documentation (atleast i couldnt find one) about the kbd file so i cannot tell for sure wether the script will work on all the O.S i mean the number (647394) is still a little mysterious and the entire script is based on the number and thats what is really “ugly” about the script, what if it changes in the next version of max … so theres lot of uncertainity about the script, but it works fine on my version of max, may be the better way of coding this would be reading the mainui file and retrieving this number from the file and then using it inside the script that way i think 1 can be assured that it will work on all O.S
however i googled this number and found a couple of kbd files people have posted on the web and all of them have this number, heres 1 :
http://www.resistdesign.com/media/ryan.kbd
Yes it all remains a bit tricky. I think that the least we should do when using the script is making a backup of the users kbd file, just in case something goes horribly wrong.
I was playing around with macro recorder the other day and found some thing interesting about the numbers showing up in the listener for instance :
actionMan.executeAction 0 "50002" -- Tools: Select and Rotate
the number 50002 is of interest here it can be found in the keyboard file :-
13=3 69 50002 0
which is the shortcut key for rotate “E”
also this number is found in the MaxStartUI file -the file contains information about the menus and the buttons inside them as well as the action numbers associated with each button in the particular menu which tell Max to execute the specific action when the button is pressed, In this case the action number associated with rotate button in the edit menu is 50002 max processes this number by calling the function responsible for showing the rotaion gizmo – :-
Item10_Action=0|50002
CustomTitle_10="Rotate"
next, when i performed actions like going to the edit>Transform Toolbox here’s what the macro recorder shows :
macros.run "PolyTools" "TransformTools"
the correspoing entry in MaxStartUI file reveals this:
Item_13_Mode=2
Item13_Action=647394|TransformTools`PolyTools
this led me to conclude that this number (647394)actually represents an action code which the windows procedure of max processes and decides to call the macros.run command and probably takes as the parameters the values “TransformTools” and “PolyTools “
therfore the line in the kbd file 0=19 69 EPoly_Extrude_Along_Spline`Editable Polygon Object 647394 means pass the macro name “EPoly_Extrude_Along_Spline” in the category “Editable Polygon Object ” to the function 647394 which max regards as macros.run function when the keys
19 69 are pressed i.e ALT+E