[Python][Maya] Connections method does not work on Reference Objects?

Hi,

I’m trying to get the skinCluster of a selected object.
The code works. However, if the selected object is a reference object, the code will not output the relevant skinCluster

The skinCluster was not made in the reference file itself but in the file it was referenced in.

You can check the illustration video here (12 sec)

Here is the code so far:

import pymel.core as pm

obj = pm.ls(sl=True)[0].getShape()

skinClusterNode = None
for node in obj.connections():
    print node.nodeType()

    if node.nodeType() == 'skinCluster':
        skinClusterNode = node
        #print skinClusterNode

Thank you

Check the node editor for the input history of both nodes. My guess is that the one it is failing on is not directly connected to the skincluster but has a node inbetween. This could be another intermediate shape node for example.

If that’s the case and you want to find skinclusters further upstream you could either recursively go over the input connections or instead just use history instead.

Note that with further recursion you could get a skincluster that is used for a mesh in a blendshape too. Likely not what you’d want. Likely you want the closest in history that is a skincluster so you could break the iterations there.

Does this help?

1 Like

For exact querying of nodes like this I’d avoid PyMel and drop back to cmds - listConnections() and listHistory() each give you more control over traversal order and filtering of connections. At a push connectionInfo() can also let you track it plug by plug, but that’s a bit beyond what you usually want.
[i for i in cmds.listHistory(shape) if cmds.nodeType(i) == "skinCluster"]
should get you most of the way there, and will give a consistent ordering of the returned deformers.

1 Like

You are right @BigRoyNL. There is an intermediary shape node on the reference object. Once I properly retrieved that, I got the skinCluster but for the solution I went with @EdArt proposal.

For convenience, since the cmds code works for both reference and non-reference object.

Thanks for the responses. Have a great day ahead!