PDA

View Full Version : // Error: Cannot find procedure "differenceStringArrays". //


Levitateme
02-01-2004, 01:23 PM
I am trying to get this default shader script to work. but i keep getting this error? does anyone know why it is not working? I would like to have a script that will have like a blinn shader as the default, so everytime i do something it alwyas has a b linn shader im assuiming this script does that.

/* This file downloaded from Highend3d.com
''
'' Highend3d.com File Information:
''
'' Script Name: defaultMaterial v1.0
'' Author: Julian Love
'' Last Updated: May 31, 2002
'' Update/Change this file at:
'' http://www.highend3d.com/maya/mel/?section=rendering#1764
''
'' Please do not alter any information above this line
'' it is generated dynamically by Highend3d.com and will
'' be changed automatically on any updates.
*/

//defaultMaterial, by Julian Love, JulianLove@mac.com. Copyright (C) Julian Love, 2002
//
//description: laods and assigns tothe selected objects the material saved as a file
// called "deafult_materialName.ma" in the user's prefs folder.
//
//usage: Export any material from hypershade to your /Maya/Prefs/ folder with the
// name "default_materialName.ma".
//
// The file must be a .ma file and end with That exact extension. The name of
// the material as it appears within Maya must also appear after "default_".
// The script uses this portion of the file name to determine if the material
// has already been loaded for this scene. If it hasn't then it will load it
// and then assign it. Otherwise, it just assigns the one that is already loaded.
//
// If the materialName and the "materialName" portion of the file name don't
// match, the script will load a new file each time it is run.
//
// So, if your material is called "blinn1"in maya, export it as "default_blinn1.ma"
//
// run the script by selecting any number of objects and typing "defaultMaterial"
// at the command line or whathaveyou.

proc string itemInStringArray (string $item, string $array[]){
string $x;
int $theSadTruth = 0;

for ($x in $array){
if ($x == $item)
{$theSadTruth = 1;}
}

return ($theSadTruth);
}

proc string stringFirstWord (string $item, string $wordChar){
string $wordList[];

tokenize $item $wordChar $wordList;

return $wordList[0];
}

proc string stringLastWord (string $item, string $wordChar){
string $wordList[];

tokenize $item $wordChar $wordList;

return $wordList[(size($wordList) -1)];
}



global proc defaultMaterial (){
string $prefsDir = `internalVar -upd`;
string $dirList[] = `getFileList -fld $prefsDir -fs "default_*.ma"`;
string $matPath = ($prefsDir + $dirList[0]);
string $matList[] = `ls -mat`;
string $newMatList[];
string $shadeList[] = `ls -type "shadingEngine"`;
string $connexList[];
string $diffList[];
string $sel[] = `ls -sl -type "transform"`;
string $matName, $shadeName, $x;


//...determine the material name
if (size($dirList[0]) != 0){
$matName = `stringLastWord $dirList[0] "_"`; //chop off "default"
$matName = `stringFirstWord $matName "."`; //chop off ".ma"

//...import the material
if (`itemInStringArray $matName $matList` == 0){ //does it already exist?
if (`filetest -r $matPath` == 1) //make sure the path exists
{file -i -pmt 0 $matPath;} //import the file
else
{error ("No deafult material file found at: " + $matPath);}
}


//...is there a shader group?
if (`itemInStringArray $matName $matList` == 0){ //did the file name match the material?
$newMatlist = `ls -mat`;
$diffList = `differenceStringArrays $newMatlist $matList`;
if (size($diffList) != 0)
{$matName = $diffList[0];}
else
{error ("Couldm't locate the expected new material: " + $matName);}
}


$connexList = `listConnections -d 1 ($matName + ".outColor")`; //get the connexList

if (size($connexList) == 0){ //is there an SG connex?
$shadeName = ($matName + "SG"); //get the SG name

if (`itemInStringArray $shadeName $shadeList` == 0) //does the SG exist?
{sets -name $shadeName -r true -nss true -empty;} //create the SG

connectAttr -f ($matName + ".outColor") ($shadeName + ".surfaceShader");
}
else
{$shadeName = $connexList[0];}


//...assign the material
if (size($sel) == 0)
{warning "No objects selected. Material loaded only";}
else{
select -r $sel;
sets -e -forceElement $shadeName;
}
}
else
{warning ("No default materials found at: " + $prefsDir + " No action taken.");}
}

markbones
02-05-2004, 03:04 AM
According to my Maya 4.0 MEL command reference, there's no "differenceStringArrays" command/proc/keyword.

$diffList = `differenceStringArrays $newMatlist $matList`;

is making a call to the procedure "differenceStringArrays" with the 2 string arrays passed as arguments, but cannot find "differenceStringArrays". Maybe the procedure was left out of the script you downloaded?

Levitateme
02-05-2004, 04:40 AM
Yah, my friend said the same thing...thanks for the info, i just wish there was a way to have may use a differnt shader for the default is all.

bigfatMELon
02-08-2004, 07:10 PM
Well... there is THIS differenceStringArrays command. And a new version defaultMaterial.mel appears on my site with this included.


global proc string[] differenceStringArrays (string $array1[], string $array2[])
{
string $x;
string $y;
string $newArray[];
string $flatArray[];
int $itemFound = 0;


//...find items in array1 that don't appear in array2
for ($x in $array1)
{
$itemFound = 0;
for ($y in $array2)
{
if ($x == $y) {$itemFound = 1;}
}
if ($itemFound == 0) {$newArray[size($newArray)] = $x;}
}


//...find items in array2 that don't appear in array1
for ($x in $array2)
{
$itemFound = 0;
for ($y in $array1)
{
if ($x == $y) {$itemFound = 1;}
}
if ($itemFound == 0) {$newArray[size($newArray)] = $x;}
}


//...flatten the result
$flatArray[0] = $newArray[0];
for ($x in $newArray)
{
$itemFound = 0;
for ($y in $flatArray)
{
if ($x == $y) {$itemFound = 1;}
}
if ($itemFound == 0) {$flatArray[size($flatArray)] = $x;}
}

return ($flatArray);
}


-jl

Levitateme
02-08-2004, 09:35 PM
@bigfatmelon

Thanks for this script. i was curious if there is anyway to make it so everything is that default. i could just assign to a hotkey, but in hypershade i would be having lots of extra materials. just curious if that was possible. so everytime a scene starts the default material is what is in my folder. Right now its great i think, just be neat to not end up with a lot of shaders in hypershade is all.

bigfatMELon
02-08-2004, 09:52 PM
Maya needs a shader that it knows it can rely on to draw anything that might be created at the instant it is created. Lambert1 is that shader. It cannot be removed nor supplanted by another. The best work around I could come up with was this script that lets you define your own that can be applied on a hotkey. It shouldn't result in multiple extra materials because it checks to see if your "default" shader exists before it tries to load it from disk. Unless you named it something like lambet1, that is.

-jl

Levitateme
02-08-2004, 10:28 PM
MELon, that makes perfect sense, after showing 3 of my friends this script they all agreed that it makes sense to have it to a hotkey, cause you may not alwyas want that shader.

I named my material

default_Blinn.ma

is that right?

bigfatMELon
02-09-2004, 07:45 AM
That should work.

-jl

CGTalk Moderation
01-17-2006, 09:00 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.