Return RenderElement-nodeName with Mel procedure vrayAddRenderElement

Hi Guys,

just FYI…it would be great for scripting if you could return the nodeName of a newly created RenderElement…i just hacked your mel…its just some minor changes…maybe you could implement it in the next releases…


// $index is the index in the vrayRenderElementsNames and vrayRenderElementsLabels arrays
global proc string vrayAddRenderElementImpl(int $ind) {
    global string $vrayRenderElementsNames[];
    global string $vrayRenderElementsLabels[];

    string $node;
    if ($vrayRenderElementsNames[$ind]=="LightSelectElement") $node=`createNode VRayRenderElementSet`;
    else $node = `createNode VRayRenderElement`;

    string $newName = "vrayRE_" + $vrayRenderElementsLabels[$ind];
    // Maya would do this automatically, but produces some warnings.
    $newName = `substituteAllString $newName " " "_"`;
    $newName = `substituteAllString $newName "-" "_"`;
    $node = `rename $node $newName`;    
    string $endingNum;
    if (size($node) != size($newName)) $endingNum = `match "[0-9]*$" $node`;
    addAttr -ln "vrayClassType" -dt "string" $node;
    setAttr -type "string" ($node+".vrayClassType") $vrayRenderElementsNames[$ind];
    addAttr -ln "enabled" -keyable true -at "bool" -dv 1 $node;
    int $j;
    for ($j = 0;; $j++) {
        string $buffer[] = `vray getAHint "RenderElement" $vrayRenderElementsNames[$ind] ("attribute_" + $j)`;
        string $attrName = $buffer[0];
        if (size($attrName) == 0) break;
        vrayAddAttr($node, $attrName);
        // If we have more than one RE of the same type - change the suffix so that different output files are created.
        $buffer = `vray getAHint "RenderElementAttribute" $attrName "vray_parameter"`;
        string $vray_parameter = $buffer[0];
        if ($vray_parameter == "name" && $endingNum != "" && 
            $vrayRenderElementsNames[$ind] != "ExtraTexElement" && $vrayRenderElementsNames[$ind] != "MaterialSelectElement") {

            string $currentVal = `getAttr ($node+"."+$attrName)`;
            setAttr -type "string" ($node+"."+$attrName) ($currentVal+$endingNum);
        }
    }
[B]    return $node;[/B]
}

global proc string vrayAddRenderElement(string $renderElementName) {
    global string $vrayRenderElementsNames[];

    // Make sure the global arrays with the elements names/labels have been loaded, as the UI may not have been created yet
    vrayLoadRenderElementsGlobalArrays();
    [B]string $node;[/B]
    // Find the location of $renderElementName in the $vrayRenderElementsNames array
    for ($i=0; $i<size($vrayRenderElementsNames); $i++) {
        if ($vrayRenderElementsNames[$i]==$renderElementName) {
            [B]$node=[/B]vrayAddRenderElementImpl($i);
            updateListExistingElements(1);
            return [B]$node[/B];
        }
    }
    warning("Render element with name " + $renderElementName + " not found !");
}

This is already implemented since a long time in the nightly builds.

Best regards,
Vlado

Damn…sorry for that…but unfortunately i cannot work with nightlies at the moment but i thought i am :wink: