MEL: specifying shader paths & files with numbers

Thanks for the help so far. It’s nice to see a forum where people respond 🙂

This script is shader specific, so not ideal, but is going to save heaps of time right now because I have to make so many of them. I basically want to set the attributes of my shaders automatically, as well as set the file paths to texture files with specific naming conventions that are numbered. The numbers of the files should coincide with the number appended to the shader.

Since I didn’t know how to do that (query and modify the numbers), I was going to base it on a counter, so as the counter updates during a for loop in an if statement, it would use that number and append it to the name of the file after fixing the padding.

Now the counter is probably not ideal, especially the way I set it up. Ideally I would want to query the number at the end of the shader, add padding if necessary and use that to append to the file name, i.e. shader is named Rman_1, the file name would be appended with 001

So far the actual file paths work fine, it’s just the number that’s crap.

Here’s my code, I will split it up into pieces to hopefully make it easier to follow.

Texture Files (these are all residing in a global proc)
The variable declarations:

Code:

string $shader;
    string $selectedShaders[] = `ls -sl`;
    string $rmanTexPath = "renderman/textures/job/";
    string $texFilePrefix = "DOS_desertPiece";
    string $texFileSeparator = "_";
    $counterD = 0;
    $counterS = 0;
    $counterF = 0;
    string $texFileSuffixD = $counterD;
    string $texFileSuffixS = $counterS;
    string $texFileSuffixF = $counterF;
    string $shaderChannelA = "diffuse";
    string $shaderChannelB = "spec";
    string $shaderChannelC = "fresnel";
    string $fileExtension = ".tex";


The Diffuse Texture File:

Code:

//Set Diffuse Texture
    for($shader in $selectedShaders)
    {
        if($counterD <=45) ++$counterD;
        setAttr -type "string" ($shader + ".diffuseTexture")
        (
        $rmanTexPath +
        $texFilePrefix +
        $texFileSeparator +
        $texFileSuffixD +
//      $texFileSeparator +
//      $shaderChannelA +
        $fileExtension
        );
    }


The Specular Texture File:

Code:

//Set Specular Texture
    for($shader in $selectedShaders)
    {
        if($counterS <=45) ++$counterS;
        setAttr -type "string" ($shader + ".specularTexture")
        (
        $rmanTexPath +
        $texFilePrefix +
        $texFileSeparator +
        $texFileSuffixS +
        $texFileSeparator +
        $shaderChannelB +
        $fileExtension
        );
    }


The Fresnel Texture File:

Code:

//Set Fresnel Texture
    for($shader in $selectedShaders)
    {
        if($counterF <=45) ++$counterF;
        setAttr -type "string" ($shader + ".fresnelTexture")
        (
        $rmanTexPath +
        $texFilePrefix +
        $texFileSeparator +
        $texFileSuffixF +
        $texFileSeparator +
        $shaderChannelC +
        $fileExtension
        );
    }


Now for the other procedure, I thought I set it up correctly, but I think the way I’m trying to set the attributes is incorrect. I get an error that there was an error while parsing the arguments and my guess it comes to the vector stuff. I’m just trying to set the RGB color, it’s a color slider in the shader.

Code:

//Set DOS hapke shader attributes
global proc setDosAtt(){

    string $shader;
    string $selectedShaders[] = `ls -sl`;
    string $attribute1 = ".diffuseMultiplier";
    string $attribute2 = ".diffuseColor";
    string $attribute3 = ".applySRGB";
    string $attribute4 = ".forwardScattering";
    string $attribute6 = ".occlSamples";
    string $attribute7 = ".specRoughness";
    string $attribute8 = ".specularColor";
    string $attribute9 = ".fresnelIntensity";
    string $attribute10 = ".fresnelCoeff";
    string $attribute11 = ".fresnelBias";
    string $attribute12 = "._computesOpacity";
    vector $setting1 = <<1, 1, 1>>;
    vector $setting2 = <<1, 1, 1>>;
    float $setting3 = 1.0;
    float $setting4 = 0.1;
    float $setting5 = 0.6;
    float $setting6 = 16.0;
    float $setting7 = 0.5;
    vector $setting8 = <<1, 1, 1>>;
    float $setting9 = 0.2;
    float $setting10 = 0.05;
    float $setting11 = 0.5;
    float $setting12 = 1.0;
   
    if(`size $selectedShaders` == 0)
    {
    error "Nothing is selected. Please select your Renderman Shaders before initiating.";
    }
   
    for($shader in $selectedShaders)
    {
        setAttr ($shader + $attribute1) $setting1;
        setAttr ($shader + $attribute2) $setting2;
        setAttr ($shader + $attribute3) $setting3;
        setAttr ($shader + $attribute4) $setting4;
        setAttr ($shader + $attribute6) $setting6;
        setAttr ($shader + $attribute7) $setting7;
        setAttr ($shader + $attribute8) $setting8;
        setAttr ($shader + $attribute9) $setting9;
        setAttr ($shader + $attribute10) $setting10;
        setAttr ($shader + $attribute11) $setting11;
        setAttr ($shader + $attribute12) $setting12;
    }

}


No Responses to “MEL: specifying shader paths & files with numbers”

Post a Comment