Discussion:
[Maya-Python] Check all node types from a given full path
yann19
2018-09-13 20:21:24 UTC
Permalink
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?
--
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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/d12316b3-8bfa-4295-8e8f-f3b2588015e4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Michael Kato
2018-09-13 20:32:10 UTC
Permalink
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!
Post by yann19
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..
node_split = node.split('|')
split_len = len(node_split)
# I need to use +2, if using a +1, a "|" will be returned...
num = num + 2
item = "|" + "|".join(node_split[1:num])
print item
It seems to work for my cause but wondering if there is a better way to
deal with this?
--
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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/59c307ec-ca68-42f0-861e-5b5b20caa890%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
yann19
2018-09-13 21:01:04 UTC
Permalink
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_maya+***@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.
Justin Israel
2018-09-13 21:56:21 UTC
Permalink
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]
Post by yann19
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/cc239786-e3dc-4fc1-8bac-5181846b3274%40googlegroups.com
<https://groups.google.com/d/msgid/python_inside_maya/cc239786-e3dc-4fc1-8bac-5181846b3274%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3oJ_1dQZOtwksgDK18e58OFaSLG%2B_7CmXNFs0CC1-QzA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
yann19
2018-09-13 22:57:18 UTC
Permalink
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
--
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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/22cd722a-e097-4366-9791-f4afa7ab491a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Marcus Ottosson
2018-09-14 06:12:11 UTC
Permalink
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]
Post by yann19
current_object = cmds.listRelatives(path, parent = True, fullPath
= True ) or []
# Set the condition here...
return current_object[0]
current_object = cmds.listRelatives( current_object,
parent = True, fullPath = True )
return None
--
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/22cd722a-e097-4366-9791-f4afa7ab491a%40googlegroups.com
<https://groups.google.com/d/msgid/python_inside_maya/22cd722a-e097-4366-9791-f4afa7ab491a%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAZ7DKTQ5UxpwLU3_KkUJ2%3D%3D%2BFkbLxqd5X0%2BcNmE_js%2BA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Loading...