PyMel select duplicated names

I have a Maya scene with several transform nodes with the same name (and this could not be changed), e.g. “Object_A”.

I need to select objectst:

import pymel.core as pm
list = ['Object_A', 'Object_B']
pm.select(list)

Which results in an error. What workarounds are possible?
If you type Object_A in Status Line “Select by name” the objects would be selected without errors.

Instead of passing an explicit list of strings to pm.select(), list them first using pm.ls()

import pymel.core as pm
objects = pm.ls(['Object_A', 'Object_B'])
# OR
objects = pm.ls('Object_A', 'Object_B')
pm.select(objects)

Edit: Also don’t use “list” as a variable. That will overwrite the list keyword!

1 Like

Nice, thanks, exactly what I was looking for!

And yes, I would not have clashing names in my actual code!

You did post actual code that an actual person ran. :wink: