// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== // // // Creation Date: 14 May 1997 // // File Name: // deleteShadingGroupsAndMaterials.mel // // Description: // This file holds useful delete utilities used in // various spots in the UI. // ////////////////////////////////////////////////////////////////////// // // Procedure Name: // resetDefaultShadingGroup // // Description: // // Pick the first renderable shading group // and set it to be the default. If the geometry string // is not "", take the given geometry and assign it // to the new default. // // This proc is most useful when deleting the default shading group. // // Input Arguments: // $geometry - string in the form "obj1 obj2 ... objx" // where objx is the name of an object to be reassigned to // the new default shader. // // Return Value: // None. // // Examples: // resetDefaultShadingGroup ""; // choose a new one, no assignments // // choose a new one, and assign nurbsSphere3 nurbsPlane1 to it. // resetDefaultShadingGroup "nurbsSphere3 nurbsPlane1"; // global proc resetDefaultShadingGroup(string $geometry) { // check for reassigning default SG string $sets[] = `ls -sets`; // find the first renderable SG string $surface[]; string $surfacePlug; int $numSurfs; for($set in $sets) { if (`sets -q -renderable $set`) { $numSurfs = 0; // renderable set // check if this guy has a surface shader. $surfacePlug = ($set + ".surfaceShader"); catch ( $surface = `listConnections -source true -destination false $surfacePlug` ); $numSurfs = `size $surface`; if($numSurfs > 0) { string $msg = (uiRes("m_deleteShadingGroupsAndMaterials.kSetDefault")); print (`format -stringArg $set $msg`); setDefaultShadingGroup $set; break; } else { string $msg = (uiRes("m_deleteShadingGroupsAndMaterials.kNoSurfaceShader")); warning (`format -stringArg $set $msg`); clear $surface; } } } if ($geometry != "") { string $cmd = ("sets -e -forceElement " + $set + " " + $geometry); eval $cmd; } } ////////////////////////////////////////////////////////////////////// // // Procedure Name: // deleteShadingGroups // // Description: // Safely deletes all the given shading groups. It // Checks each element for whether it's 1) a set and // 2) renderable. Gemoetry is moved from the deleted groups // to the default shading group. If the default group is // among the deleted, a new default group is arbitrarily picked. // // Input Arguments: // $sets - array of set names. These are assumed to be sets or shading groups. // // Return Value: // None. // // Examples: // string $SGs[] = `ls -type shadingEngine`; // deleteShadingGroups $SGs; // global proc deleteShadingGroups(string $sets[]) { string $defaultSG = `setDefaultShadingGroup -q`; string $reAssign[]; string $objs[]; int $newDefault = false; int $count = 0; int $numObjs = `size $sets`; if($numObjs > 0 ) { // deactivate swatch rendering renderThumbnailUpdate false; } // Delete all shadinggroups first. string $objList = ""; for ($set in $sets) { if (`sets -q -renderable $set`) { // renderable set $objs = `sets -q $set`; for($obj in $objs) { $objList += ($obj + " "); } string $cmd = ("delete " + $set); if((catch (`eval ($cmd)`)) && $newDefault == false && $set == $defaultSG) { $newDefault = true; } } } if($newDefault) { resetDefaultShadingGroup $objList; } else if ($objList != "") { string $cmd = ("sets -e -forceElement " + $defaultSG + " " + $objList); eval $cmd; } // reactivate swatch rendering renderThumbnailUpdate true; } //////////////////////////////////////////////////////////////////////// // Procedure Name: // deleteShadingGroupsAndMaterials // // Description: // Deletes all shading groups and everything // returned by "ls -materials". Geometry in the // shading groups is reassigned to the // intialShadingGroup, which cannot be deleted. // // Input Arguments: // None. // // Return Value: // None. // // // // deleteShadingGroupsAndMaterials // // // deleteShadingGroupsAndMaterials // // // None // // // None // // // Deletes all shading groups and everything // returned by "ls -materials". Geometry in the // shading groups is reassigned to the // intialShadingGroup, which cannot be deleted. // // // // deleteShadingGroupsAndMaterials; // // global proc deleteShadingGroupsAndMaterials( ) { // deactivate swatch rendering renderThumbnailUpdate false; // first the shading groups string $targets[] = `ls -sets`; deleteShadingGroups $targets; // then the materials int $issueCmd = false; $targets = `ls -mat`; string $cmd = "delete "; for($target in $targets) { $cmd += ($target + " "); $issueCmd = true; } if($issueCmd) { eval $cmd; } // reactivate swatch rendering renderThumbnailUpdate true; }