[Closed] A very simple macro – how to assign to a key?
I have a very simple set of macro commands that I have recorded in the MAXscript listener. I was able to drag and drop the contents to a toolbar, but I want to assign it to a keystroke. Any help would be appreciated. Basically I just want the keystroke to change the viewport to Perspective View; Zoom Extents the selected object; then enter into Arc Rotate mode. The code looks like this:
macroScript Macro1
category:“DragAndDrop”
toolTip:””
(
max vpt persp user
max tool zoomextents
max rotateview
)
If I save this as a *.ms file and assign a key to it, I get an error message.
Joel
In Customize UI dialog, instead of going to Toolbars tab, go to Keyboard tab. Navigate to DragAndDrop category, find the Macro1 and enter the keystrokes in the field to the right. (If the keystroke is already assigned somewhere else, you will be informed).
Then save the Customized UI and exit the dialog. When you press the defined keyboard shortcut, your macro should be executed…
Of course, it is a better idea to change the category and name of your macro to something more obvious…
UThanks for your help Borislav.
It works like a charm if I leave the catagory as “Drag and Drop” (which I don’t care for). I tried changing the category to “Tools” but it doesn’t show up under tools. Also, I want to put the file under the max/ui/macroscripts directory (makes sense since the other scripts are there), but if I edit the script from say, a button… it then wants to save the file in convoluted space like c:\Documents and Settings\Administrator\Local Settings\Application Data\Autodesk\3dsmax\9 – 32bit\enu\ui\usermacros. Yuck! What could I be doing wrong here? And also, is there a difference between the ms and mcr extension? Sorry if that sounds like a dumb question – I’m not well versed in scripting (but I’m trying).
Thanks,
Joel
Edit: Well I got it to work when I placed the ms file in the Scripts/Startup folder… That’s good enough for me!
Somebody does not read the manuals
As I pointed out many times (incl. in the Reference), MacroScripts manage themselves.
You just Evaluate the code and the .MCR will be created in the correct UI/Macroscripts folder (in Max 9 it goes to the user’s UI/Macroscripts folder as you described below because when Vista comes out, you might not have enough priviledges to write into a Program Files subfolder at all…)
You SHOULD NOT save the .MS file into the Scripts/Startup folder, but rather in the \Scripts folder which does not get evaluated each time Max is started. Open Max, load the .MS source with your code, press Ctrl+E and the corresponding .MCR file with name containing the Category and the Macro name will be written where Max can see it at launch time (you DON’T CARE where that is, it is Max’ business to manage these). You can make changes to your source .MS file and keep on saving (iterations, if you want) to your \Scripts folder or any other folder you like. When you make a change you want to keep and use, just hit Ctrl+E and the Macro will be automatically updated. If there is already a button/menu/shortcut using that Macro, it will be updated to use the new version automatically, too. Next time you boot Max, it will find the latest .MCR file in the Macroscripts folder and keep on using it. If you want to make changes to that code, you better open the original .MS file again and repeat as described above. DO NOT open the .MCR files from the \Macroscripts folder for editing. Do NOT save your own files to the \Macroscripts folder unless you are instructed to by a 3rd party installation readme file.
Here is an example of what could happen in your current configuration:
*Let’s say you have your .MS in Scripts\Startup and your .MCR file in Ui\Macroscripts folders.
*There is some small bug you forgot to fix and while using the Macro inside of Max, an error occurs and the source code opens.
*You find the problem, save the file without noticing that the file opened is the source Max knows about – in other words the .MCR!
*Next day you start Max again – the .MS file in Scripts\Startup gets evaluated and OVERWRITES the .MCR file automatically.
RESULT: Your bug fixes are GONE!
Hope this helps.
Bobo,
Thanks for taking the time and having the patience to explain this to me. I could have guessed that there was a specific reasoning for the file extensions and their respective locations. I’m better informed now – knowing how to handle these files and what not to do. Thank you.
Just to clarify, my mode of thinking is that I would like to keep these files organized myself – for example, when max 10 is unveiled, I’ll be able to transfer my scripts easily and without having to search for them buried in some obscure folder. And the restrictions regarding Vista don’t sound entirely positive if I understand you correctly. I like organizing my files my way, which is not necessarily the Microsoft way.
I’ve got this simple script working in the Scripts folder as you suggest, so I’m happy with the result. Thanks again.
Joel
You can organize your files like this:
*Create a directory for MAXScript development independent of the Max installation, somewhere on any drive you like. Keep the .MS sources of your scripts there.
*For each MACROSCRIPT you write, make sure you give a meaningful Category. Of course, you can prefix the name of the category with some unique identifier like your initials. This means that any .MCR file created automatically by MAX from your code would have the same prefix in the file name and would be easily identifiable.
*When a new version of Max is released, you can either collect all .MCR files from the UI\Macroscripts that have your special prefix in the Category part of the name, or evaluate the sources from your development directory as you need (for example by simply dragging and dropping them onto the toolbar of Max, or by using the MAXScript>Run Script).
*Another way to quickly evaluate all your sources would be to temporarily specify the root of your development folder as a valid Plugin path. Since Max evaluates automatically ANY .MS files found in Plugin paths AND THEIR SUBFOLDERS (!), just launching Max once would evalute all scripts from your dev. directory and recreate all .MCRs. Then you could remove the path from the plugins dir. list again. Of course, this would only work assuming your dev. directory contains only the latest versions of the scripts and not multiple iterations (as it would be impossible to ensure that the latest version would be evaluated last).
Ok, that works if your scripts are blocks of code inside a “macroscript” block.
What if you have a collection of utility functions, structures, and other re-use code. I think you still have to keep your source code in the “stdscripts” folder so that you can access it from other macroscripts.
Yep, as you can see, the whole topic is about how to deal with MacroScripts.
If you are at the level of writing functions in \Stdscripts, this thread is not for you anyway
I am sure you would have no trouble moving your Max 8 custom functions into the corresponding folder in Max 9 without my help, right?
Bobo,
Again, thanks for all of the great information.
I must admit, I’ve always known that even the slightes bit of scripting knowledge would allow me to work smarter not harder. I’ve been affraid of it for far too long and my lack of imagination regarding how to use it, well that just won’t cut it any longer. You’ve convinced me to invest in your DVD!
Sincerely,
Joel Gray
My last silly question for this post – I promise.
Why do I get MaxScript Debugger windows when I start up Max? Did I do something wrong, or is there a good reason for these?
Joel