Skip to content

Instantly share code, notes, and snippets.

@patwooky
Last active September 20, 2016 09:48

Revisions

  1. patwooky revised this gist Sep 20, 2016. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions highestObjInHierarchy_v01_002_20160917.py
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    # Written by Patrick Woo
    # patrickwoo@yahoo.com

    from pymel.core import *
    import random

  2. patwooky revised this gist Sep 17, 2016. No changes.
  3. patwooky revised this gist Sep 17, 2016. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions highestObjInHierarchy_v01_002_20160917.py
    Original file line number Diff line number Diff line change
    @@ -11,12 +11,12 @@ def highestObjInHierarchy(objsList=[], scrambleOrder=False):
    scrambleOrder - <bool> if True, will shuffle the order of the incoming list. this feature
    is more to test that my this function works by reordering incoming items in a random manner
    False by default.
    return - <list> the nodes that are the highest level of the selected objects
    '''
    if scrambleOrder:
    random.shuffle(objsList)
    topLevelRefChildren = []
    topLevelChildren = []
    if not objsList:
    print 'highestObjInHierarchy: nothing in list'
    return []
    @@ -26,14 +26,14 @@ def highestObjInHierarchy(objsList=[], scrambleOrder=False):
    # print 'tmpParent is', tmpParent
    if tmpParent == []:
    # print node,'is the highest in referenced objects. breaking out of for loop'
    if node not in topLevelRefChildren:
    topLevelRefChildren.append(node)
    if node not in objsList:
    topLevelChildren.append(node)
    continue
    if tmpParent[0] not in refChildren:
    # print node,'is the highest in referenced objects'
    if node not in topLevelRefChildren:
    topLevelRefChildren.append(node)
    return topLevelRefChildren
    if node not in topLevelChildren:
    topLevelChildren.append(node)
    return topLevelChildren

    # print highestObjInHierarchy([x for x in ls(type='reference')[0].referenceFile().nodes() if 'transform' in nodeType(x, i=True)])
    print highestObjInHierarchy(ls(sl=True))
  4. patwooky revised this gist Sep 17, 2016. 1 changed file with 8 additions and 4 deletions.
    12 changes: 8 additions & 4 deletions highestObjInHierarchy_v01_002_20160917.py
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,21 @@
    from pymel.core import *
    import random

    def highestObjInHierarchy(objsList=[]):
    def highestObjInHierarchy(objsList=[], scrambleOrder=False):
    '''
    This function returns nodes at the highest level within the pass-in list of objects.
    This is accomplished by searching upwards through all selected nodes
    to find the nodes that have parents that are not within the selection.
    objsList - a list of maya nodes. must be DAG nodes that belong to the scene hierarchy
    objsList - <list> a list of maya nodes. must be DAG nodes that belong to the scene hierarchy
    scrambleOrder - <bool> if True, will shuffle the order of the incoming list. this feature
    is more to test that my this function works by reordering incoming items in a random manner
    False by default.
    return - <list> the nodes that are the highest level of the selected objects
    '''
    random.shuffle(objsList)
    if scrambleOrder:
    random.shuffle(objsList)
    topLevelRefChildren = []
    if not objsList:
    print 'highestObjInHierarchy: nothing in list'
  5. patwooky created this gist Sep 16, 2016.
    35 changes: 35 additions & 0 deletions highestObjInHierarchy_v01_002_20160917.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    from pymel.core import *
    import random

    def highestObjInHierarchy(objsList=[]):
    '''
    This function returns nodes at the highest level within the pass-in list of objects.
    This is accomplished by searching upwards through all selected nodes
    to find the nodes that have parents that are not within the selection.
    objsList - a list of maya nodes. must be DAG nodes that belong to the scene hierarchy
    return - <list> the nodes that are the highest level of the selected objects
    '''
    random.shuffle(objsList)
    topLevelRefChildren = []
    if not objsList:
    print 'highestObjInHierarchy: nothing in list'
    return []
    for node in objsList:
    # print 'node is',node
    tmpParent = [x for x in listRelatives(node,p=True)]
    # print 'tmpParent is', tmpParent
    if tmpParent == []:
    # print node,'is the highest in referenced objects. breaking out of for loop'
    if node not in topLevelRefChildren:
    topLevelRefChildren.append(node)
    continue
    if tmpParent[0] not in refChildren:
    # print node,'is the highest in referenced objects'
    if node not in topLevelRefChildren:
    topLevelRefChildren.append(node)
    return topLevelRefChildren

    # print highestObjInHierarchy([x for x in ls(type='reference')[0].referenceFile().nodes() if 'transform' in nodeType(x, i=True)])
    print highestObjInHierarchy(ls(sl=True))