Select all by type: Geometry. Equivalent Python script?

geometry, maya, python, scripting, select

Solution

What you're seeing is the procedure `SelectAllGeometry`, and its contents:

select -r `listTransforms -geometry`;

That command is several parts. The part in the backquotes:

listTransforms -geometry

Is actually a MEL procedure. Run the command `help listTransforms` to see the path to the .mel file. Reading that, the command is actually

listRelatives("-p", "-path", eval("ls", $flags));

The output of that is the argument to:

select -r the_list_of_geometry_transforms

So check out Maya's MEL and Python command reference for `select`, `listRelatives`, and `ls`, to research how one command translates to the other:

- select

- listRelatives

- ls

Combining that all together, the equivalent MEL actually being called is:

select -r `listRelatives("-p", "-path", eval("ls", $flags))`

And as Python, that would be:

from maya import cmds
cmds.select(cmds.listRelatives(cmds.ls(geometry=True), p=True, path=True), r=True)

Expanded out to be just a tad more readable:

from maya import cmds
geometry = cmds.ls(geometry=True)
transforms = cmds.listRelatives(geometry, p=True, path=True)
cmds.select(transforms, r=True)

Problem

I was trying to find the right code to make maya select all the geometry objects in my scene. I tried to echo command while doing the operation and I get this: ``` SelectAllGeometry; select -r `listTransforms -geometry`; ``` (Edit > Select All by Type > Geometry) Could anyone translate this to Python?

Original source