// =========================================================================== // 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. // =========================================================================== global proc polyConvertToShell() { //array of cmds to be executed string $cmdLine[]; // 1. Convert selected edges to face, extendToShell, and convert // the faces back to edges. // string $edgeToFace[] = `polyListComponentConversion -fe -tf`; string $edgeToFaceExpanded[] = `filterExpand -ex true -sm 34 $edgeToFace`; if (`size $edgeToFaceExpanded`) { string $buffer[]; int $numTokens; //tokenize to get the component numbers $numTokens = `tokenize $edgeToFaceExpanded[0] "[]" $buffer`; //Variable to count number of objects (number of command strings) int $numObjs = 1; string $checkObjName; int $temp; string $objName[]; //tokenize to get the object name $temp = `tokenize $buffer[0] "." $objName`; //Start building the cmd for the 1st object selected $cmdLine[0] = "polySelect -ns -asSelectString -ets "; $cmdLine[0] = $cmdLine[0] + $buffer[1]; $checkObjName = $objName[0]; int $i; //If there is more than one component loop through the rest if (`size $edgeToFaceExpanded` > 1){ int $temp; string $objName[]; for ($i = 1;$i < `size $edgeToFaceExpanded`;$i++) { $numTokens = `tokenize $edgeToFaceExpanded[$i] "[]" $buffer`; $temp = `tokenize $buffer[0] "." $objName`; //check if the object name of the next component is different //if it is end the old command string and start a new one if ($objName[0] != $checkObjName){ $cmdLine[$numObjs - 1] = $cmdLine[$numObjs - 1] + " " + $checkObjName; $checkObjName = $objName[0]; $cmdLine[$numObjs] = "polySelect -ns -asSelectString -ets "; $cmdLine[$numObjs] = $cmdLine[$numObjs] + $buffer[1]; $numObjs++; //If it is the same object name, simply add the new components //to the command string } else { $cmdLine[$numObjs - 1] = $cmdLine[$numObjs - 1] + " -ets " + $buffer[1]; } } //need to add the last object name at the very end $cmdLine[$numObjs - 1] = $cmdLine[$numObjs - 1] + " " + $checkObjName; } //Convert the selection of faces back to edges by evaluating each //command line and converting for ($i = 0;$i < $numObjs;$i++) { string $faceShellForEdges[] = eval($cmdLine[$i]); if (`size $faceShellForEdges` > 0) { string $faceShellToEdges[] = `polyListComponentConversion -ff -te $faceShellForEdges`; select -addFirst $faceShellToEdges; } } } // 2. Convert selected verts to face, extendToShell, and convert // the faces back to edges. // string $vertToFace[] = `polyListComponentConversion -fv -tf`; string $vertToFaceExpanded[] = `filterExpand -ex true -sm 34 $vertToFace`; if (`size $vertToFaceExpanded`) { string $buffer[]; int $numTokens; //tokenize to get the component number $numTokens = `tokenize $vertToFaceExpanded[0] "[]" $buffer`; //variable to keep track of the number of objects selected //one command line for each int $numObjs = 1; string $checkObjName; int $temp; string $objName[]; //tokenize to get the object name $temp = `tokenize $buffer[0] "." $objName`; //Build up the first command line $cmdLine[0] = "polySelect -ns -asSelectString -ets "; $cmdLine[0] = $cmdLine[0] + $buffer[1]; $checkObjName = $objName[0]; int $i; //If more that one component, loop through them all if (`size $vertToFaceExpanded` > 1){ int $temp; string $objName[]; for ($i = 1;$i < `size $vertToFaceExpanded`;$i++) { $numTokens = `tokenize $vertToFaceExpanded[$i] "[]" $buffer`; $temp = `tokenize $buffer[0] "." $objName`; //If the new object name is different than end the old command string //and begin a new one for this object if ($objName[0] != $checkObjName){ $cmdLine[$numObjs - 1] = $cmdLine[$numObjs - 1] + " " + $checkObjName; $checkObjName = $objName[0]; $cmdLine[$numObjs] = "polySelect -ns -asSelectString -ets "; $cmdLine[$numObjs] = $cmdLine[$numObjs] + $buffer[1]; $numObjs++; //If it is not different add the current component to the command //string } else { $cmdLine[$numObjs - 1] = $cmdLine[$numObjs - 1] + " -ets " + $buffer[1]; } } //Add the object name on the very last command string $cmdLine[$numObjs - 1] = $cmdLine[$numObjs - 1] + " " + $checkObjName; } //Convert the face commands back to vertices by evaluating each command //and converting for ($i = 0;$i < $numObjs;$i++) { string $faceShellForVerts[] = eval($cmdLine[$i]); if (`size $faceShellForVerts` > 0) { string $faceShellToVerts[] = `polyListComponentConversion -ff -tv $faceShellForVerts`; select -addFirst $faceShellToVerts; } } } // 3. extendToShell on selected faces. // string $faces[] = `filterExpand -ex true -sm 34`; if (`size $faces`) { string $buffer[]; int $numTokens; //tokenize to get the component numbers $numTokens = `tokenize $faces[0] "[]" $buffer`; //variable to keep track of the number of objects, in order to //have one command line for each object int $numObjs = 1; string $checkObjName; int $temp; string $objName[]; //tokenize for the object name $temp = `tokenize $buffer[0] "." $objName`; //Build the first command string $cmdLine[0] = "polySelect -af -asSelectString -ets "; $cmdLine[0] = $cmdLine[0] + $buffer[1]; $checkObjName = $objName[0]; int $i; //If there is more than 1 component loop through the rest if (`size $faces` > 1){ int $temp; string $objName[]; for ($i = 1;$i < `size $faces`;$i++) { $numTokens = `tokenize $faces[$i] "[]" $buffer`; $temp = `tokenize $buffer[0] "." $objName`; //If the current object name is different from the last, end the old //command string and start a new one if ($objName[0] != $checkObjName){ $cmdLine[$numObjs - 1] = $cmdLine[$numObjs - 1] + " " + $checkObjName; $checkObjName = $objName[0]; $cmdLine[$numObjs] = "polySelect -af -asSelectString -ets "; $cmdLine[$numObjs] = $cmdLine[$numObjs] + $buffer[1]; $numObjs++; //If it is the same simply add the current component to the command string } else { $cmdLine[$numObjs - 1] = $cmdLine[$numObjs - 1] + " -ets " + $buffer[1]; } } //Add the object name to the very last command string $cmdLine[$numObjs - 1] = $cmdLine[$numObjs - 1] + " " + $checkObjName; } //Evaluate all the command strings for ($i = 0;$i < $numObjs;$i++){ eval($cmdLine[$i]); } } }