Last active
September 20, 2016 09:48
-
-
Save patwooky/eac4f54200b88badda1d9d6c6998dd84 to your computer and use it in GitHub Desktop.
nodes that are the highest level amongst the selected objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Written by Patrick Woo | |
# [email protected] | |
from pymel.core import * | |
import random | |
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 - <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 | |
''' | |
if scrambleOrder: | |
random.shuffle(objsList) | |
topLevelChildren = [] | |
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 objsList: | |
topLevelChildren.append(node) | |
continue | |
if tmpParent[0] not in refChildren: | |
# print node,'is the highest in referenced objects' | |
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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment