PDA

View Full Version : Random selection


Irakli
08-18-2009, 11:39 AM
How to select randomly about 50% of objects in the scene?
I guess first need to get list:
string $mySel[] = `ls -sl`;
then I neen to know how how many objects there are in the seletion:
int $myNum = size($mySel)

then I need to use rand command but I don't know how.

Jacobborsting
08-18-2009, 01:51 PM
Here is a python script to do that:


import maya.cmds as mc
import random

sl = mc.ls(tr=1)
size = len(sl)
procent = .5 # 0 to 1

for o in range(size*(1-procent)):
index = random.randrange(0,(len(sl)-1))
sl.pop(index)

mc.select (sl)
print 'There are %s objects in the selection out of a total of %s' % (len(sl),size)


edit: the indentation seems to get messed up in the post.

Irakli
08-18-2009, 02:02 PM
Thank you! I've never used Python but I'll reed documentation.

CGTalk Moderation
08-18-2009, 02:02 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.