MEL script not working

MEL script not working

Anonymous
Not applicable
4,516 Views
11 Replies
Message 1 of 12

MEL script not working

Anonymous
Not applicable

Hey Guys,

I'm having a weird problem with an existing script. I copied and pasted it into MEL, pressed Strg+Enter..so far so good. I also pressed "execute" and now the script is supposed to show up into my scene but it doesnt. 

 

Can anybody tell me what am I doing wrong and can guide me? I also have TeamViewer. just saying

0 Likes
Accepted solutions (1)
4,517 Views
11 Replies
Replies (11)
Message 2 of 12

sean.heasley
Alumni
Alumni

Hi @Anonymous and welcome to the community!

 

Can you please post the script here when you get a chance?

0 Likes
Message 3 of 12

Anonymous
Not applicable

hi, thanks for replying 

 

 

 

proc diamondSquare(float $h)
{
polyPlane -w 1 -h 1 -sx 16 -sy 16 -ax 0 1 0 -cuv 2 -ch 1 -n "terrain";
int $SIZE=16+1;

for ($sidelength = $SIZE-1; $sidelength > 1; $sidelength/=2)
{
int $halfside = $sidelength/2;
for ($x=0; $x<$SIZE-1; $x+=$sidelength)
{
for ($z=0; $z<$SIZE-1; $z+=$sidelength)
{
vector $p0 = `pointPosition -w terrain.vtx[$x + $z*$SIZE]`;
vector $p1 = `pointPosition -w terrain.vtx[$x + $sidelength + $z*$SIZE]`;
vector $p2 = `pointPosition -w terrain.vtx[$x + ($z+$sidelength)*$SIZE]`;
vector $p3 = `pointPosition -w terrain.vtx[$x + $sidelength + ($z+$sidelength)*$SIZE]`;

float $avg = ($p0.y + $p1.y + $p2.y + $p3.y)/4.0;
$r = rand(-1.0*$h, $h);
select -r terrain.vtx[$x+$halfside + ($z+$halfside)*$SIZE];
move -y ($avg + $r);
}
}
for($x=0; $x<$SIZE-1; $x+=$halfside)
{
for($z=($x+$halfside)%$sidelength; $z<$SIZE-1; $z+=$sidelength)
{
vector $p0 = `pointPosition -w terrain.vtx[($x-$halfside+$SIZE-1)%($SIZE-1) + $z*$SIZE]`;
vector $p1 = `pointPosition -w terrain.vtx[($x+$halfside)%($SIZE-1) + $z*$SIZE]`;
vector $p2 = `pointPosition -w terrain.vtx[$x + (($z+$halfside)%($SIZE-1))*$SIZE]`;
vector $p3 = `pointPosition -w terrain.vtx[$x + (($z-$halfside+$SIZE-1)%($SIZE-1))*$SIZE]`;

float $avg = ($p0.y + $p1.y + $p2.y + $p3.y)/4.0;
$r = rand(-1.0*$h, $h);

select -r terrain.vtx[$x + $z*$SIZE];
move -y ($avg + $r);

if ($x == 0)
{
select -r terrain.vtx[$SIZE-1 + $z*$SIZE];
move -y ($avg + $r);
}
if ($z == 0)
{
select -r terrain.vtx[$x + ($SIZE-1)*$SIZE];
move -y ($avg + $r);
}
}
}
$h/=2;
}
}

Message 4 of 12

Stephen.Blair
Community Manager
Community Manager

That's the proc definition.

 

To actually use it, you have to execute the proc like this:

 

diamondSquare( 0.333 );


// Stephen Blair
// Arnold Renderer Support
0 Likes
Message 5 of 12

sean.heasley
Alumni
Alumni

Hi @Anonymous

 

@Stephen.Blair beat me to it Smiley Tongue

 

When you get a chance, can you add the code to yours so we can make sure it works for you as well?

Message 6 of 12

Anonymous
Not applicable

do i have to add this at the beginning or at the end?

0 Likes
Message 7 of 12

Stephen.Blair
Community Manager
Community Manager

You can't go wrong by putting it at the end.

 

1) define proc

2) call proc

 

That will work in any language.

 

In MEL, you could call the proc first, because Maya obviously parses the whole thing first.

 

But in Python, you'd get an error if the definition didn't come first.



// Stephen Blair
// Arnold Renderer Support
0 Likes
Message 8 of 12

