Calling an image in MEL scripting

Calling an image in MEL scripting

lucascarci17
Contributor Contributor
2,181 Views
4 Replies
Message 1 of 5

Calling an image in MEL scripting

lucascarci17
Contributor
Contributor

I've recently started playing around with the MEL script capabilities in Maya, and have come across a small issue. The tutorial I have been following is out a book — Parametric Building Design With Maya.

 

He is importing an image, which he then maps the placement of the "Buildings" on a plane. That being said, I cannot link the image I have because I cannot locate the file itself. 

 

string $filenode = `createNode file`;
string $shader = `createNode lambert`;
string $path = "C:/TM/topo-house16.TIF";

 

This is the first three lines of code. However the $path variable is using the "C" drive, for a Windows Machine. I own a Mac. 

 

So essentially, it should link in a similar manner (or I think so).

 

On a mac it should look something like so: string $path ="/Users/username/Desktop/topo-house16.TIF";

 

The script runs fine, but in the console, it is logged that the file could not be found. Just to make sure, I executed the same file route on my mac with the "Goto folder" window. (Command + Shift + G). Typed in the same 

Typed in the same file route, and located the image I was looking for. So it verified that the route was working, but from Maya, I could not load the image. 

 

I am new to MEL and Python but have been modeling/animating with Maya for 4 years now. This is not my first time using a scripting language, however, unless I have to grab assets from specific folders within the MEL, I'm not sure where to go from here.

 

Thanks!

 

0 Likes
Accepted solutions (1)
2,182 Views
4 Replies
Replies (4)
Message 2 of 5

kevin.picott
Alumni
Alumni

What you are doing seems perfectly reasonable. What is the line of MEL that is actually trying to access the file?



Kevin "Father of the DG" Picott

Senior Principal Engineer
Message 3 of 5

lucascarci17
Contributor
Contributor

This is the block of script that has anything the do with the actual image itself:

 

{
// __________ IMAGE MAPPING _________________________________
string $filenode = `createNode file`;
string $shader = `createNode lambert`;
string $path = "C:/TM/topo-house16.TIF";
// connect the nodes
connectAttr ($filenode + ".outColor") ($shader + ".color");

// insert the image path in the file node
string $map = $path;
setAttr -type "string" ($filenode + ".fileTextureName") $map;

// assign the shader to an object
string $object[] = `nurbsPlane -ax 0 1 0 -w 100 -lr 1 -name "nurbsPlane1"`;
//string $object[] = `sphere -name "nurbsPlane1"`;
// __________________________________________________________

 

 

And then the rest of the script determines where My "buildings" are being placed:

 

select -r $object[0];
hyperShade -assign $shader;

int $u, $v,
$nu = 50, $nv = 50;
float $minU = 0, $minV = 0,
$maxU = 1, $maxV = 1;

float $rgb[] = `colorAtPoint -o RGBA -su $nu -sv $nv -mu $minU -mv $minV
-xu $maxU -xv $maxV $filenode`;

float $deltaU = ($maxU - $minU)/($nu - 1);
float $deltaV = ($maxV - $minV)/($nv - 1);
float $currU, $currV;
int $index = 0;

$currU = $minU;
for($n = 0; $n < $nu; $n++)
{
$currU += $deltaU;
$currV = $minV;

for($i = 0; $i < $nv; $i++)
{
float $r = $rgb[$index];
float $g = $rgb[$index + 1];
float $b = $rgb[$index + 2];
float $a = $rgb[$index + 3];
print($r + " " + $g + " " + $b + " " + $a + "\n");
if( ($r + $g + $b) < 2)
{
float $p[] = `pointOnSurface
-u $currU
-v $currV
$object[0]`;

string $listA[]={"building01", "building02", "building03"};
string $listB[]={"building04", "building05", "building06"};
string $listC[]={"building01", "building02", "building03", "building04", "building05", "building06"};

//-----------Red value. commercial
if( $r > 0.8 )
{
int $number = rand(0,3);
string $building = $listA[$number];
select $building;
instance $building;
scale -r (rand(1, 2)) (rand(2, 4)) 1;
move $p[0] $p[1] $p[2];
rotate -r 0 ((-360)*$a) 0;

int $rottime = rand(0,4);
rotate -r 0 (90*$rottime) 0;
}

//-----------Green value. residential
if($g > 0.8)
{
int $number = rand(0,3);
string $building = $listB[$number];
select $building;
instance $building;
scale -r (rand(1, 3)) (rand(1, 2)) (rand(1, 2));
move $p[0] $p[1] $p[2];
rotate -r 0 ((-360)*$a) 0;
int $rottime = rand(0,4);
rotate -r 0 (90*$rottime) 0;
}

}
$index += 4;
$currV += $deltaV;
}
}

}

 

 

0 Likes
Message 4 of 5

kevin.picott
Alumni
Alumni
Accepted solution

Interesting... I'm also on a Mac and when I substitute my own file location for yours the script runs with no message and correctly shows the texture on the plane. A couple of things to check:

  1. Do you have the correct capitalization for the file path and file name? Some Mac configurations can be finicky about that.
  2. When you get the error message, does the name of the file it cannot find match the name you set in $path?

 



Kevin "Father of the DG" Picott

Senior Principal Engineer
Message 5 of 5

lucascarci17
Contributor
Contributor

Ah! This is something I overlooked which I never thought of. I thought the capitalization in my file was correct, as it was a simple mistake and I had been looking at it for too long.

 

Thank you! the script Has worked!

 

 

0 Likes