Select all by type: Geometry. Equivalent Python script?

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?

Answers


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:


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)

ls -type (or cmds.ls) use the maya node hierarchy (as laid out in the docs. So you can get all geometry shapes with ls -type geometryShape, since geometryShape is the node from which all other kinds of geometry derive. (Check the list in the link for ways to refine this by picking different types and subtypes)

To get the transforms, add a listRelatives -p. So the total would be

string $sh[] = `ls -type geometryShape`;
string $t[] = `listRelatives -p $sh`;
select -r $t;

It's easy:

import maya.cmds as cmds

cmds.SelectAllGeometry()

Need Your Help

place value in text box which has name in array format

jquery

In a page I have a number of text box with name in array format. I want to put a value 'test' in one of them when a function is executed or event is occured. But my jquery code puts value in all the