return an array of meshes among any selection

return an array of meshes among any selection

jerome.pourcel
Contributor Contributor
504 Views
2 Replies
Message 1 of 3

return an array of meshes among any selection

jerome.pourcel
Contributor
Contributor

Hi,

I wanted to extract from any selection (meshes, locator, cameras, lights...) only the mesh objects.

As `ls -sl -typ mesh` returns nothing, I did this:

 

proc string [] ReturnMeshListFromSelection ()
{
	string $allMeshes [];
	string $selectedMeshes [];
	string $selection [] = `ls -sl -tr`;
	string $allMeshesShapes [] = `ls -typ mesh`;
	for ($obj in $allMeshesShapes)
	{
		string $transformNode [] = `listRelatives -p $obj`;
		$allMeshes [size ($allMeshes)] = $transformNode [0];
	}
	for ($each in $selection)
	{
		if (stringArrayContains ($each,$allMeshes))
		{
			$selectedMeshes [size($selectedMeshes)] = $each;
		}
	}
	return $selectedMeshes;
}

It seems ok but i'm sure there is a smarter and shorter way to do this.

Anyone?

0 Likes
Accepted solutions (1)
505 Views
2 Replies
Replies (2)
Message 2 of 3

rajasekaransurjen
Collaborator
Collaborator
Accepted solution

Hi,

Try this....

string $selection [] = `ls -sl -tr`; //lists all the selected transform nodes in the scene.
string $selectedMeshes [] = `filterExpand -sm 12 $selection`; //filters out all the non-polymesh nodes.

 

Message 3 of 3

jerome.pourcel
Contributor
Contributor

I must admit that it's quite better Smiley Very Happy

filterExpand, I should have thought about it...

 

Thanks a lot.

0 Likes