Community
Maya Forum
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya topics.
cancel
Showing results for
Show  only  | Search instead for
Did you mean:

## MEL script not working

11 REPLIES 11
SOLVED
Message 1 of 12
Anonymous
2814 Views, 11 Replies

## MEL script not working

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

Tags (2)
11 REPLIES 11
Message 2 of 12

Hi @Anonymous and welcome to the community!

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

All the best,

Sean Heasley
Technical Support Specialist

Message 3 of 12
Anonymous

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

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
Message 5 of 12

Hi @Anonymous

@Stephen.Blair beat me to it

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

All the best,

Sean Heasley
Technical Support Specialist

Message 6 of 12
Anonymous

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

Message 7 of 12

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
Message 8 of 12
Anonymous

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.

Message 9 of 12
Anonymous

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. //

Message 10 of 12

```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

god bless you

now i have to figure out how to scale the terrain

Message 12 of 12
Anonymous