[Maya-Python] Optimise this: Hierarchy from String

2016-09-14 Thread Marcus Ottosson
Hi all, I’m putting together a minor helper function for establishing a transform hierarchy within Maya but am not yet satisfied with the implementation. It works like this. hierarchy_from_string("""\ rig implementation geometry skeleton interface controls

Re: [Maya-Python] Optimise this: Hierarchy from String

2016-09-15 Thread Eric Thivierge
Isn't this sort of thing what YAML and JSON were created for? Human readable formats that have tools to iterate over hierarchies of data? Eric Thivierge http://www.ethivierge.com On Thu, Sep 15, 2016 at 1:36 AM, Marcus Ottosson wrote: > Hi all, > > I

Re: [Maya-Python] Optimise this: Hierarchy from String

2016-09-15 Thread Justin Israel
On Fri, 16 Sep 2016, 7:15 AM wrote: > Snarky, but thanks for chiming in. > Maybe. Maybe not. It seems to address your 2nd and 3rd points, by asking if you would consider changing the input string format to a style that would give you hierarchy processing for free. > -- > You received this mess

Re: [Maya-Python] Optimise this: Hierarchy from String

2016-09-15 Thread marcus . ottosson
Snarky, but thanks for chiming in. -- 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+unsubscr...@googlegroups.com. To vi

Re: [Maya-Python] Optimise this: Hierarchy from String

2016-09-15 Thread Eric Thivierge
Definitely didn't mean to be snarky. I could have worded it differently sure. I guess I was trying to get more info on why JSON or YAML wouldn't be a solution for you. Eric Thivierge http://www.ethivierge.com On Thu, Sep 15, 2016 at 3:18 PM, Justin Isr

Re: [Maya-Python] Optimise this: Hierarchy from String

2016-09-15 Thread Marcus Ottosson
Fair enough! The resulting function is going into a code example that I’m trying to make as readable as possible. I find the readability of this approach less distracting and less motivated than, say, this. hierarchy_from_json({ "rig": { "implementation": {}, "geometry": {},

Re: [Maya-Python] Optimise this: Hierarchy from String

2016-09-16 Thread Alok Gandhi
IMHO, parsing the string is just a matter of administrative logic and should not be bothered with when focussing on the business logic (which, in this case, is recreating the hierarchy). Sure JSON, YAML, and XML(ugly) are a few options to choose from for parsing the string. In the end, It is just

Re: [Maya-Python] Optimise this: Hierarchy from String

2016-09-16 Thread Alok Gandhi
On second thought, we would NOT like to parse escape characters as maya would complain later: for nodeName, currIndent in ((line.strip(), len(line) - len(line.lstrip())) for line in hierarchy.split("\n")

Re: [Maya-Python] Optimise this: Hierarchy from String

2016-09-16 Thread Marcus Ottosson
Thanks Alok, that's just what I was looking for. I was just about to mention that about the escape characters, a bare `strip()` works to our advantage here. Use of bisect is interesting, I'll have to dig deeper into that. -- You received this message because you are subscribed to the Google Gro

Re: [Maya-Python] Optimise this: Hierarchy from String

2016-09-16 Thread Marcus Ottosson
Ok, Alok, I had a closer look at your example and the bisect module in Python. In my example, a dict replaces bisect. The dict is limited, in that once a parent at the same level as an above parent appears, the above parent vanishes from consideration. But in this case, maybe that works to our

Re: [Maya-Python] Optimise this: Hierarchy from String

2016-09-16 Thread Alok Gandhi
Hi Marcus, My objective was simple, parenting is the main focus and it should be done once and only once for each node in the hierarchy. To achieve this, during each iteration the node should have knowledge about his parent just by knowing its position (indent). I did not want complex processing

Re: [Maya-Python] Optimise this: Hierarchy from String

2016-09-16 Thread Marcus Ottosson
> but then you should do this lookup only once for each node and not iterate through each key and then deep inside it until some condition is reached. To me, that is a bit complex. Ah, yes that is true. I did not think of that. Thanks for pointing that out. As someone who isn't terribly familiar

Re: [Maya-Python] Optimise this: Hierarchy from String

2016-09-16 Thread Alok Gandhi
> How does bisect achieve this if not by traversing each node in turn and returning the first found, like how the dict is being used currently? In all fairness, there is no way, this can be achieved without some sort of iteration. Bisect is efficient because it implements the binary search algorit

Re: [Maya-Python] Optimise this: Hierarchy from String

2016-09-16 Thread Ian Jones
It can be achieved without iteration if you solve the original problem in another way. If the problem originally is: I’m putting together a minor helper function for establishing a transform hierarchy within Maya but am not yet satisfied with the implementation. Then I might suggest something li

Re: [Maya-Python] Optimise this: Hierarchy from String

2016-09-16 Thread Alok Gandhi
Hi Ian, Although your approach is so valid, I was working under the following constraints, most of which were assumptions: 1. Marcus originally presented a single function with a need to reimplement it to achieve a few specific goals as he mentioned. 2. I wanted to keep the signature of the funct

Re: [Maya-Python] Optimise this: Hierarchy from String

2016-09-16 Thread Marcus Ottosson
Thanks Ian! Some notes. - The implementation is up for grabs, but I'd like to keep the interface of the function; that is, passing a single string with indentation for hierarchy. - Performance is not important here, because (1) the function is only being used in example code, where the call itsel

Re: [Maya-Python] Optimise this: Hierarchy from String

2016-09-16 Thread Alok Gandhi
Ah ok, just saw Marcus's answer, so most of my assumptions were correct. I would still say, there are many ways to achieve the same thing in programming. With the kind of flexibility, that python provides, the 'many ways' becomes 'so many ways'. Coming back to some of the points that Ian raised:

Re: [Maya-Python] Optimise this: Hierarchy from String

2016-09-16 Thread Justin Israel
On Sat, Sep 17, 2016 at 5:27 AM Alok Gandhi wrote: > > Coming back to some of the points that Ian raised: > > Readability is a perfectly valid goal to seek but I > find maintainability is often overlooked. > > IMHO more readable code is more maintainable. Readability goes hand in > hand with

Re: [Maya-Python] Optimise this: Hierarchy from String

2016-09-16 Thread yury nedelin
Is performance something you are concerned with for this process? Yury On Sep 16, 2016 6:16 PM, "Justin Israel" wrote: > > > On Sat, Sep 17, 2016 at 5:27 AM Alok Gandhi > wrote: > >> >> Coming back to some of the points that Ian raised: >> > Readability is a perfectly valid goal to seek but

Re: [Maya-Python] Optimise this: Hierarchy from String

2016-09-16 Thread Justin Israel
On Sat, 17 Sep 2016, 1:09 PM yury nedelin wrote: > Is performance something you are concerned with for this process? > Yury > Marcus had said it was not a concern. I was just sharing some interesting info on the topic of readability and maintainability > On Sep 16, 2016 6:16 PM, "Justin Israel"

Re: [Maya-Python] Optimise this: Hierarchy from String

2016-09-16 Thread Alok Gandhi
@Justin: I agree with readability trumping performance, and almost at all times, I follow almost the same tenets. However, in our trade, performance is ever more critical and is becoming important every single day. The entertainment industry is one of the major stakeholders when it comes to demand

Re: [Maya-Python] Optimise this: Hierarchy from String

2016-09-16 Thread Justin Israel
On Sat, Sep 17, 2016 at 5:34 PM Alok Gandhi wrote: > @Justin: I agree with readability trumping performance, and almost at all > times, I follow almost the same tenets. However, in our trade, performance > is ever more critical and is becoming important every single day. The > entertainment indus

Re: [Maya-Python] Optimise this: Hierarchy from String

2016-09-16 Thread Alok Gandhi
> > Also I would like to throw my 2 cents in as someone that develops not as > one that writes scripts and tools on a per-show basis to get shots finaled, > but as one that works on longer term projects to serve the ongoing > pipeline. The advise from that conference might be more applicable to > s

Re: [Maya-Python] Optimise this: Hierarchy from String

2016-09-16 Thread Justin Israel
On Sat, 17 Sep 2016, 6:12 PM Alok Gandhi wrote: > Also I would like to throw my 2 cents in as someone that develops not as >> one that writes scripts and tools on a per-show basis to get shots finaled, >> but as one that works on longer term projects to serve the ongoing >> pipeline. The advise f

Re: [Maya-Python] Optimise this: Hierarchy from String

2016-09-18 Thread Geordie Martinez
Okay. I know this has probably already been figured out, but I can’t help myself with puzzles. Marcus I think you were on to the right idea but just needed to use an OrderedDict with enumerate. here is my stab at it: import maya.cmds as mcfrom collections import OrderedDictdef hierarchy_from_strin