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*
[email protected]
--
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/CAFRtmODMBoLY%2Bcc_%3DK58NKmaPt0D%3DBKqdwL%2B%3DRFwLLH2j8831A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.