Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Placing objects together

Placing objects together

Anonymous
Not applicable
413 Views
2 Replies
Message 1 of 3

Placing objects together

Anonymous
Not applicable

Hi everyone,

 

i'm doing a project where i have to build a chessboard and chess pieces and then place each piece accurately on the board using Mel. So i'm wondering if there is a way i can set chess piece 1 to chessboard square 1 and so on in a for loop? I'd appreciate the help. 

 

thanks.

0 Likes
414 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
0 Likes
Message 3 of 3

Anonymous
Not applicable

Good Evening,

 

I while ago I used Mel but I switched over to python. I have created a code snippet for you which I guess can easily converted into Mel:

 

Edit: Here is the Mel code:

 

$width = 10;
$height = 10;
$size = 1;
$offset = 0.5;

for ($z = 0; $z < $height; $z++)
{
    for ($x = 0; $x < $width; $x++)
    {
       spaceLocator -p (($x*$size)+$offset) 0 (($z*$size)+$offset);
    }
}

 

import maya.cmds as cmds

width = 10
height = 10
size = 1

offset = 0.5

for z in range(height):
    for x in range(width):
        cmds.spaceLocator(position = ((x*size)+offset, 0, (z*size)+offset))

 

I think in Mel you need to adjust the for loops into 

for ($z = 0; $z < height; $z++) { 
spaceLocator();

[..]
}

 Width defines the items along the z-axis and height along the x-axis. Size defines the space between each "figure" and the offset pushes them into the middle.

 

So this would be the output:

chess.png

 

 

So you just need to create 2 for loops for those 2 "teams" and it should be done 🙂 And if you want to access those objects later I would name them like the field name for e.g figure_2_3 where 2 is the row and 3 column so you can later compose a string "figure_"+$row+"_"+$column for accessing this figure. Good luck

 

Regards,

Life


Circlelizer circle tool for Maya.