select Random edges

224 views
Skip to first unread message

Vishal Kadam

unread,
Jun 1, 2020, 3:38:03 AM6/1/20
to Python Programming for Autodesk Maya
Hello,

can anyone help me, I want to select random edges using python script, as we do that from polygon selection constraint on edges then adjusting the count using ratio value

MichaelEden

unread,
Jun 1, 2020, 3:56:41 AM6/1/20
to Python Programming for Autodesk Maya
# import random module, documentation is here:
import random

# select the object
selection = cmds.ls(sl=True)[0]
# calculate how many edges this object have
maxRandomValue = cmds.polyEvaluate(edge=True)

# select the random edges of the object selected
cmds.select("{}.e[{}]".format(selection, random.randint(0,maxRandomValue)))

# print
print "{} is selected".format(cmds.ls(sl=True)[0])


hopefully it helps. cheers. 

Vishal Kadam

unread,
Jun 1, 2020, 8:16:45 AM6/1/20
to Python Programming for Autodesk Maya
thanks but it selects only one random edge

Vishal Kadam

unread,
Jun 1, 2020, 10:06:16 AM6/1/20
to Python Programming for Autodesk Maya
I have this in mel but I need this in python

ConvertSelectionToEdges;
PolySelectConvert 2;
PolySelectConstraint -m 2;
PolySelectConstraint -r true;
PolySelectConstraint -rr 0.20;
polySelectSp -loop;

in this polySelectSp -loop; is not selecting edge loop properly it skips few edge loops and stuck in the middle

can anyone help me to convert this in python or can I have same kind of script where I can select random edge loops

Vishal Kadam

unread,
Jun 4, 2020, 2:17:13 AM6/4/20
to Python Programming for Autodesk Maya
Hi can anyone please reply on this

MichaelEden

unread,
Jun 4, 2020, 2:33:03 AM6/4/20
to Python Programming for Autodesk Maya
i'm not sure what you mean. but if you already have mel script and want to change it into python in a hurry, just convert it using mel.eval

from maya import mel

mel
.eval("
ConvertSelectionToEdges;")
mel.eval("PolySelectConvert 2;")
mel.eval("PolySelectConstraint -m 2;")
mel.eval("PolySelectConstraint -r true;")
mel.eval("PolySelectConstraint -rr 0.20;")
mel.eval("polySelectSp -loop;")



Vishal Kadam

unread,
Jun 4, 2020, 3:01:02 AM6/4/20
to Python Programming for Autodesk Maya
this doesn't work for me as I need it, so basically I want to select random edges from an object and control the random count by a value, can that be possible using python

Soham Parmar

unread,
Jun 4, 2020, 3:24:01 AM6/4/20
to python_in...@googlegroups.com
I am also not sure what exactly what you want, but if you just want to select random edges from polygon then MichaelEden’s first reply was helpful i think. you just want to change some line if you want multiple edges rather then one.
i have quickly  changed few line from MichaelEden’s first reply for selecting multiple edges.

import random
def randomEdgeSelection(obj, randomEdgeCount):


# calculate how many edges this object have
maxRandomValue = cmds.polyEvaluate(edge=True)

   # random edges count can not be grater the edges in the poly
if randomEdgeCount > maxRandomValue:
cmds.error("randomEdgeCount can not be grator then maxRandomValue")

edgeIndex = []
for i in range(randomEdgeCount):

# select the random edges of the object selected
      edgeIndex.append(random.randint(0, maxRandomValue))

edges = []
for index in edgeIndex:
edges.append("{0}.e[{1}]".format(obj, index))

cmds.select(edges)

randomEdgeSelection(cmds.ls(sl=True)[0], 20)
hopefully it helps.

-- 
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/53235f73-0223-4e2c-807e-eb65306e5f3b%40googlegroups.com.

Vishal Kadam

unread,
Jun 8, 2020, 5:56:45 AM6/8/20
to Python Programming for Autodesk Maya
Thanks this it works but for example if I have a cube with these values height = 5, subdiv width and depth = 5, and  subdiv height = 20, and when we use this script horizontal edges selection will be very lesser than vertical edges, so is it possible to select more random edges horizontally, or control the count of edge selection for vertically and horizontally
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
Message has been deleted

Vishal Kadam

unread,
Jun 9, 2020, 7:30:24 AM6/9/20
to Python Programming for Autodesk Maya
Hi can anyone please reply on this

Marcus Ottosson

unread,
Jun 9, 2020, 8:06:16 AM6/9/20
to python_in...@googlegroups.com
You've already gotten tons of (really good!) help Vishal, but I haven't seen you apply any of the help to your problem. What have you tried so far, where do you get stuck?

To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/b4e44ad0-69cf-43ce-b8ba-d95cbcf2dbbao%40googlegroups.com.

Vishal Kadam

unread,
Jun 9, 2020, 9:18:45 AM6/9/20
to Python Programming for Autodesk Maya
The help which Soham Parmar has done it works as same as the built-in maya from poly constraints selecting random edges that is fine it works and thanks for that, but my question is is there any option or possibility possible to select more random edges horizontally, or control the count of edge selection for vertically and horizontally
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages