March 2019: is getting relocated to, please update your bookmarks.

MEL How-To #07

Back · Previous · Next Maya

How can I turn off all of a scene's textures for rendering (similar to the flag in PA)?

proc enableMaterials( int $enable )
// Usage:
//   enableMaterials( 0 );  -- turn off all Materials.  Everything renders
//                             gray.
//   enableMaterials( 1 );  -- turn on all Materials (normal render)
   string $materials[] = `ls -materials`;

   for ( $mat in $materials )
      shadingConnection -e -cs $enable ( $mat + ".color" );

To demonstrate what this script is doing, open the MultiLister and double-click on a Material to display it in the Attribute Editor.

Hold down the RMB over the 'Color' attribute label. One of the items in this pop-up menu is "Ignore When Rendering." This script is simply toggling this attribute -- formally known as the '-connectionState' attribute -- off or on.

To truly disable the texture you'd want to toggle the '.transparency,' '.ambientColor,' etc., attributes as well. I'll leave that as an exercise for the reader.

Note: The "Ignore When Rendering" option in the UI is only available on mapped attributes, and there's no indication when the -connectionState is disabled for unmapped attributes. This makes sense, I suppose -- a 'connectionState' doesn't affect something that doesn't have any connections.

Regardless, setting the '−connectionState' to false does take even on unmapped attributes. If you map an attribute for which the '−connectionState' is disabled, you will have to explicitly enable it to see the affects of the mapping.

Thanks to Scott Hamilton of A|W for sharing this technique.