Sumit Banerjee
Sumit Banerjee

Reputation: 31

Get list of reference nodes In Maya using Python API

I just want to list all the reference nodes on the current Autodesk Maya scene file using python API (only), there is this class called MFileIO in C++ API but that to returns the referenced file name not the reference node but there is no such class in Python API.

Please any suggestions regarding this.

Note: I don't want to use MEL or Python commands only through API.

Upvotes: 3

Views: 9007

Answers (1)

mayaknife
mayaknife

Reputation: 302

You can use Maya's 'ls' command to list all of the reference nodes in the scene:

import maya.mel as mm
refNodes = mm.eval('ls -type reference')

'refNodes' will contain an array of reference node names.

If you dislike using Maya commands for some reason, you can do it purely through the API as well:

import maya.api.OpenMaya as om
it = om.MItDependencyNodes(om.MFn.kReference)
refNodes = om.MObjectArray()
while not it.isDone():
    refNodes.append(it.thisNode())
    it.next()

'refNodes' will be an MObjectArray containing the MObjects for all of the reference nodes in the scene.

Upvotes: 1

Related Questions