Select objects from a List - python

Select objects from a List - python

danispag
Enthusiast Enthusiast
1,338 Views
4 Replies
Message 1 of 5

Select objects from a List - python

danispag
Enthusiast
Enthusiast

I have a list of 9 objects and I want to select 6 of them (from 'spine1_result_JNT' to 'spine6_result_JNT').

how can I do it?

List of objects is this:

 

spine01_FK_CTRL
spine02_FK_CTRL
spine1_result_JNT
spine2_result_JNT
spine3_result_JNT
spine4_result_JNT
spine5_result_JNT
spine6_result_JNT
spine7_result_JNT 

0 Likes
1,339 Views
4 Replies
Replies (4)
Message 2 of 5

tdHendrix
Collaborator
Collaborator

Something like this should do it:

cmds.select(my_list[2:-1])


Greg Hendrix - Senior Technical Animator
LinkedIn : Twitter
Message 3 of 5

danispag
Enthusiast
Enthusiast

yes that works but if you have something like this that solution doesn't work:

image attached below

0 Likes
Message 4 of 5

tdHendrix
Collaborator
Collaborator

Just to clarify, in the pic you posted, you want it to also select those specific joints in that situation?


Greg Hendrix - Senior Technical Animator
LinkedIn : Twitter
0 Likes
Message 5 of 5

olarn
Advocate
Advocate

Based on name only?

Perhaps something like this? (didnt check the code tho)

import re
sel = [name for name in joint_list if re.match(r"spine[0-9].*_result_JNT", name) ]

 

0 Likes