Anonymous
Not applicable

i add this at the very beginning of the script and this is what maya tells me 

 

// Error: Line 51.6: "$h" is an undeclared variable.

0 Likes
Message 9 of 12

Anonymous
Not applicable

this is very confusing 😕 when i add this at the end 

 

maya tells me that ive to delete this -> $r 

 

// Error: $r = rand(-1.0*$h, $h);
//
// Error: Line 18.18: "$h" is an undeclared variable. //
// Error: $r = rand(-1.0*$h, $h);
//
// Error: Line 18.22: "$h" is an undeclared variable. //
// Error: move -y ($avg + $r);
//
// Error: Line 20.19: "$r" is an undeclared variable. //
// Error: $r = rand(-1.0*$h, $h);
//
// Error: Line 33.18: "$h" is an undeclared variable. //
// Error: $r = rand(-1.0*$h, $h);
//
// Error: Line 33.22: "$h" is an undeclared variable. //
// Error: move -y ($avg + $r);
//
// Error: Line 36.19: "$r" is an undeclared variable. //
// Error: move -y ($avg + $r);
//
// Error: Line 41.19: "$r" is an undeclared variable. //
// Error: move -y ($avg + $r);
//
// Error: Line 46.19: "$r" is an undeclared variable. //
// Error: $h/=2;
//
// Error: Line 50.6: "$h" is an undeclared variable. //

0 Likes
Message 10 of 12

Stephen.Blair
Community Manager
Community Manager
Accepted solution

 

 

 

diamondSquare( .1 );



proc diamondSquare(float $h)
{
polyPlane -w 1 -h 1 -sx 16 -sy 16 -ax 0 1 0 -cuv 2 -ch 1 -n "terrain";
int $SIZE=16+1;

for ($sidelength = $SIZE-1; $sidelength > 1; $sidelength/=2)
{
int $halfside = $sidelength/2;
for ($x=0; $x<$SIZE-1; $x+=$sidelength)
{
for ($z=0; $z<$SIZE-1; $z+=$sidelength)
{
vector $p0 = `pointPosition -w terrain.vtx[$x + $z*$SIZE]`;
vector $p1 = `pointPosition -w terrain.vtx[$x + $sidelength + $z*$SIZE]`;
vector $p2 = `pointPosition -w terrain.vtx[$x + ($z+$sidelength)*$SIZE]`;
vector $p3 = `pointPosition -w terrain.vtx[$x + $sidelength + ($z+$sidelength)*$SIZE]`;

float $avg = ($p0.y + $p1.y + $p2.y + $p3.y)/4.0;
$r = rand(-1.0*$h, $h);
select -r terrain.vtx[$x+$halfside + ($z+$halfside)*$SIZE];
move -y ($avg + $r);
}
}
for($x=0; $x<$SIZE-1; $x+=$halfside)
{
for($z=($x+$halfside)%$sidelength; $z<$SIZE-1; $z+=$sidelength)
{
vector $p0 = `pointPosition -w terrain.vtx[($x-$halfside+$SIZE-1)%($SIZE-1) + $z*$SIZE]`;
vector $p1 = `pointPosition -w terrain.vtx[($x+$halfside)%($SIZE-1) + $z*$SIZE]`;
vector $p2 = `pointPosition -w terrain.vtx[$x + (($z+$halfside)%($SIZE-1))*$SIZE]`;
vector $p3 = `pointPosition -w terrain.vtx[$x + (($z-$halfside+$SIZE-1)%($SIZE-1))*$SIZE]`;

float $avg = ($p0.y + $p1.y + $p2.y + $p3.y)/4.0;
$r = rand(-1.0*$h, $h);

select -r terrain.vtx[$x + $z*$SIZE];
move -y ($avg + $r);

if ($x == 0)
{
select -r terrain.vtx[$SIZE-1 + $z*$SIZE];
move -y ($avg + $r);
}
if ($z == 0)
{
select -r terrain.vtx[$x + ($SIZE-1)*$SIZE];
move -y ($avg + $r);
}
}
}
$h/=2;
}
}

 



// Stephen Blair
// Arnold Renderer Support
Message 11 of 12

Anonymous
Not applicable

god bless you Smiley Happy

 

now i have to figure out how to scale the terrain

0 Likes
Message 12 of 12

Anonymous
Not applicable

If I copy and paste this script or code into the MAYA script editor will anything happen ? 

0 Likes