Skip to content
Tags

MEL: Querying the Illuminates by Default attribute

by nikos on March 14th, 2011

Finding lights in Maya that have the “Illuminates by Default” attribute on/off can be a bit tricky because we aren’t querying a normal attribute but instead a connection between nodes. Here’s a procedure that allows us to select lights that have the flag enabled or disabled.

Usage:
selectIlluminatesByDefault( 0 ); // selects all lights with the flag “off”
selectIlluminatesByDefault( 1 ); // selects all lights with the flag “on”

proc selectIlluminatesByDefault( int $mode ) {
    select -clear;
    string $lights[] = `ls -dag -lights`;
    for ( $light in $lights ) {
        string $transforms[] = `listRelatives -parent $light`;
        string $connections[] = `listConnections $transforms[0]`;
        string $inst = $transforms[0] + ".instObjGroups";
        string $dfs[] = `connectionInfo -dfs ( $inst )`;

        int $isConnected = 0;
        if ( objExists( $dfs[0] ) && `isConnected $inst $dfs[0]` ) {
            $isConnected = 1;
        }
        if ( $mode == 1 ) {
            if ( $isConnected ) {
                select -add $light;
            }
        }
        else {
            if ( !$isConnected ) {
                select -add $light;
            }
        }
    }
}

From → MEL

No comments yet

Leave a Reply

You must be logged in to post a comment.