Yea this isn't what you want. It has bugs. Firstly, you seem to be
formatting the number 1 instead of the variable "i" :-)
You can't change the base variable at all. That needs to stay the original
value so that you can use it as the base of building the next name to test.


Here is an updated example of how you could make the padding amount an
optional parameter:
https://gist.github.com/justinfx/e06e8496e535badb20e6b4ec5f0f5f77

Justin

On Thu, Sep 15, 2016 at 9:55 AM likage <dissidia....@gmail.com> wrote:

> I tried to use your case and did an update, and it failed badly...
> Even so, my method was wrong to begin with, i think. It already fails if I
> am trying to do the counter in the middle of the naming
>
> def uniqueNamePattern(base=""):
>
>     i = 1
>     customRepl = base.format('x') != base
>
>
>     if customRepl:
>
>         name = base.format(i)
>
>     else:
>         name = base
>
>
>     while cmds.objExists(name):
>         i += 1
>
>         base = base + "{0:0>3}".format(1)
>         if customRepl:
>             name = base
>             print "name1 : ", name
>         else:
>
>             name = "{0}{1}".format(base, i)
>
>             print "name2 : ", name
>
>
>     return name
>
>
> cmds.group(name=uniqueNamePattern("test_"))
>
> --
> 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/9f1441a6-53ca-43b9-9e7d-c8fc3c27b6e3%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/9f1441a6-53ca-43b9-9e7d-c8fc3c27b6e3%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 python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3KO1-_LZj%2B1dyd42ayvCzVOecaySE9zsJ6GMvJek7pTA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to