Tuesday, May 28, 2013

Export/Import Shading Group Set Members

On the off chance a scenes shaders needs to be exported and then imported to the same scene without shaders(happens in production...). Doesn't work with face components, will need to do that manually. fixed: copy pasted the import code in the export code.


Export

proc exportSG() {
    string $shadingGroup[];
    $shadingGroup = `ls -sl -type shadingEngine`;
    string $mesh[];
    string $shaders[];
    string $meshList = ("/home/julio/meshlist.txt" );
    int $fileId =`fopen $meshList "w"`;
    for($i = 0; $i < size($shadingGroup); $i++) {
        select -r -ne $shadingGroup[$i];
        $mesh = `listConnections -s 1 -d 0 -type mesh`;
        $face = `listConnections -s 1 -d 0`;
        $meshList = ("/home/julio/meshlist.txt" );
    
        for($j = 0; $j < size($mesh); $j++) {
            fprint $fileId ($shadingGroup[$i] + " " + $mesh[$j] + "\n");
            }
    }
        fclose $fileId;
    }
    
    exportSG;


Import

proc importSG() {
    int $fileId =`fopen "/home/julio/meshlist.txt" "r"`;
    string $buffer[];
    string $nextLine = `fgetline $fileId`;
    while ( size( $nextLine ) > 0 ) {
        tokenize $nextLine " " $buffer;
        select -r $buffer[1];
        sets -e -forceElement $buffer[0];    
        $nextLine = `fgetline $fileId`;
    }
    fclose $fileId;
}

importSG;

0 comments:

Post a Comment