Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 571
Ramon Blanquer Avatar asked Aug 14 '26 11:08

Ramon Blanquer


2 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:

  • 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)
like image 160
mhlester Avatar answered Aug 17 '26 01:08

mhlester


It's easy:

import maya.cmds as cmds

cmds.SelectAllGeometry()
like image 41
Pramod Nirwan Avatar answered Aug 17 '26 01:08

Pramod Nirwan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!