Created
January 21, 2017 04:20
-
-
Save dgovil/29247cd34277ae4de7244ce5b3464587 to your computer and use it in GitHub Desktop.
Finding what nodes were imported from a Maya file
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
# First lets import our Maya command library | |
from maya import cmds | |
# Then we import our file. In this case I'm using a hardcoded value | |
# But notice the returnNewNodes parameter that tells it to give us back any imported nodes | |
# This may contain nodes we don't want | |
# So we'll need to shorten it down | |
nodes = cmds.file('C:/Users/dhruv/Documents/maya/controllerLibrary/bigdonut.ma', | |
i=True, returnNewNodes=True) | |
# We need to find all the objects that are shapes | |
# We use ls to list the nodes we got, and to make sure we only get the shapes | |
shapes = cmds.ls(nodes, shapes=True, shortNames=True) | |
# We'll have an empty list to get the controllers | |
controllers = [] | |
# Then lets loop through this list | |
for shape in shapes: | |
# We want to ignore any cameras so we check the type | |
if cmds.objectType(shape) == 'camera': | |
# If it's a camera then continue on to the next item | |
continue | |
# Then we need to find the transform. | |
# So we list its' parent to find it | |
parent = cmds.listRelatives(shape, parent=True)[0] | |
# Then we add the parent transform to the controllers list | |
controllers.append(parent) | |
# Finally lets print out the controllers to see if we got it right | |
print controllers |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment