mo49
7/14/2019 - 8:54 AM

detachSeparate.md

https://www.highend3d.com/maya/script/detachseparate-mel-for-maya

面選択したオブジェクトを別オブジェクトとして分離する

//detachSeparate.mel v1.1
//Jeff Dobson 7/2/01
//jeffdobs@swbell.net
//
//DESCRIPTION: This script will effectively detach and separate selected faces from a poly mesh.
//Advantages of this script over Maya's built in detach/separate is that this script doesn't create
//a third parent node.  It also allows you to break off only the selected faces as opposed to exploding
//every sub-mesh of an object.
//SETUP:  Create a shelf button or hotkey with the command   detachSeparate;
//ICON:  detachSeparate.bmp
//HISTORY: 7/20/01 - v1.1 -- Changed duplicate command to -un from -rr.  Fixes bug that leaves an extra
        // shape node when script is run on an object with an extrude in its history.


global proc detachSeparate()
{
	string $nameSplitSkip[];
	string $faceNum[];
	string $temp[];
	string $newObj[];
	string $newFaceSel[];

	string $origFaceSel[] = `filterExpand -ex 1 -sm 34`;
	string $origObjShape[] = `listRelatives -p $origFaceSel`;
	string $origObj[] = `listRelatives -p $origObjShape`;
	
	//Get my selected face numbers into $faceNum
	for ($step = 0, $skip = 0; $step < size($origFaceSel); $step++, $skip++)
	{
		tokenize $origFaceSel[$step] "." $temp;
		$nameSplitSkip[$skip] = $temp[0];
		$skip++;
		$nameSplitSkip[$skip] = $temp[1];
		clear $temp;
	}
	
	for ($step2 = 0, $skip2 = 1; $step2 < (size($nameSplitSkip)/2); $step2++, $skip2 = $skip2 + 2)
	{
		$faceNum[$step2] = $nameSplitSkip[$skip2]; //every other value	
	}
	
	//Dupe original object
	$newObj = `duplicate -un $origObj[0]`;
	delete -ch $newObj[0];
	string $newAllFaces[] = `ls ($newObj[0] + ".f[*]")`;
	
	//Make new array for face selection on $newObj
	for ($step3 = 0; $step3 < size($faceNum); $step3++)
	{
		$newFaceSel[$step3] = ($newObj[0] + "." + $faceNum[$step3]);
	}
	
	//Delete original face selection
	delete $origFaceSel;
	
	//Delete inverse face selection on duplicate
	select -r $newAllFaces;
	select -d $newFaceSel;
	delete;
	select -r $newObj[0];
}