Automating Geometry Creation And Texture Assignment With Mel

Hello,

I'm hoping this isn't too difficult and I get moving forward soon.

I have a large number of textures (100 or so) in a dozen directories in my sourceimages folder. Each texture needs to be assigned to a new NURBs plane in my scene. In a perfect world, the name of the texture would also be assigned to the name of the geometry, and be used in the name for the Material and Texture File-in -- to keep everything organized.

I figured this wouldn't be hard to do with MEL, but I'm not super-experienced with MEL and so far am not having much luck at it.

Currently, just getting a list of texture names from a specific directory and putting that into a variable to then use in a script is the problem.

I would have thought it was a common sort of task, but I didn't find any posts or existing mel commands which work.

Can anyone help me with writing this script? Much thanks in advance.

~A

QUOTE(activated @ 04/20/06, 11:18 PM) [snapback]234902[/snapback]
Hello,

Currently, just getting a list of texture names from a specific directory and putting that into a variable to then use in a script is the problem.

You can get lsit of textures in folder with getFileList

[b] getFileList -fld directory -fs filespec

[/b][b]filespec=.tga,.tif,.iff like

[/b]then u cn get all in one array or do with loop u can read every one

then put to texture file node..it will help

u need more specifications then getFileList

http://localhost:4449/Maya7.0/en\_US/Comman...etFileList.html

Hey, thanks for your help.

I tried to use the "getFileList" but I ran into issues with getting the command to work like I'd like it to.

The examples in the manual go like this:
getFileList -folder internalVar -userScriptDir -filespec "*.mel";

When I use this command, it gets a predictable result and lists those MEL commands in the scripts directory for sure. However, if I change the code to reflect my needs, to find for example this file located here (C:\PROJECTS\Nobel_Son\sourceimages\projection2-pCube1.tga ), I seem to have problems.

Here are a few of the examples I tried....

getFileList -folder "C:\PROJECTS\Nobel_Son\sourceimages" -filespec "*.tga";

or...
getFileList -folder "C:/PROJECTS/Nobel_Son/sourceimages" -filespec "*.tga";

or even...
getFileList -folder "sourceimages" -filespec "*.tga";

I get nothing, not even a syntax error.

Can someone please point out what I could do to set this straight?

Thanks again.

QUOTE(kurianos3d @ 04/20/06, 10:15 PM) [snapback]234949[/snapback]
You can get lsit of textures in folder with getFileList

[b] getFileList -fld directory -fs filespec

[/b][b]filespec=.tga,.tif,.iff like

[/b]then u cn get all in one array or do with loop u can read every one

then put to texture file node..it will help

u need more specifications then getFileList

http://localhost:4449/Maya7.0/en\_US/Comman...etFileList.html

Hi

CODE
{
    string $getFold[]=getFileList -folder "C:/PROJECTS/Nobel\_Son/sourceimages/" -filespec "*.tga";
    print $getFold;
}

your prob is

[b]"C:/PROJECTS/Nobel_Son/sourceimages"

[/b]you want give

[b]"C:/PROJECTS/Nobel_Son/sourceimages/"

[/b]then it will work

FYI "C:\PROJECTS\Nobel_Son\sourceimages" = C:PROJECTSNobel_Sonsourceimages

since \ is the escape character so ainside quytes you always need two baklashes to include one

so following also works

getFileList -folder "C:\blahblah\" -filespec "*.ugh";

Ok. Now I'm stumped on how to assign a material with a shading group.

Below you'll see the code I've written up 'til now. It makes a list of textures on disk and uses that list to name the following: a NURBs plane, a file-in, a material; then maps the file-in to the material, but that's it.

I haven't figured out the assignment of shaders yet. It seems to me that I have to figure out creation of a Shading Group and somehow assign that.

Suggestions?

string $getFold[]=getFileList -folder "C:/PROJECTS/Nobel\_Son/sourceimages/SCANs\_AFX\_(processed\_SGI16)/MasterA\_2x2/" -filespec "*.sgi";
string $currentFile;

for ($currentFile in $getFold)
{
//tokenize the element $currentFile so as to be rid of the dot/period it has natively
string $tokenBuffer[];
tokenize $currentFile "." $tokenBuffer;
string $imageName = $tokenBuffer[(size $tokenBuffer - 2)];

	//test: print $imageName;
	//test: print $currentFile;
	//try:  string $image = ($folder + $imageName + ".sgi";
string $image = ($imageName + ".sgi");

nurbsPlane -p 0 0 0 -ax 0 1 0 -w 2 -lr 1 -d 1 -u 1 -v 1 -ch 1; 
rename nurbsPlane17 ($imageName);

//create material shader node with proper name;
shadingNode -n ($imageName + "\_" +"phongE") -asShader phongE;

//create file-in node with proper name;
shadingNode -n ($imageName + "\_" + "fileIn") -asTexture file;

//input proper sourceimage to file-in node;
setAttr ($imageName + "\_fileIn.ftn") -type "string" ("C:\\PROJECTS\\Nobel\_Son\\sourceimages\\SCANs\_AFX\_(processed\_SGI16)\\MasterA\_2x2\\" + $image);

//connect file-in to material
connectAttr -f ($imageName + "\_fileIn.outColor") ($imageName + "\_phongE.color");
connectAttr -f ($imageName + "\_fileIn.outTransparency") ($imageName + "\_phongE.transparency");

}

sets -e -forceElement shadingGroup object1 object2....

why would you want to tokenlize and then reinsert the token?!?! Alsi if its a numbering bit then you refeer to the same image many many times.