Object starts with?

1.8k Views Asked by At

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.

1

There are 1 best solutions below

3
On

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.*'):
    ...