// =========================================================================== // 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: 18 April 1997 // // proc concatArray (string $res[], string $in[]) { for ($i in $in) $res[size($res)] = $i; } proc string[] extractShapesWithPath (string $in[], string $type) { string $res[]; for ($i in $in) { // first test that the visibility exists for the object string $vis_exists[1]=`listAttr -s -st visibility $i`; if (size($vis_exists) == 0) continue; // then check if the object is visible (or it will mess up the // unite/separate implementation) int $vis=`getAttr ($i + ".visibility")`; if ($vis != 1) continue; // now check if the object is not an intermediate object... $vis_exists=`listAttr -s -st intermediateObject $i`; if (size($vis_exists) != 0) { $vis=`getAttr ($i + ".intermediateObject")`; if ($vis != 0) continue; } if ($type == `nodeType $i`) $res[size($res)]=$i; else { // this means that if a top level object is selected // its children are selected too... string $curlevel[]=`listRelatives -c -pa $i`; if (size($curlevel) != 0) concatArray $res `extractShapesWithPath $curlevel $type`; } } return $res; } global proc string[] polyCheckSelection (string $fun, string $funtype, int $expandInstances) { // first set up various attributes & selection constraints // to allow the action to show up clearly // extract command name string $tmp[]; tokenize($fun, $tmp); $fun = $tmp[0]; string $sres[]; int $res=0; int $isInstalled=0; if ($funtype == "o") { // for function that work on objects, we need to do the job ourselves... string $sel[]; polyInstallAction -uc -ud; // remove any pending constraint. // unite, separate and boolean ops want all the shapes, // but with their correct path information. // Note bool ops need to take the lead object separately... $sel=`ls -sl`; string $hllist[]=`ls -hl`; if (size($hllist) != 0) concatArray $sel $hllist; $sres=`extractShapesWithPath $sel "mesh"`; $res=size($sres); clear $sel; if ($res == 0) { string $fmt = (uiRes("m_polyCheckSelection.kOnlyWorksForPolygons")); warning `format -s $fun $fmt`; } } else { if (`optionVar -q polyAutoConvertAction`) { if ($expandInstances) { $sres = `polyInstallAction -keepInstances -cs $fun`; } else { $sres = `polyInstallAction -cs $fun`; } if (! `optionVar -q polyAutoInstallAction`) polyInstallAction; // Remove settings } else if (`optionVar -q polyAutoInstallAction`) if ($expandInstances) { $sres = `polyInstallAction -keepInstances $fun`; } else { $sres = `polyInstallAction $fun`; } else { polyInstallAction; // Remove prev settings $sres = `ls -sl`; } // usually polyInstallAction of a poly command provides // the list of all matching items $res = size($sres); $isInstalled = `polyInstallAction -q -cn` != ""; } global string $gPolyLastTool; global string $gSelect; if ($res == 0) { if (! `optionVar -q polyAutoInstallAction`) { if ($isInstalled) polyInstallAction -uc $fun; // no last tool to store $gPolyLastTool=""; } else { // *** should show in setSelectMode that the mode is for $fun // *** should set a script job to remove the sel. constraints. // when the selectMode or selectType is changed. $gPolyLastTool=`currentCtx`; setToolTo $gSelect; } } else { if (`optionVar -q polyAutoInstallAction` && (`getModifiers` % 2) == 1) { // shift is down string $fmt = (uiRes("m_polyCheckSelection.kSetupWarning")); warning `format -s $fun $fmt`; // setup for action: don't do the action, just prepare for it... clear $sres; // *** should show in setSelectMode that the mode is for $fun // *** should set a script job to remove the sel. constraints. // when the selectMode or selectType is changed. } else { // uninstall selection constraints if ($isInstalled) polyInstallAction -uc $fun; } // store last tool $gPolyLastTool=`currentCtx`; setToolTo $gSelect; } // return array of objs to process return $sres; }