I'm fairly new to MEL so please bare with me.
I'm trying to create a script that will create a polyCube with a spotLight after pressing a button, but each time you press the button in the menu it would create another copy of the two, but right beside it and not on top of the original. Basically creating a loop of the cube and light, but placed right beside it. All of my code works except for anything trying to add in a for loop. I'm not sure where in my code it should be placed. Anyone have a suggestion? Here is the working code without the for loop.
//Create a window with a gray working menu bar. Window will Exit and go to Maya Help.
//Window has an image based button.
//User can create a PolyCube with 5 subdivision in the X,Y & Z axis. PolyCube also has unwrapped UVs and a Spot Light.
//Window will close previous window if there is already a window present.
{
if (`window -exists myMenuBar`)
{
deleteUI myMenuBar;
windowPref -remove myMenuBar;
}
window -title "Kevin's Window" -menuBar true -width 50 -height 100 myMenuBar;
gridLayout -bgc .2 .2 .2 -numberOfColumns 3 -cellWidthHeight 150 50;
$command = ("polyCube -sx 5 -sy 5 -sz 5 -createUVs 1 ; spotLight -position 4.403 1.919 6.585 -rotation -11.235 34.113 0 ;");
symbolButton -image "Network/AIRDSERV01/Student Drive/Cherme/GAD3333 - 3DScripting/Final/kevinautry/cube.xpm" -width 50 -height 100 -command $command;
//Create a tearOff menu with menu item.
menu -label "File" -tearOff true;
//Added menu items
menuItem -label "Exit" -command "deleteUI myMenuBar";
//Add a help menu.
menu -label "Help" -helpMenu true;
global string $docs = ("Commands/index.html"); //this string tells where the help file is located
menuItem -label "MEL Command Reference" -command " showHelp -docs $docs " ;
showWindow myMenuBar;
}
Replies
If that's the case, this is not a loop thing. It's a 1 time function that executes as you press the button. You'll need to find a way to store the location so that you can add to it each time the function is called.
Here's an example. I hope it gives you some idea.
Once you run that, use this command to execute.
Would that be placed in the () before polyCube?
I'm sorry I haven't script in MEL for a very long time so I won't be able to cook you any examples. I can only give you the idea.
More importantly what is the importance of the position of the light relative to the cube?
( fer example will the cube be a look at "aim" object or a position constraint for the light? )
Without knowing it's next to impossible to suggest a strategy for initial position at creation.
Also...
Just wondering why 5 subdivisions?