def fix_shapes():
all_geos = cmds.ls(sl = True)
for geo in all_geos:
shapes = cmds.listRelatives(geo, fullPath=True, shapes=True)
if len(shapes) == 1:
continue
new_listing = []
listing.append(shapes[:1])
# pop out the first shape, since we don't have to fix it
multi_shapes = shapes[1:]
for multi_shape in multi_shapes:
new_transform = cmds.duplicate(multi_shape, parentOnly=True)
new_geos = cmds.parent(multi_shape, new_transform, addObject=True, shape=True)
listing.append(new_geos)
# remove the shape from its original transform
cmds.parent(multi_shape, removeObject=True, shape=True)
# counter to 'version' up new_geos group naming
counter = 0
new_group_name = cmds.group(em=True, name = 'TEST_' + str(counter + 1) + '_GRP')
for item in new_listing:
counter = counter + 1
new_geos_parent_name = cmds.listRelatives(item, parent = True)
cmds.parent(new_geos_parent_name, new_group_name)
counter = 0
for item in listing:
counter = counter + 1
new_geos_parent_name = cmds.listRelatives(item, parent = True)
new_group_name = cmds.group(em = True, name = 'TEST_' + str(counter) + '_GRP')
cmds.parent(new_geos_parent_name, new_group_name)
def uniqueNamePattern(base="object"):
i = 1
customRepl = base.format('x') != base
if customRepl:
name = base.format()
else:
name = base
while cmds.objExists(name):
i += 1
if customRepl:
name = base.format()
else:
name = "{0}{1}".format(base, i)
return name
cmds.group(name=uniqueNamePattern("test_{0}_GRP"))
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/fde473f3-2f99-459c-82dc-f92061d65f4f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Correct me if I am wrong but is that suppose to be the name of object?
Hi, was wondering if you could explain more on 'base='object' as I am not really understanding it... Not to mention about the base.format that you have used.
Correct me if I am wrong but is that suppose to be the name of object?
--
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+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/75146519-887f-492b-89c5-0a3eba98d3b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
@Justin : Might I suggest a minor change to your example function : using the format code in the default argument would make it more readable (especially in absence of any example usage)so the signature becomes:def uniqueNamePattern(base="whatever_{0}_whatever")
This improves readability for `base.format` used later.- Alok
On Tue, Aug 23, 2016 at 2:40 PM, likage <dissid...@gmail.com> wrote:
Hi, was wondering if you could explain more on 'base='object' as I am not really understanding it... Not to mention about the base.format that you have used.
Correct me if I am wrong but is that suppose to be the name of object?
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/75146519-887f-492b-89c5-0a3eba98d3b4%40googlegroups.com.
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPaTLMSwuY%3D6_YeJeF05nz%3Dd7cJ2PEO50eW7FsD2iHgGYzp2-g%40mail.gmail.com.
@alokI guess I could have made the default base use the pattern that likage had specified, but I was really just making it generic and then the usage of it could specify that custom format. Maybe my docstrings clarified the usage though?Justin
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/f45bea80-1f80-4552-a1fc-796efe4ddbae%40googlegroups.com.
On Thu, 8 Sep 2016, 6:54 AM likage <dissid...@gmail.com> wrote:I tried to tweak the code a bit so that it will register version padding - eg. abc_001, abc_002 where in my code I am using something like uniqueNamePattern("abc_{0}{0}{0}")While it seems to work in a sense, I got abc_111, abc_222 instead... Also I tried something like uniqueNamePattern("abc_00{0}")However, say if I have 12 of the same items and as I execute the code, instead of getting abc_010 or abc_011, I got abc_0010, abc_0011Can someone shed some light to me?Your approaches have tried to format either 3 independent counter numbers into the string (the same number 3 times) or uses 2 fixed 0 characters that never changeIf you are using my custom counter suggestion, try updating the format string like thisuniqueNamePattern("abc_{0:0>3}")That says to pad the number with 0, right aligned, with a width of 3
--
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+unsub...@googlegroups.com.
I did not know that I can write it as {0:0>3}! Works like a charm!
On Wednesday, September 7, 2016 at 12:24:56 PM UTC-7, Justin Israel wrote:
On Thu, 8 Sep 2016, 6:54 AM likage <dissid...@gmail.com> wrote:I tried to tweak the code a bit so that it will register version padding - eg. abc_001, abc_002 where in my code I am using something like uniqueNamePattern("abc_{0}{0}{0}")While it seems to work in a sense, I got abc_111, abc_222 instead... Also I tried something like uniqueNamePattern("abc_00{0}")However, say if I have 12 of the same items and as I execute the code, instead of getting abc_010 or abc_011, I got abc_0010, abc_0011Can someone shed some light to me?Your approaches have tried to format either 3 independent counter numbers into the string (the same number 3 times) or uses 2 fixed 0 characters that never changeIf you are using my custom counter suggestion, try updating the format string like thisuniqueNamePattern("abc_{0:0>3}")That says to pad the number with 0, right aligned, with a width of 3
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/f45bea80-1f80-4552-a1fc-796efe4ddbae%40googlegroups.com.
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/b9d86111-fcd6-4f78-910f-84ef12625a5b%40googlegroups.com.
On Thu, Sep 8, 2016 at 10:19 AM likage <dissid...@gmail.com> wrote:I did not know that I can write it as {0:0>3}! Works like a charm!For completeness, the equivalent in using the older string formatting approach would be:"abc_%03d" % numberBut using the format() method is the newer preferred approach.
On Wednesday, September 7, 2016 at 12:24:56 PM UTC-7, Justin Israel wrote:
On Thu, 8 Sep 2016, 6:54 AM likage <dissid...@gmail.com> wrote:I tried to tweak the code a bit so that it will register version padding - eg. abc_001, abc_002 where in my code I am using something like uniqueNamePattern("abc_{0}{0}{0}")While it seems to work in a sense, I got abc_111, abc_222 instead... Also I tried something like uniqueNamePattern("abc_00{0}")However, say if I have 12 of the same items and as I execute the code, instead of getting abc_010 or abc_011, I got abc_0010, abc_0011Can someone shed some light to me?Your approaches have tried to format either 3 independent counter numbers into the string (the same number 3 times) or uses 2 fixed 0 characters that never changeIf you are using my custom counter suggestion, try updating the format string like thisuniqueNamePattern("abc_{0:0>3}")That says to pad the number with 0, right aligned, with a width of 3
--
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+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/f45bea80-1f80-4552-a1fc-796efe4ddbae%40googlegroups.com.
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+unsub...@googlegroups.com.
name = "{0}{1}".format(base, i)
into
name = "{0:<03}".format(i)
But as I tried to use uniqueNamePattern("test_{0}_GRP"), the padding revert back to a single digit unless I change {0} to {0:<03}
I apologize in advance that I have not done much testing before I type this out
Can you post a new version of the code you tried? I have a feeling you are trying to either update the default case but still passing in a customRepl solution (a string with a replacement pattern). Or you are changing the wrong part of the format string.
It should be possible to make the default case be padded to 3 places, if you don't pass in a string with your own pattern. Another approach would be to refactor the function to have a second param for the fill size and default it to 3. Then you would just fill the counter to that padding before formatting it into the base string.
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/08b2f88c-1aa5-4b9c-948a-428081ae8498%40googlegroups.com.
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_m...@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.
why don’t you just add a hash to the name which auto-numerates nodes without name collision?
import maya.cmds as mc
blah = mc.polyCube(n="someBaseName#") # the hash inside the string is legal and will resolve to the next unique int
ah... I am still trying to get my head around this...
--
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+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/1088c21f-6557-4ea2-9904-dda0477ab32e%40googlegroups.com.
why don’t you just add a hash to the name which auto-numerates nodes without name collision?
import maya.cmds as mc blah = mc.polyCube(n="someBaseName#") # the hash inside the string is legal and will resolve to the next unique int
On Mon, Sep 19, 2016 at 3:45 PM, likage <dissid...@gmail.com> wrote:
ah... I am still trying to get my head around this...
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/1088c21f-6557-4ea2-9904-dda0477ab32e%40googlegroups.com.
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CABPXW4g4ZVifT7iZXfF7dXb2440VP%3D49A4-Mpm1QibDVyvGA%2Bg%40mail.gmail.com.