On Sat, Oct 6, 2018, 10:57 AM kiteh <[email protected]> wrote:

> Hi all,
>
> I am trying to filter some controllers from current selections.
> Currently this is the code I had:
> exclude_list = [
>     "main_global_ctrl",
>     "main_globalOffset_ctrl",
>     "main_path_ctrl",
>     "main_start_ctrl"
> ]
>
>
> exclude_ctrls = []
> all_ctrls = cmds.ls(selection=True, long=True)
> for ctrl in all_ctrls:
>     # Remove any of the *:<exclude_ctrls> found
>     if ctrl.endswith(tuple(exclude_list)):
>         exclude_ctrls.append(ctrl)
>
>
> # Remove the specified controllers
> filtered_ctrls = [c for c in all_ctrls if c not in exclude_ctrls]
>
> It would works if within my list of current selections, the naming is
> exactly the same as the ones I have in the `exclude_list`.
> What is the best way that I can make the items in `exclude_list` to work
> as a wildcard, eg. if within my selection I had a `M_main_global_ctrl` (see
> that "M_" is not part of the list)?
>

What kind of wildcard pattern are you after? Prefix? Suffix? Both?
Arbitrary characters in between? I don't really understand the example that
filters twice. Seems you already figured out how to do an endswith() to
filter a list on suffix matches and that sounds like the wildcard approach
you wanted.

In general you can either use fnmatch or regular expressions for arbitrary
wildcard matching:

https://docs.python.org/2/library/fnmatch.html
https://docs.python.org/2/library/re.html


-- 
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/382eb1c5-4350-4942-822d-5f17105528e4%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/382eb1c5-4350-4942-822d-5f17105528e4%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0iXyK8Pax1n5fR%3DjmFFAhzQJE%2B0_vtVKunX4UtgYghMA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to