You are seeing this output because there is no correlation between your
"all_grp" and "all_loc" lists. But you zip them together as if they are
related. One is a list of groups under the named group. The other is a list
of all the parents of all the locators in your seen. There is no
correlation in the order of these two.

Maybe what you want is to search the hierarchy of each subgroup?

import maya.cmds as cmds

all_grp = cmds.listRelatives("group", path=True)
# Map from group to its locator decendants
mapping = {}
for grp in all_grp:
    shapes = cmds.listRelatives(grp, ad=True, type="locator")
    locs = cmds.listRelatives(shapes, parent=True)
    mapping[grp] = locs
for grp, locs in mapping.iteritems():
    print "grp - {0}, locs - {1}".format(grp, locs)

​

Justin

On Fri, Sep 9, 2016 at 10:43 AM yann19 <[email protected]> wrote:

>
> I am doing a dry-run test of my code and bump into an issue...
> Please see my screenshot for my very simple hierarchy as I am trying to do
> renaming.
>
>
> <https://lh3.googleusercontent.com/-DTj1Gk7sU1A/V9HpRqBELWI/AAAAAAAAB2o/nl9mbnySHbocUO0s5jbbWQr93qktbRDrwCLcB/s1600/hie_test_run.jpg>
>
>
> This is my code:
> import maya.cmds as cmds
> all_grp = []
> for child_grp in cmds.listRelatives("group", path=True):
>     print child_grp
>     all_grp.append(child_grp)
>
>
> all_loc = cmds.listRelatives(cmds.ls(type='locator'), parent = True)
>
>
> for grp, loc in zip(all_grp, all_loc):
>     print "grp - {0}, loc - {1}".format(grp, loc)
>
>
> What I am expecting to see:
> # Correct
> grp - sub_group1, loc - locator1
> grp - sub_group3, loc - locator3
> grp - sub_group2, loc - locator2
>
>
> But my dry-run result says otherwise:
> # Wrong
> grp - sub_group1, loc - locator1
> *grp *
> *- sub_group3, loc - locator2grp - sub_group2, loc - locator3*
>
>
> Notice that in both sub_group3 and sub_group2, I am expecting the loc to
> be grabbing locator3 instead of locator2 (for sub_group3)
> How do I iterate such that 'loc' will checks if it belongs within the
> hierarchy of 'grp'?
>
> I am trying to achieve something like this:
> If loc belongs in this grp, then do this processA...
> if loc does not belong in that grp, loop thru the grp list to find its
> 'parent/grp' then do processA..
>
> --
> 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/0aa2d366-f162-4962-a509-ab7f787f9ac4%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/0aa2d366-f162-4962-a509-ab7f787f9ac4%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/CAPGFgA20R2mnxtsq2gcVuHiO%3DmyR5e1_Xbu4hC%2Bzm%2BnCBOdNuw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to