SimplyMaya Forums

Welcome to the forum, feel free to ask questions here.


SM Forums / Maya Questions / Programming / using mel to select multiple objects

Programming MEL Scripts, Expressions & Programming Related Topics

Join the conversation. Reply to post
 
Thread Tools
02-02-2017, 01:26 PM   #1
davad138
Registered User
 
Join Date: Feb 2017
Location: Glasgow, Scotland
Posts: 2
using mel to select multiple objects
i am trying to select a range of objects using mel. is this even possible?

for a uni project i am using ncloth to lay a cobblestone path (the path looks more natural when i do this) but when i delete the ncloth i am left with objects in two states, the initial and set. i can easily delete the duplicates but it is taking too long to do.

lets say my objects are called brick1-brick100, is there a way to select bricks 1-50 using mel? i know to select one object using select ("brick1*"); (or just select brick1 works also) - am i on the right track to selecting what i want?
  Reply with quote
11-02-2017, 03:28 PM   #2
NextDesign
Technical Director
 
NextDesign's Avatar
 
Join Date: Feb 2004
Posts: 2,988
One way would be to use python list comprehensions. This will select brick 1 to 4. (Note that even though it says 1-5, 5 is not included)

Not the most efficient, but it will work.

Code:
python("cmds.select(['brick%s' % n for n in range(1,5)])");
__________________
Imagination is more important than knowledge.
  Reply with quote
29-01-2020, 03:10 PM   #3
AverageRigger
Registered User
 
Join Date: Jan 2020
Posts: 7
So basically you want to run a for-loop x-number of times you want a brick to be selected. F.e. you want to select 50 bricks
$i start , <51 end
for($i=1; $i < 51); $i++)
{
}

inside the loop you check if there is an object with the name "brick"+"current run number"
if there is an object with that name you add it to selection.
if you reach maximum number of loopruns or an object with the name you looking for doesn't exist you end the loop

I am at work and can't look up the syntax at the moment but that's one solution for it basically.

Hope that helps

Last edited by AverageRigger; 29-01-2020 at 03:25 PM.
  Reply with quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Objects move inconsistently when I move multiple MrSandman Maya Technical Issues 5 20-04-2015 08:13 PM
Strange Problem - Unable to change attributes for multiple objects anthonysw3 Maya Technical Issues 4 04-12-2010 11:56 PM
mapping multiple objects in mel bendingiscool Programming 1 19-05-2008 05:33 AM
simple script to select objects leotikansas Programming 2 08-05-2008 09:05 PM
Problems with multiple collision objects Uglynakedguy Maya Technical Issues 1 08-05-2008 01:06 AM