[MAYA-PYTHON] Return input nodes of selected object



Hi, I am writing a script which allows the user edit the basic parameters of the basic INPUT of an object selected in the scene, in my case a polyPipe node created by myself in another script and with a custom attribute, and I want give the user the possibility to change it’s radius through a slider.

Obviously the INPUT polyPipe must exists in history, but how can I access that?

the cmds.polyPipe in edit mode works with a string like that:

cmds.polyPipe(objectSelected, edit = True, r= value)

where objectSelected must have this format:

[u’pPipe1’, u’polyPipe1’]

But how can I access the polyPipe string of a selected object in the scene?

I managed to iterate all the connections until reaching it, but the user could also change it’s name, and in that case my code wouldn’t work.

Any ideas? Thanks!


Something like this maybe?

def get_nodes_in_history_by_type(typ):
    selection = cmds.ls(sl=True)
    nodes = []
    for obj in selection:
        for node in cmds.listHistory(obj):
            if cmds.nodeType(node) == typ:
    return nodes

You’d get the polyPipe nodes by calling get_nodes_in_history_by_type('polyPipe') at which point you could edit them with cmds.polyPipe.


That’s awesome, thank you!