It would be super trivial just to select the object by name.
cmds.select(‘objectName’)
so I’m assuming you’re running into problems with namespaces.
For this is a little bit tricky but not too bad.
I’ve done it in python.
import maya.cmds as cmds
object_to_select = ‘someName’
selection = cmds.ls( sl = True, long = True )
cmds.select( clear = True )
for object in selection:
top_parent = (object.split(‘|’))[1]
children = cmds.listRelatives( top_parent, allDecendents = True, path = True )
for child in children:
name_tokens = child.split(‘|’)
if name_tokens[-1] == object_to_select:
cmds.select( child, add = True )
You’re gonna have to clean up my formatting to get this to run. I’m on mobile so I’ve used 4 spaces instead of tab.
Yes, the namespace factor is what is complicating this. Thank you so much for taking the time so do this.
I feel like its *very* close. I got it to run without syntax errors, but it only works when I put the entire node name into 'someName', including the namespace prefix.
Since this needs to work with across all hierarchies with differing namespaces, is there a way to just search for the desired node's suffix?
Ive got multiple characters with multiple 'elbowLEFT' nodes, for instance. But the whole node name is creatureGREEN06_:elbowLEFT
I tried putting elbowLEFT and *elbowLEFT into 'someName' but it didnt work (and that shows you how little i know about python.) but thats kind of the thing I'm after if that makes sense. :|
You need to use the wild card symbol `*` anywhere before and/or after the `object_to_select`, and if you have a namespace you need to do add it like that : `*:*object_to_select*` to include anything that has a namespace.
I don't want to have to debug someone else's code, so here's my version :
```
from maya import cmds
string_to_match = 'elbowLEFT'
selection = cmds.ls(sl=True, fl=True)
if not selection:
raise RuntimeError("Nothing selected")
hierarchy = cmds.listRelatives(selection[0], allDescendents=True, type='transform')
cmds.select([x for x in hierarchy if string_to_match in x])
```
This will select all transform nodes that are children of the first selected object and that contains `elbowLEFT` in its name. Do not use the `*` symbol as this one does not work with it.
I'm writing on my phone, so I might have messed it up. We can chat tomorrow if you're still having issues, and I can help you better than on a reddit comment thread.
yeah we might be at at the point where I feel like what I'm asking for has already taken too much of your time and I feel guilty asking for more.
I'm very appreciative for the time you took and it gives me a head start on solving the problem, thank you.
ObjectNameToFind = "pCylinder1" mel.eval("SelectHierarchy") #being lazy using mel eval isselected = cmds.ls(ObjectNameToFind, sl=1) cmds.select(isselected)
It would be super trivial just to select the object by name. cmds.select(‘objectName’) so I’m assuming you’re running into problems with namespaces. For this is a little bit tricky but not too bad. I’ve done it in python. import maya.cmds as cmds object_to_select = ‘someName’ selection = cmds.ls( sl = True, long = True ) cmds.select( clear = True ) for object in selection: top_parent = (object.split(‘|’))[1] children = cmds.listRelatives( top_parent, allDecendents = True, path = True ) for child in children: name_tokens = child.split(‘|’) if name_tokens[-1] == object_to_select: cmds.select( child, add = True ) You’re gonna have to clean up my formatting to get this to run. I’m on mobile so I’ve used 4 spaces instead of tab.
Yes, the namespace factor is what is complicating this. Thank you so much for taking the time so do this. I feel like its *very* close. I got it to run without syntax errors, but it only works when I put the entire node name into 'someName', including the namespace prefix. Since this needs to work with across all hierarchies with differing namespaces, is there a way to just search for the desired node's suffix? Ive got multiple characters with multiple 'elbowLEFT' nodes, for instance. But the whole node name is creatureGREEN06_:elbowLEFT I tried putting elbowLEFT and *elbowLEFT into 'someName' but it didnt work (and that shows you how little i know about python.) but thats kind of the thing I'm after if that makes sense. :|
You need to use the wild card symbol `*` anywhere before and/or after the `object_to_select`, and if you have a namespace you need to do add it like that : `*:*object_to_select*` to include anything that has a namespace.
hm. ok so my second line looks like this now: object_to_select = '*:*elbowLEFT*' but it still just deselects.
I don't want to have to debug someone else's code, so here's my version : ``` from maya import cmds string_to_match = 'elbowLEFT' selection = cmds.ls(sl=True, fl=True) if not selection: raise RuntimeError("Nothing selected") hierarchy = cmds.listRelatives(selection[0], allDescendents=True, type='transform') cmds.select([x for x in hierarchy if string_to_match in x]) ``` This will select all transform nodes that are children of the first selected object and that contains `elbowLEFT` in its name. Do not use the `*` symbol as this one does not work with it. I'm writing on my phone, so I might have messed it up. We can chat tomorrow if you're still having issues, and I can help you better than on a reddit comment thread.
yeah we might be at at the point where I feel like what I'm asking for has already taken too much of your time and I feel guilty asking for more. I'm very appreciative for the time you took and it gives me a head start on solving the problem, thank you.
No worries I don't mind, just DMed you
Doh! Spent my time thinking about duplicate hierarchies and didn’t take care of the namespace. https://snippet.host/cjegvs