Maya Training

Creating characters In Maya and Zbrush

Maya Training

Creating character renders in Maya 2017 and Arnold

Maya Training

Spach-Alspaugh House the complete courseware
You are here > Home > SimplyMaya Community Forums

Welcome to Simply Maya

Please Sign in or Sign up for an account

Member Login

Lost your password?

Not a member yet? Sign Up!

Old 14-12-2008, 11:39 AM   #1
bendingiscool's Avatar
Join Date: Jul 2006
Location: London
Posts: 567
Thanks: 0
Thanked 1 Time in 1 Post
Default select random object in selection

Hey, ok this should be dead simple, but I can't work out the syntax.

Basically I want to be able to be able to select a bunch of geometry, cubes, cylinders, etc, then go through a loop randomly instancing one of them each time through.

So far I have...

string $sel[] = `ls -sl`;

for ($i=0; $i<10; $i++)
select $sel[1];

now this is just going to select a specified object from the selection, what I want is to be able to select a random object of the selection each time it loops through.

Many thanks, Chris
bendingiscool is offline   Reply With Quote
Old 16-12-2008, 08:45 AM   #2
Registered User
t1ck135's Avatar
Join Date: May 2004
Location: UK
Posts: 1,991
Thanks: 0
Thanked 0 Times in 0 Posts

check out rand() in the documentation
you'll be able to grab a random value in the range of (in your example) 0 to 10 and use that in the select statement

if I had maya installed (learning the slightly cheaper blender at the minute) then I'd modify your code to get it working but you should be able to figure it out easily enough.

Examples of bTraffic - a traffic animation tool for Maya
bFlocking - a tool for Maya 8.5+ to generate flocking and swarming behaviours
Jan/Feb Challenge 2007 Entry and W.I.P
May/Jun Challenge 2006 Entry and W.I.P
Mar/Apr Challenge 2006 Entry and W.I.P
Jan/Feb Challenge 2006 Entry and W.I.P
Nov/Dec Challenge 2005 Entry and W.I.P
Sep/Oct Challenge 2005 Entry and W.I.P
Jul/Aug Challenge 2005 Entry
t1ck135 is offline   Reply With Quote

A little bit about who we are
Links you might find useful
Catch up with SimplyMaya
SimplyMaya specialises in Maya tutorials. We offer over 1,000 individual Maya training videos, ranging from basic Maya tutorials through to intermediate Maya tutorials. Our tutorials are created by instructors with industry experience and are designed to get you up and running in Maya quickly without making it seem like hard work.

Copyright © 1999-2017 SimplyMaya - vBulletin® Copyright © 2000-2017, Jelsoft Enterprises Ltd.