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 <konstrukt...@gmail.com>
wrote:

> 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
>         preview
> """)
>
> Resulting in this.
>
> [image: Inline images 1]
>
> The idea then is to start making nodes and move them into their home via
> cmds.parent().
>
> But my implementation so far is fairly limited.
>
>    1. Doesn’t take existing nodes into account
>    2. Breaks on empty lines
>    3. Can overall be made more elegant, I think
>
> So my question to you is, how would you write this?
>
> def hierarchy_from_string(hierarchy):
>     parents = {}
>
>     for line in hierarchy.split("\n"):
>         if not line:
>             continue
>
>         name = line.strip()
>         padding = len(line[:-len(name)])
>         parents[padding] = name
>
>         name = cmds.createNode("transform", name=name)
>
>         for parent in sorted(parents):
>             if parent < padding:
>                 cmds.parent(name, parents[parent])
>
> Thanks for chiming in!
> ​
> --
> *Marcus Ottosson*
> konstrukt...@gmail.com
>
> --
> 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 view this discussion on the web visit https://groups.google.com/d/
> msgid/python_inside_maya/CAFRtmODMBoLY%2Bcc_%3DK58NKmaPt0D%3DBKqdwL%2B%
> 3DRFwLLH2j8831A%40mail.gmail.com
> <https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODMBoLY%2Bcc_%3DK58NKmaPt0D%3DBKqdwL%2B%3DRFwLLH2j8831A%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 python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAAjrnHsrd4ZxOKKGS%2B_hE4_wBJNf3fR01x20MFyxDSL2-2dd0A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to