Digital humans the art of the digital double
Ever wanted to know how digital doubles are created in the movie industry? This course will give you an insight into how it's done.
# 1 18-10-2014 , 05:09 AM
Registered User
Join Date: Oct 2014
Posts: 2

Array of Shingles for ArchViz (MEL Script help :)!!!

Hello I ma right now working on a Architectual Visualisation. My Problem is I have to model shingles of a wall. Actually I am nearly driving crazy becauce I know it would be quite easy if i coud script just a little bit. The point is I have really no idear. Thats why I am here maybe one of the members of this forum can help me!

I would be so thankfull!!!!

Okay now I explain you what I need and for what I am to dumm for user added image!

The mel script should select randomly between maybe 10 cubes with different scale's in the z axis one cube. It should make a inctance copy of this cube an translate it then with the same scale of this cube plus a gap.

In the screenshot you can see what I mean.

I thought It would work maybe with a if and else statment. I mean if the script would randomy choose between the 10 cubes for example cube1 ant it would translate this cube 5 units to the z axis (because that is the scale of the cube1) + 0.15 units (because that is the gap between each cubes) it would work. if it could do that 1000 times I would have one row of my shingles. That would help me so much otherwise I have to do that all by hand user added image! Oh my god!

Attached Thumbnails
# 2 19-10-2014 , 09:10 PM
EduSciVis-er
Join Date: Dec 2005
Location: Toronto
Posts: 3,374
You're realizing how much a benefit it is to know some basic scripting, which is great! Instead of writing a script for you, how about if I help you figure out how to write your own?

First thing is to write some "pseudo-code" that will form the structure of the code. Something like this.
(I'm imagining that you've created 10 template shingles and named them shingle_template_01 through shingle_template_10)

1) Start the total length of the row as 0
2) Get a random number from 1-10
3) Copy the cube called "shingle_template_randomNum" as an instance
4) Get the width of the selected cube
5) Store the total length of the row as the current length + the width of the new cube + the gap width
6) Loop through steps 2 to 5 1000 times
7) Bonus: Move the y position (or x) up to the next row and do steps 1 - 6 again

So that should help you understand the flow of the program. The next thing, which is really just an exercise in googling and debugging (for everyone), is to replace the pseudocode with MEL commands. There are three things that are invaluable for this.
1) The Maya MEL docs (Help > MEL Command reference)
2) Checking the script editor, because Maya will repeat MEL commands for everything you are doing. Using echo all commands in the script editor (History > Echo all commands) is even more verbose.Try creating an instance of something and see what pops up.
3) SimplyMaya, if you are getting a syntax error, someone may be able to spot what is wrong.

So, you will probably have to look up the "rand" command, the "getAttr" command, "instance", "xform" (i.e. transform), and maybe a few others.

Your main loop block will probably look something like this:

float $totalLength = 0.0; //set row length to zero at start (// means a comment)
for ($numShingles = 0; $numShingles < 1000; $numShingles ++){
//your instance, moving and $totalLength update should be in here
}

Now maybe it would have taken less time to write the complete script, but I think you'll learn more this way. user added image Good luck.

# 3 20-10-2014 , 05:37 AM
Registered User
Join Date: Oct 2014
Posts: 2
Thanks a lot for your large answere! I solved this problem by hand because I really have to rush. My client is not very patient. Actually I googled a hole day but in a wrong way I would say.

After I am done with the viz I will try your advice because it would be so nice if I could solve such simple problems in the futur with some lines of code!

Posting Rules Forum Rules
You may not post new threads | You may not post replies | You may not post attachments | You may not edit your posts | BB code is On | Smilies are On | [IMG] code is On | HTML code is Off

Similar Threads