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 hidden or 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
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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment