PDA

View Full Version : MEL Scripting trouble...


A. Ryan Rodriguez
08-21-2009, 04:17 PM
Hey, all. I'm trying to create a simple City Generator using MEL in Maya 2009, and I've run into some trouble/confusion on where to go next. I've made a script that makes a basic randomized city, but I want to be able to control it using an UI window. I've created a simple script that would make a window (I want it to control the Number of Buildings you make, and Tall, and how Wide they are) a window pop up that has the attributes I want controllable on them, but I'm stumped on how I connect the two, and actually get them to work with one another.

Any help would be GREEEEATLY appreciated. Here's what I have so far, if you want to take a look first-hand for yourself..... Also, any links to other sites that you know of that explain the process of city generators would help, as well....

Thanks!

RANDOMIZED CITY:
========================================
proc createCity(int $city)
{
int $A=0;
while($A < 2000){
polyCube;
int $MoveRandZ=gauss(20);
int $MoveRandX=gauss(20);
int $Hdistrib=abs($MoveRandZ) + abs($MoveRandX);
float $ScaleRandY=(sqrt((rand(5,20)) / $Hdistrib)) * 1.5;
float $MoveY=($ScaleRandY)/2;
move $MoveRandX $MoveY $MoveRandZ;
scale .5 $ScaleRandY .5;
$A++;
print($A + "n");
};

}

createCity(10);
===================================

BASIC WINDOW:
===================================
proc addFloat(int $af)
{
$myDialog = `window -h 150 -w 400 -title "City Generator Box"`;
columnLayout;
intSliderGrp -l "Number of Buildings" -f true -min 0 -max 255 -v 1 rint1;
intSliderGrp -l "Building Height" -f true -min 0 -max 1000 -v 1000 rint2;
intSliderGrp -l "Building Width" -f true -min 0 -max 1000 -v 500 rint3;
string $currentOptions = "";
$currentOptions += `intSliderGrp - q -v rint1`;
print ($currentOptions + "\n");
showWindow;
}
addFloat(3);
======================================

Hans Schrijvers
08-21-2009, 04:55 PM
Okay, I am just going to ignore your scripts for now and show you how to link a window to another proc.


global proc genericwindow()
{
//create a window
window
-wh 315 380
-t "Hans' Example"
-s 0
win;
//add a control
floatSliderGrp
-label "Value"
-w 300
-precision 3
-field true
-minValue 0
-fieldMinValue 0
-value 1.00
myval;
//show window
showWindow;
}

global proc printvalue()
{
//find your window's value
float $yourvalue = `floatSliderGrp -q -v myval`;
//print your value
print $yourvalue;
}


that's how it works, I hope this helps and you can apply it to your scripts.