Reputation: 418
I have a script where the user selects a vertex, and should store the name of the mesh that vertex belongs to.
However I'm unaware of a way to elegantly get that information. It's printed out nice, e.g. pPipe1.vtx[242]
. But getting just the pPipe1 transform node name doesn't seem super straightforward. Would rather not resort to cutting off characters in the string. That seems bad practice.
Upvotes: 0
Views: 1959
Reputation: 2512
for one item :
sel = cmds.ls(sl=True)[0].split('.')[0]
for a list of items :
sel = [i.split('.')[0] for i in cmds.ls(sl=True)]
sel = list(set(sel)) # Use this to remove multiple instance of an object
Upvotes: 1
Reputation: 12218
The ugly way is the easy way - if you string split the vertex entries on period you'll get the transform parents. However you can also pass vertex entries to cmds.ls(o=True)
which strips off attribute and component names and returns only objects:
cmds.select("pCube1.vtx[*]")
sel = cmds.ls(sl=True)
print sel
# [u'pCube1.vtx[0:7]']
obj = cmds.ls(*sel, o=True)
print obj
# [u'pCubeShape1']
Upvotes: 3