Selecting Specific Objects: MEL


#1

Hey, guys. I’m a very early learner of MEL, and I’m trying to program a Lego generator. I have managed to make a loop that makes a one-dotted brick and the dot on top, but I do not know how to combine the cube and dot into one object in this loop. My question is how can I select only the objects which I created for the brick, regardless of the name, and without selecting anything else? A possible solution I thought would be to make a “select all” command, but that would select everything else, not just the components of the new brick. Here is the progress of my script so far:

float $dotSeparation = 0.8;
float $height = $dotSeparation*0.4;
float $width = $dotSeparation-0.02;
float $dotHeight = 0.17;
float $dotRadius = 0.24;
int $numDots = 2;

polyCube -w $width -h $height -d $width ;

for ($i = 1; $i < $numDots; ++$i) {
polyCylinder -r $dotRadius -h $dotHeight ;
move -r 0 ($dotHeight/2+$height/2) 0 ;
}

You may notice that I gave the cube some of its dimensions based on the separation of the dots have from each other. That was just to integrate the relationships that the measurements that Lego bricks have into the script.

Remember, I am a very early learner, so please keep in mind that some of the things you may refer to I may not know about. Thank you all in advance, and have a nice day.


#2

Using your script to select things is not the best way to do it. Instead you should assign the result of each command to a variable that you can refer to later in the script. The polyCube command returns the name of the transform as well as the name of the polyCube creation node, so the variable you assign this result to needs to be a string array. Notice the use of the back-quotes to enclose the command.

\\ $cube is a string array
string $cube[] = `polyCube -w 5 -h 3 -d 8` ;

\\ $pCube is the first element of the string array, ie the name of the cube transform
string $pCube = $cube[0];

You can do the same with the cylinder creation. So when you want to combine them you can refer to them using the variable names.

\\ polyUnite returns the transform and the name of the polyUnite node
string $block[] = `polyUnite -n "block1" $pCube $pCylinder`;

If you are not familiar with the difference between a string and a string array variable or how to work with them, then try to find some tutorials covering these concepts.

David


#3

Wow! That worked! Thanks a lot! That solved my problem, but keep bringing in the suggestions, guys! I might learn something new. :slight_smile: