1

Is there a way to see if an object exists in Maya, but only search for a partial object name?

Example, search for an object that starts with object, but it's actual name is object_001.

Is there a way to do this? As it stands I only know how to search for a specific name:

if (objExists('object_001'):
    //Do Something

But obviously the obj stringwould have to be exact to the object e it self.

Shannon Hochkins
  • 11,763
  • 15
  • 62
  • 95
  • If you know it will always be a number you could try a loop with something like light = 'Light_%d' % (light_id) | or there are some python string functions that you could try searching the hiearchy – user-2147482637 Aug 25 '13 at 12:22

1 Answers1

1

Pymel ls seems to accept directly a regular expression matching names, thus the following should work - provided that matching elements exists, a non-empty list will be returned; and a non-empty list in boolean context will be evaluated as True, whereas an empty will be False.

if ls(regex='object.*'):
    ...