Check all node types from a given full path

24 views
Skip to first unread message

yann19

unread,
Sep 13, 2018, 4:21:24 PM9/13/18
to Python Programming for Autodesk Maya
Hi all,

What is the best way that I can break apart and check all the nodes within a given node's full path?
I am trying to check the list of nodes within the path, and should the node/path fulfills a certain node type, it will stop iterating and store that selection..

So far I have tried the following:
for node in set(selections):
    node_split = node.split('|')
    split_len = len(node_split)
    for num in range(split_len):
        # I need to use +2, if using a +1,  a "|" will be returned...
        num = num + 2
        item = "|" + "|".join(node_split[1:num])
        if cmds.nodeType(item) == "customType":
            print item

It seems to work for my cause but wondering if there is a better way to deal with this?



Michael Kato

unread,
Sep 13, 2018, 4:32:11 PM9/13/18
to Python Programming for Autodesk Maya
For this my preference would be using PyMel doing something like this

import pymel.core as pm
selections = pm.ls(sl=True)
for node in set(selections):
    allParents = node.getAllParents()
    print allParents

Hope that helps!

yann19

unread,
Sep 13, 2018, 5:01:05 PM9/13/18
to Python Programming for Autodesk Maya
Possible to do it not without the use of pymel?

Justin Israel

unread,
Sep 13, 2018, 5:56:37 PM9/13/18
to python_in...@googlegroups.com
Assuming your selections list are proper full paths, what about something like this:

selections = [
'|path|to|my|node',
]

for node in set(selections):
item = node
while item:
print item
item = item.rsplit('|', 1)[0]


On Fri, Sep 14, 2018 at 9:01 AM yann19 <yang...@gmail.com> wrote:
Possible to do it not without the use of pymel?

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/cc239786-e3dc-4fc1-8bac-5181846b3274%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

yann19

unread,
Sep 13, 2018, 6:57:19 PM9/13/18
to Python Programming for Autodesk Maya
Thank you all, I chanced upon a method and compiled the following code:

def node_type_iteration(path_lists):
    for path in set(path_lists):
        current_object = cmds.listRelatives(path, parent = True, fullPath = True ) or []
        while current_object:
            # Set the condition here...
            if cmds.nodeType(current_object[0]) == "customType":
                return current_object[0]
            else:
                current_object = cmds.listRelatives( current_object, parent = True, fullPath = True )
        return None


Marcus Ottosson

unread,
Sep 14, 2018, 2:12:27 AM9/14/18
to python_in...@googlegroups.com

If I understand the goal, then something like this might work.

from maya import cmds
cmds.listRelatives("|group1", type="nurbsCurve", allDescendents=True)

If there’s a nurbsCurve on any path starting with |group1, then this would return it.

Test scene

cmds.file(new=True, force=True)
circle = cmds.circle()
cube = cmds.polyCube()
cmds.select(circle + cube)
group = cmds.group()

found = cmds.listRelatives(group, type="nurbsCurve", allDescendents=True)
assert found[0] == cmds.listRelatives(circle[0], shapes=True)[0]

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages