"One of the reasons that I like to use PyMel is that when you create an
object you get a reference to that object and you are not dependent of the
name when you want to find the object."

Yes, I agree. Well, in this case, you are dependent on the name. Or you
cause a bug. :)

Also I couldn't resist writing this as list comprehensions. Doing it this
way stores your locators as a list of objects that you can reference even
after your range(10) is complete.

locators = [pm.spaceLocator(n='test#') for x in range(10)]
groups = [pm.group(loc, n='group#') for loc in locators]

By the way, zfill() is a nice way to give number padding when making a
numbered naming convention. This would make test_000, test_001, test_002,
etc. ...But this will still cause a nodeError if you don't have unique
names:

locators = [pm.spaceLocator(n='test_{0}'.format(str(x).zfill(3))) for x in
range(10)]
groups = [pm.group(loc, n='group#') for loc in locators]



On Thu, Mar 5, 2015 at 8:22 PM, johan Borgström <[email protected]> wrote:

> Thanks Geordie!
>
> I did not know that, I agree with Marcus really nice one :)
>
>
> On Thursday, March 5, 2015 at 8:13:08 PM UTC+1, Geordie Martinez wrote:
>>
>> Another approach is to at the "#" into your naming schema. this will
>> increment to the next unique number for that name.
>> then the name will not have a collision with other objects in your scene
>>
>> for x in range(10):
>>     grp = pm.group(em=True)
>>     t = pm.spaceLocator(n='*test#*')  # add the pound symbol to get next 
>> unique number.
>>     pm.parent(t, grp)
>>
>>
>>
>> On Thu, Mar 5, 2015 at 10:52 AM, Chris Lesage <[email protected]>
>> wrote:
>>
>>> Oh sorry, that was your workaround. :)
>>>
>>> On Thu, Mar 5, 2015 at 7:51 PM, Chris Lesage <[email protected]>
>>> wrote:
>>>
>>>> It's because when there are more than one nodes that have the same
>>>> non-unique name, Maya sees them as this:
>>>>
>>>> |group1|test
>>>> |group2|test
>>>> |group3|test
>>>>
>>>> So it can't find "test" anymore. Even though you are casting it as a
>>>> variable, there is some bug. This bug only seems to occur for locators.
>>>>
>>>> Is there a reason you aren't using unique names?
>>>>
>>>> If you do need non-unique names, then this works: Rename the locator
>>>> after creation.
>>>>
>>>> for x in range(10):
>>>> grp = pm.group(em=True)
>>>> t = pm.spaceLocator()
>>>> pm.rename(t, 'test')
>>>> pm.parent(t, grp)
>>>>
>>>>
>>>> On Thu, Mar 5, 2015 at 6:37 PM, Marcus Ottosson <[email protected]>
>>>> wrote:
>>>>
>>>>> I had a good look at this, and it looks to be quite the interesting
>>>>> quirk. :)
>>>>>
>>>>> Here’s the same problem in maya.cmds.
>>>>>
>>>>> from maya import cmds
>>>>> for x in range(2):
>>>>>     grp = cmds.group(em=True)
>>>>>     t = cmds.polySphere(n='test')[0]
>>>>>     assert isinstance(grp, unicode)
>>>>>     assert isinstance(t, unicode)
>>>>>     cmds.parent(t, grp)
>>>>>
>>>>> Merely replacing polySphere with spaceLocator causes the error for me
>>>>> in Maya 2015, and I have no idea why.
>>>>>
>>>>> Good find!
>>>>> ​
>>>>>
>>>>> --
>>>>> 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/CAFRtmODHPmSgwZkj-uh8%
>>>>> 3DswwjnZjL9jR8wXXu0EvsEbXRXwp9Q%40mail.gmail.com
>>>>> <https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODHPmSgwZkj-uh8%3DswwjnZjL9jR8wXXu0EvsEbXRXwp9Q%40mail.gmail.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/CAHUba0KynD8USgVOKg6ohOx8c7EA0
>>> WXfHccDRt%3Dd5kgWbLY0%2Bg%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/python_inside_maya/CAHUba0KynD8USgVOKg6ohOx8c7EA0WXfHccDRt%3Dd5kgWbLY0%2Bg%40mail.gmail.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/7d8478c4-33e5-4e5b-a93d-013c0a245bcc%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/7d8478c4-33e5-4e5b-a93d-013c0a245bcc%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/CAHUba0LMPxZTMh78dh8-NJt%3DOARh4BiUtDjPz%2Bs3_rWpUGbv4g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to