Hi Alberto!

I tested it out and it works! Thank you so much!! I have a followup 
question: what if the side of the CNTL is a custom input from the user?

I tried this but it only selects the CNTLs with upper case "M"

customSide= "M"

regex = re.compile(r"(.*[%s]_\w*_[cntlCNTL]{4})" %(customSide))


Thanks!

-Francesco

On Thursday, February 21, 2019 at 1:59:47 PM UTC-8, Alberto Sierra Lozano 
wrote:
>
> Hello!!
>
> That is only a showcase of how would I do it.
> Here you have a functional way to do it 
>
> import re
>
> def get_elements_by_criteria():
>     regex = re.compile(r"(.*[lL]_\w*_[cntlCNTL]{4})")
>     all_elements = cmds.ls()
>     matched_elements = list()
>     for element in all_elements:
>         matched = regex.match(element)
>         if matched:
>             matched_elements.append(element)
>             
>     if not matched_elements:
>         raise ValueError("Any element match the criteria")
>         
>     return matched_elements
>
>
> get_elements_by_criteria()
>
>
> It will raise an exception if no elements match the criteria (you can 
> change the raise with the cmds.error, or if you don't want any error, you 
> can just return an empty list)
> Hope it helps!
>
>
> El jueves, 21 de febrero de 2019, 22:44:29 (UTC+1), Francesco escribió:
>>
>> Hi Alberto,
>>
>> Thank you for the quick response! I tried your method but it returns a 
>> lot of None as results, although it might just be me using not correctly, 
>> I'm not super familiar with this.
>> What I wanted is to check if objects with those specified naming 
>> conventions exist, and if so select them, otherwise return the error 
>> message.
>>
>> Cheers!
>>
>> On Thursday, February 21, 2019 at 1:11:35 PM UTC-8, Alberto Sierra Lozano 
>> wrote:
>>>
>>> I was thinking about something like:
>>>
>>> import re
>>>
>>> regex = re.compile(r"(.*[lL]_\w*_[cntlCNTL]{4})")
>>> all_elements = cmds.ls()
>>> for element in all_elements:
>>>     print regex.match(element)
>>>
>>>
>>> Tell me if that works for you!
>>>
>>> Cheers!
>>>
>>> El jueves, 21 de febrero de 2019, 21:17:23 (UTC+1), Francesco escribió:
>>>>
>>>> Hi everybody!
>>>>
>>>> I have a question on whether it's possible to ignore the case 
>>>> sensitivity when checking if something exists. Here's an example:
>>>>
>>>> if cmds.objExists("L_*_CNTL") == False:
>>>>         cmds.error("Error! No left side CNTLs were found!")
>>>>
>>>> Basically I want to check if there are controllers that have the "L" 
>>>> prefix and "CNTL" suffix, but sometimes there might be scenarios where the 
>>>> rigger used different naming conventions, using lower case "l", lower case 
>>>> "cntl" or a mix, like "Cntl".
>>>>
>>>>
>>>> Thanks!
>>>>
>>>> -Francesco
>>>>
>>>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/9e25522c-a281-4d2c-8113-0950b428f72b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to