Re: [Maya-Python] Re: Dictionary help

2014-10-14 Thread Justin Israel
On Wed, Oct 15, 2014 at 3:16 PM, flaye wrote: > > > Solved it: > > Tried initially > self.dHandles[limbName]=allHandles > > but the dictionary kept returning only one value list. > > Tried also > self.dHandles[limbName].append(allHandles) > > with the same result. > > Finally, got this to work li

[Maya-Python] Re: Dictionary help

2014-10-14 Thread flaye
Solved it: Tried initially self.dHandles[limbName]=allHandles but the dictionary kept returning only one value list. Tried also self.dHandles[limbName].append(allHandles) with the same result. Finally, got this to work like a charm: self.dHandles.setdefault(limbName,[]).append(allHandle

Re: [Maya-Python] Re: dictionary help

2014-10-09 Thread Justin Israel
Fo' sho' Anytime you see a for/while loop in there with many inner PyMel calls, it probably could benefit from testing a cmds or api variation wow, that's quite a bit faster. Thanks for this! I didn't anticipate that much of an increase. Guess it's time to start using cmds more often. Kev -- Yo

Re: [Maya-Python] Re: dictionary help

2014-10-09 Thread kevcortez99
wow, that's quite a bit faster. Thanks for this! I didn't anticipate that much of an increase. Guess it's time to start using cmds more often. Kev -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from thi

Re: [Maya-Python] Re: dictionary help

2014-10-09 Thread Justin Israel
I threw together a cmds version of this code (but someone please confirm my results. Maybe I did this wrong). I didn't really do anything to the actual logic, other than switching from PyMel to cmds, and I also switched to using a set, for an extra bit of performance increase, since the loop is doi

Re: [Maya-Python] Re: dictionary help

2014-10-09 Thread kevcortez99
Hey Jack, I noticed that yesterday when playing around with it a bit. In certain cases, it would give me some extra groups, depending on how I selected the verts. It makes sense. I'm gonna have to pick apart your code to understand it a bit better. I had a feeling this stuff was gonna be fair

Re: [Maya-Python] Re: dictionary help

2014-10-09 Thread Marcus Ottosson
This is pretty slow in python for big selections as it runs in polynomial time, it might be more useful as a command C++ plugin. I bet this will see a substantial performance increase if done using maya.cmds. Iterating over large sets isn’t a task well suited for PyMEL. ​ On 9 October 2014 18:22,

Re: [Maya-Python] Re: dictionary help

2014-10-09 Thread Jack Straw
I now understand what you are trying to achieve. You want to group selections of vertices that are connected. The approach you were using had the caveat that you would need to select the verts in connected order otherwise it was possible to have orphaned ones that should be grouped (I fixed your c

Re: [Maya-Python] Re: dictionary help

2014-10-08 Thread Justin Israel
On Thu, Oct 9, 2014 at 8:45 AM, wrote: > Ah-ha. I was appending a list to the list of connectedVerts. > > I still need to test it a bit, but I think this gets me what I'm after. > Thanks guys for holding my hand through it. > > btw, how are you guys nicely formatting your code? are there no > t

[Maya-Python] Re: dictionary help

2014-10-08 Thread kevcortez99
Ah-ha. I was appending a list to the list of connectedVerts. I still need to test it a bit, but I think this gets me what I'm after. Thanks guys for holding my hand through it. btw, how are you guys nicely formatting your code? are there no tags? #= import py

Re: [Maya-Python] Re: dictionary help

2014-10-08 Thread kevcortez99
Thx Justin, I'm gonna have to think about that one for a while. I can't say I fully understand what chain does. All I know is that sometimes, when I have nested lists or what not, it works for me. haha. I guess it's time to get smarter. You can laugh ;) Cheers! -- You received this message

[Maya-Python] Re: dictionary help

2014-10-08 Thread kevcortez99
okay, I think I get it, get the value of the key, append the vtx to the list, then set that list as the value for the key. And from the looks of it, it seems as though everything should work now. So why doesn't it work :( #== import pymel.core as pm sel = pm.ls(sl=

Re: [Maya-Python] Re: dictionary help

2014-10-08 Thread Justin Israel
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 do

Re: [Maya-Python] Re: dictionary help

2014-10-08 Thread kevcortez99
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((k

Re: [Maya-Python] Re: dictionary help

2014-10-08 Thread kevcortez99
okay, now we're getting somewhere ;) I feel so useless, but this is really helping me understand dictionaries. I was figuring those loops could be reduced. I'll admit I'm kinda lost now in the code. It seems that "vtxKey" is returning a vertex, and not the dictionary key. What i'll need to d

Re: [Maya-Python] Re: dictionary help

2014-10-08 Thread Jack Straw
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) if vtxKey is None: connectedVerts = [ vert for vert in vtx.co

Re: [Maya-Python] Re: dictionary help

2014-10-08 Thread Marcus Ottosson
How about a loop? awesome_verts = list()for name, group in connectedVertGroups.iteritems(): for vertex in group: if vertex is 'Awesome': awesome_verts.append(vertex) ​ On 8 October 2014 17:56, wrote: > Hi jack, thx for helping me. > > I think this works for me: > > v

[Maya-Python] Re: dictionary help

2014-10-08 Thread kevcortez99
Hi jack, thx for helping me. I think this works for me: vtxKey = next((key for key, value in connectedVertGroups.iteritems() if value == vtx), None) The only problem I'm having is that my dictionary values are a list of vertices, and I need to check for a vertex within those lists. Do you hav

[Maya-Python] Re: dictionary help

2014-10-08 Thread Jack Straw
This is how I generally go about searching the values in a dict; my_key = next((key for key, value in dict.iteritems() if value == 'what im testing against'), None) my_key will be None if the condition is never True. On Wednesday, 8 October 2014 15:14:40 UTC+1, kevco...@gmail.com wrote: > > He