Here is a little tip about itertools.chain... If you already have an
iterable of sequences (the values of a dict being a list of verts), you can
use chain.from_iterable()

d['a'] = range(5)
d['b'] = range(5)
d['c'] = range(5)
chained = chain.from_iterable(d.itervalues())

The benefit is that you don't have to expand out all of your lists in
temporary memory, if you have a lot or large lists. You are just passing in
generators, and chain won't have to expand every list if you don't iterate
the whole thing.

When you do this: chain( *connectedVertGroups.values() )
You are first building out a list of lists, and then expanding them into
args to pass to chain()




On Thu, Oct 9, 2014 at 7:07 AM, <[email protected]> wrote:

> so something kinda like this, except I'm getting an error:  "MeshVertex"
> object has no attribute append, as I'm not quite sure how to do that bit.
>
>
> import pymel.core as pm
>
> sel = pm.ls(sl=1, fl=True)
>
> connectedVertGroups = {}
> vertGroups = {}
> for i, vtx in enumerate(sel):
>
>     vtxKey = next((key for key, vtx_list in
> connectedVertGroups.iteritems() if vtx in vtx_list), None)
>     connectedVerts = [ vert for vert in vtx.connectedVertices() ]
>     connectedVerts.append(vtx)
>
>     if vtxKey is None:
>         connectedVertGroups["group_{0}".format(i)] = connectedVerts
>         vertGroups["group_{0}".format(i)] = vtx
>
>     else:
>         connectedVertGroups[vtxKey] = connectedVertGroups[vtxKey].append(
> connectedVerts )
>         vertGroups[vtxKey] = vertGroups[vtxKey].append( vtx )
>
> --
> 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/239e371c-bfef-4fe0-afcb-9880c64f639f%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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1T5oQn6wGO9wpzm-hSD9-FV-GVd_r23Ee5Jz%2BojqLZxA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to