View Full Version : Record Commands?
Camaron47
03-17-2010, 09:59 PM
I just had the rather ambitious idea to make something that automatically adds commands to a shelf button. The normal way to do this is to do whatever tasks it is you want to add to the shelf, go into the script editor, highlight the code, and add it to the shelf. What I'm wanting to do is somehow pass those same commands through to a procedure, and then add that to the shelf, alleviating the need to go in and copy and paste the code manually. Is there any easy way to do this? Has it been done before in another script?
Here is my idea for the UI portion. Basically it'll have a record button and a play button, along with a text scroll list of the commands (which basically act as the shelf). When the user hits record, they can do their various tasks, then stop recording. All the stuff they did will be "recorded" somehow and put into a procedure. They then name it, it's added to the TSL, and they can select it any time and hit Play and it'll do whatever it is they recorded. Or for the savvy coder types, they can do it the same way they normally do, and add it to the TSL either way. The main thing is I don't know to "record" whatever is being done, i.e. with Echo All Commands in the script editor.
It might be overkill, but then it might be awesome as well. And I honestly can't think of how to do it.
stwert
03-18-2010, 11:42 AM
Like a macro recorder? Sounds pretty cool, not sure how to make it though. Hope you figure it out.
chrisg
03-18-2010, 04:39 PM
Hi Camaron47,
Cool idea. I looked through the Command Reference earlier and couldn't find anything, but I just looked again and found the scriptEditorInfo command which looks promising.
I don't know the specific implementation, but here are a few tidbits.
// first, clear the history
scriptEditorInfo -clearHistory;
// Begin recording the Script Editor history to a file called
// tempHistoryLog.mel in your maya directory.
scriptEditorInfo -historyFilename "tempHistoryLog.mel" -writeHistory true;
// Stop recording the Script Editor history
scriptEditorInfo -writeHistory false;
Then you just need to connect up the .mel file to a new shelf button. In theory, it sounds like it could work. In reality, you'll probably still need to go into the script file and edit things like changing the absolute object names to some sort of relative thing based off selection, and do a bunch or error checking if they select multiple objects, the wrong type of objects, etc.
Camaron47
03-18-2010, 09:54 PM
Yeah after experimenting it seems the only way to do it is to write to a file, which the user can then edit if need be.
I'll keep messing around with it and let you know what I find.
Camaron47
03-18-2010, 10:51 PM
Ok cool, I figured out how to record and write to a file. Now I need to be able to source the file in real time and execute the commands, which would otherwise require restarting Maya. If I can do that, this little script just might become a reality.
Thoughts?
Also, bravo2zero, let me understand correctly: you're suggesting I add a menu item of the macro that has been recorded, and edit the path that it's saved to? In any case I need to worry about the main functionality first, and I'm already running through the features that will be necessary for it to work. I'm also looking into, as I said before, adding the code line by line to a textScrollList, so as to visually edit the so-called "macro" and truncate anything that might give an error or not execute properly.
Camaron47
03-18-2010, 11:51 PM
Ok well, one thing at a time. I need to figure out how to a) add the code line by line to a TSL and execute them accordingly when selected and b) source the new file that has been written in real time without having to restart Maya/copy the text from said file and use textToShelf or whatever.
I was also messing around and I figured out it would be hard to give the files names because when I do for example:
string $name = "test1.mel";
Where "test1" would be the name that the user specifies in a textField, if I try to pass that through to a source statement like so:
source $name;
It gives a syntax error. These are the main issues I need to deal with first. Your suggestion is still quite confusing, but I'll look at it again later once I figure these things out. No offense, but there's no point in doing all that if I can't get the "useful" stuff to work first.
Camaron47
03-19-2010, 12:27 AM
Yeah that works, thanks.
What about the other stuff?
Camaron47
03-19-2010, 12:57 PM
Thanks for all the help, I now have the very basic functionality going and will be posting it soon.
Camaron47
03-19-2010, 10:15 PM
Ok got a lot of the stuff working now, now I need to figure out how to load all the files in a given folder. So for example I've created a directory called Macros inside of the /Scripts directory, and what I need to do is source each file in the directory one by one and add it to the TSL.
Camaron47
03-20-2010, 12:47 AM
Thanks for all the help, you guys are awesome. I'll have an initial release soon.
Camaron47
03-20-2010, 02:45 PM
Initial version released. Couldn't have done it without your guys' help. Thanks again!
http://www.creativecrash.com/maya/downloads/scripts-plugins/animation/c/macro-mania
http://worldstallestanimator.blogspot.com/2010/03/macro-mania-10.html
chrisg
03-20-2010, 04:25 PM
cool stuff! Looks like you have it working well for what you need it to do.