Hello all,
I’m having trouble working on an expression I’ve been trying to create while I learn MEL. So forewarning… I don’t have much of a background in programming and I’m new to MEL.
The expression I’m trying to make is for a rubik’s cube rig (I wanted to do it my own way from the tutorials I’ve seen out there). It would turn on orient constraints when a control is selected so that the cubes on that side would then be manipulated. So what I’ve done is create two sets of locators (one for where each cube should be and one for where each cube actually is) and I’m checking their positions against each other so when the cube locators match particular position locators the cube at that location has its constraints turned on and all other constraints turned off. I’ve only been working on one side and I’ve got my expression to the point at which it SEEMS error free (no syntax or other errors thrown in the Script Editor finally)… but it does nothing, no constraints change. After having to go back and forth fixing scope errors and then printing various variables to see if they are operating I’ve found the for loops I’ve got running don’t even seem to be executing? maybe?
Anyway I’m expecting someone will probably show me a whole slew of problems in my concept and or my code and prove how much of an idiot I am but can anyone help?
here is some of my code… (I left out the arrays of objects that are loaded at the beginning)
//Query selection...
float $red_Ctrl[] = `xform -q -ws -rp red_ctrl1GRP`;
float $red_CtrlX = $red_Ctrl[0];
float $red_CtrlY = $red_Ctrl[1];
float $red_CtrlZ = $red_Ctrl[2];
string $sel_Ctrl[] = `ls -selection`;
float $CubePos[];
float $LocPos[];
//Check if red control is selected...
if (size($sel_Ctrl) >= 1){
float $sel_Loc[] = `xform -ws -q -rp $sel_Ctrl`;
float $sel_LocX = $sel_Loc[0];
float $sel_LocY = $sel_Loc[1];
float $sel_LocZ = $sel_Loc[2];
if ($sel_LocX == $red_CtrlX){
if ($sel_LocY == $red_CtrlY){
if($sel_LocZ == $red_CtrlZ){
//cycle through obj_cubescheck locators to check location with red side locators
for ($Cubes = 0; $Cubes < size($Obj_CubesCheck); ++$Cubes){
float $CubePos[] = `xform -q -ws -rp $Obj_CubesCheck[$Cubes]`;
float $CubePosX = $CubePos[0];
float $CubePosY = $CubePos[1];
float $CubePosZ = $CubePos[2];
for ($Locs = 0; $Locs < size($Loc_Checks); ++$Locs){
float $LocPos[] = `xform -q -ws -rp $Loc_Checks[$Locs]`;
float $LocPosX = $LocPos[0];
float $LocPosY = $LocPos[1];
float $LocPosZ = $LocPos[2];
if ($CubePosX == $LocPosX){
if ($CubePosY == $LocPosY){
if ($CubePosZ == $LocPosZ){
//Change contraint to control to on
setAttr ($Obj_Cubes[$Cubes] + "_orientConstraint1.red_ctrl1W0") 1;
setAttr ($Obj_Cubes[$Cubes] + "_orientConstraint1.green_ctrl1W1") 0;
setAttr ($Obj_Cubes[$Cubes] + "_orientConstraint1.orange_ctrl1W2") 0;
setAttr ($Obj_Cubes[$Cubes] + "_orientConstraint1.blue_ctrl1W3") 0;
setAttr ($Obj_Cubes[$Cubes] + "_orientConstraint1.white_ctrl1W4") 0;
setAttr ($Obj_Cubes[$Cubes] + "_orientConstraint1.Yellow_ctrl1W5") 0;
}
}
}
}
}
}
}
}
}
EDITED: for code formatting due to newb ignorance.