How to store and then retreive parent-child dependency data (Maya MEL/Python script) -


i have hierarchy need to:

  1. break apart
  2. dosomething()
  3. put same way before.

i know how break things sure, , have plan need when flat in hierarchy. problem how parent them back?


details

this related previous question:

freeze scale transform on parent object animated child (maya mel/python script)

i need freeze scale transforms on nodes in hierarchy. problem nodes have translate animations on them, , if try freeze scale on parent node, it's child animation gets weird. looks there solution, need implementation of it. want to:

  1. group each object
  2. parent each group world
  3. bake animation world space (getting rid of group node)
  4. freeze scale transform
  5. re parent them back

it works when manually, should ok. if think there better way achieve main goal, please tell me.

so, i've been thinking write nodes string , call them there, don't know how handle branches. example: if branchless hierarchy (one parent , 1 child along) call them two, , parent easily. branches make names in string go "parent, child, child, child, parent..."

probably i'm thinking , in wrong direction. ideas?

i suggest using python if aren't - can use pretty data types each other need in single data structure. make easier creating long string , breaking again later.

to collect hierarchy data:

import maya.cmds mc  def hierarchytree(parent, tree):     children = mc.listrelatives(parent, c=true, type='transform')     if children:         tree[parent] = (children, {})         child in children:             hierarchytree(child, tree[parent][1])  top_node = 'name_of_node'  # use mc.ls(sl=true)[0] if want... hierarchy_tree = {} hierarchytree(top_node, hierarchy_tree) 

this should start top node , recursively go down hierarchy create data structure that's nested dicts... each key parent node it's key value being tuple stores list of children , dict of children data. each child dict follows same format - child key it's child data in tuple, etc, etc, etc end of hierarchy. i'm using tuple list , dict since dicts unordered... list ensure re-parent them in same order came from, store dict if don't care retaining order...

to parent back, you'll this:

def reparent(tree):     parent, data in tree.iteritems():         children, child_tree = data         mc.parent(children, parent)         reparent(child_tree)  reparent(hierarchy_tree) 

now... haven't tested code - kind of wrote on fly without bringing maya. i'm more concerned errors popping in re-parent function, may need try/except in there, it'll skip empty dict items , close need in-parenting/re-parenting. assuming of nodes have unique short names...

oh, note recursive functions... make sure they'll terminate @ point or else can stuck in infinite loop (this should fine since we're tracing hierarchy has definite end - ie: no more child nodes)


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -