Select edges automatically

49 views
Skip to first unread message

Chrysoula Kaloumenou

unread,
Dec 5, 2017, 5:37:49 PM12/5/17
to Python Programming for Autodesk Maya
Hello there!

I am fairly new to Maya, and a proper newbie to Maya scripting, so I'm sorry if my question seems silly.

So, I want to select a line of edges of a given object (a helix - image attached, in case it helps), but I haven't found any way that I could script that. According to the script editor, each edge is numbered, but it's practically impossible to name every edge that I want selected.

Do you think there is a way to resolve that?

Thank you very much! :)



Google group.png

Andres Weber

unread,
Dec 7, 2017, 3:39:35 PM12/7/17
to Python Programming for Autodesk Maya
It just depends on what you want to do and how you want to automate the selection (every nth edge, following a pattern, only edge loops, edge loop segments etc)

To select multiple edges you can use slices:
import maya.cmds as mc
start_edge
, end_edge = 1, 40
helix
, helix_shape = mc.polyHelix()
mc
.select(helix_shape+'.e[%d:%d'] % (start_edge, end_edge), r=True)

From what I´ve just hopefully understood about how they construct the shape for a helix specifically it looks like every edge loop is comprised of sets of edges where their indices are spaced out by n, where n is the number of subdivisions down the axis.  So if you wanted to select a line from a given starting edge:

import maya.cmds as mc
import re

selection
= mc.ls(sl=True, fl=True)
# Get the shape node of the selection
shape
= mc.listRelatives(selection[0], p=True)[0]
# Get the index of the selected edge
start_index
= [int(re.findall(r"[\w]+", i)[2]) for i in selection][0]

# Define what we know about the helix
num_edges
= 10
axis_subdivisions
= 8

edges
= [shape+'.e[%d]' % (start_index + (edge_index * axis_subdivisions)) for edge_index in range(num_edges)]
mc
.select(edges, r=True)

You kind of need to know a bit about the shape you're querying and how it's constructed etc.  As long as you can run through the idea in your head and come up with a way of doing it, you can write an algorithm for it.

However maybe someone else can think of a clever way of doing this on a grander scale or with custom/non default shapes, but I haven't found common patterns between shapes to be able to always select patterns I want regardless of types of shapes/construction.  I have seen some pretty neat scripts out there that do things like every nth edge etc so at least that kind of idea is well trodden if you want to go script hunting!

Andres Weber

unread,
Dec 7, 2017, 3:43:55 PM12/7/17
to Python Programming for Autodesk Maya
Oh and to add some simple code since I realized you might literally just be looking for simple edge loops:
# Query the current edges selected and return the edge loops they create then select it.
mc
.select(mc.polySelectSp(mc.ls(sl=True), q=True, loop=True), r=True)
Reply all
Reply to author
Forward
0 new messages