I ran into this just now and it’s confusing to say the least.
Run the following script in a new Rhino file with nothing in it.
import rhinoscriptsyntax as rs
for i in range(5):
gn="Itemnumber {}".format(i)
group_name=rs.AddGroup(gn)
print group_name
The first time you run it, no problem, you will get this:
Item number 1
Item number 2
Item number 3
Item number 4
Item number 5
Run it however a second time and you will get this:
Item number01
Item number02
Item number03
Item number04
Item number05
Run it a third time and you get this:
Item number06
Item number07
Item number08
Item number09
Item number10
etc.
Funny thing is that I have not added anything to these groups, so running SelGroup shows a blank dialog. I guess that’s sorta normal though…
And why on earth did it take my “Item number” text, strip the original number and then start adding numbers to the end? It should, by default, just automatically give me Group 01, Group 02, etc. My feeling is that the algorithm behind the default numbering is getting confused, it finds an already used name but it isn’t looking for a “Group nn” format, it simply finds a name with a number at the end, says Eureka!, strips that number off and adds a new number.
What it should do:
First run OK
Second run:
Item number 1 01
Item number 2 01
Item number 3 01
Item number 4 01
Item number 5 01
Third run:
Item number 1 02
Item number 2 02
Item number 3 02
Item number 4 02
Item number 5 02
etc.
Worst is it also strips out the space so even if it was working correctly it might result in this:
Item number 102
Item number 202
Item number 302
Item number 402
Item number 502
Which could be REALLY confusing.
OK, lesson learned, I need to check for the existence of a group name before adding a new group with that name. Plus for now I will not number groups with the number at the end of the name. And maybe even run a routine to clear all empty groups before starting.
Note that the following “workarounds” fail with the same problem:
gn="Panel number {}.".format(i)
gn="Panel number {},".format(i)
gn="Panel number {}-".format(i)
It’s still trying to resolve a number and “,” or “.” can be a decimal, I guess. I was surprised that the “-” was considered as well, but not “+”.
But any other character after the number seems to make it behave correctly:
gn="Panel number {}|".format(i)
gn="Panel number {}!".format(i)
gn="Panel number {}#".format(i)
gn="Panel number {}*".format(i)
etc.
Just a heads-up if anyone is interested in using or fixing this…