// =========================================================================== // 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. // =========================================================================== // // // // // // containerAssignMaterial(string $container, string $object) // // // This command assigns the object to the shading group found in the // container. If there is more than one shading group in the container, // the user can control which shading group is used by publishing // the shading group as a published node with the name "mainSG". // // If no object is specified, the command will work on the selection. // // // none // // // string $container the container with the shader // string $object the object to associate with the shader, or an empty string to act on selection // // // // Associate the selection to the shading group of $containerName // containerAssignMaterial $containerName ""; // // // Associate the a mesh to the shading group of $containerName // containerAssignMaterial $containerName $mesh; // // // global proc containerAssignMaterial(string $container, string $object) { string $shadingGroup; // First, see if a shading group is published // string $boundNodes[] = `containerPublish -q -bn $container`; int $ii, $nodeCount = size($boundNodes); for ($ii = 0; $ii < $nodeCount; $ii+=2) { if ($boundNodes[$ii] == "mainSG") { $shadingGroup = $boundNodes[$ii+1]; break; } } if (size($shadingGroup) == 0) { string $members[] = `container -q -nodeList $container`; string $sets[] = `ls -type objectSet $members`; $nodeCount = size($sets); int $shadingGroupCount = 0; for ($ii = 0; $ii < $nodeCount; $ii++) { string $materialInfo[] = `listConnections -type "materialInfo" ($sets[$ii]+".msg")`; if (size($materialInfo) > 0) { if ($shadingGroupCount == 0) { $shadingGroup = $sets[$ii]; } $shadingGroupCount++; } } if ($shadingGroupCount > 1) { string $warnMsg = (uiRes("m_containerAssignMaterial.kMoreThanOneSG")); warning($warnMsg); } } if (size($shadingGroup) > 0) { string $cmd = ("sets -forceElement \""+$shadingGroup+"\" "); if (size($object) > 0) { $cmd += $object; } eval $cmd; } else { error((uiRes("m_containerAssignMaterial.kFoundNoShadingGroup"))); } }