Join George Maestri for an in-depth discussion in this video Creating scripts in the Script Editor, part of Learning MEL Scripting in Maya.
- Now let's take a look at how to use the Script Editor window to create simple scripts. Now typically, you can use the history that Maya provides as the basis for your scripts. So I've got a simple scene here with table and chairs. And let's go into the Script Editor window and create a simple script. So like before, I just wanna go ahead and move one of the chairs. I'm gonna go ahead and select a chair and then just move that back about that much.
So what you can see here is that we have a command here that says move-r. Now I know that -r means relative to the existing position. And then here is the actual position that we're moving it. So we're moving zero in x, zero in y, and about 6.2 in z. Now if I want, I can take that command and copy it, so just highlight it and copy, and then I can right click and paste.
Now what it does, is it tells me that this move is a command. It highlights it in cyan, and then it basically just repeats what I have. So I paste it in this command. Now if I want, I can highlight this and just hit this execute button. So when I do that, it moves it back again. Now if I select, say, another chair, I can move that the same amount. So again, keep this highlighted and execute it, or execute it again.
Now this is great, but we can change this around a little bit. So if we wanted to, we could change our command. And say, let's say we didn't wanna move it six, we wanted to move it four. And let's say we wanted to move it also in x and y, so we wanted to move it four, four, and four. Now I can select another one of these, and again, I'm going to have that command executed. So now it's moved it differently. It's moved it up and in, and again, we can do this for this other one.
Now we also can change our command a little bit. Now this is something that I know, and we'll get to this in just a little bit. But if we want to, we can change it from move-r, which is relative to the existing position, to move-a, which is an absolute value. So if we wanted to, we could move this to say, the origin. Let's say we wanted to move it absolutely to the origin. So I wanna go zero, space, zero, space, zero, so x, y, and z are going to be zero for whatever object I have selected.
So select an object, highlight the script, execute it, it moves it back to its own zero position. Now this is the zero position in the channel box, so you're thinking it's going to move to the origin. But this actually has a zero position here, so let's take a look at this. So you can see that this is at 12.4800, and if we execute this script it basically zeroes out these values and the same thing here.
So as you can see, we can take commands from the history portion of the Script Editor, cut and paste them into the Script Editor to create our own commands. Now this simple task can be expanded upon to create much more sophisticated scripts.
- Using the command line and the Script Editor
- Grabbing Script Editor output
- Creating, loading, and saving buttons
- Working with variables and arrays
- Using conditionals
- Performing calculations with the math, trig, and time functions
- Creating and testing a user interface