Returning A Specific Word From MotionBuilder’s Python Dir()

I’m not sure why I did not think of this before, here is a little function that will search a user specified module using dir(), but it will also search the components and only return the ones that match the user’s specified filtered word.

Let me explain with an example. By typing “searchdir(FBStoryClip, “Ghost”)” we will be presented with the following:
Ghost
GhostModel
GhostPivot
GhostTravelling
ShowGhostClipMode

By typing “searchdir(FBStoryClip, “”)” the user will be presented with all results – no different than if they were to type “for item in dir(FBStoryClip): print item”.

The function can be found here:

##Search Components For Specific Word And Return Them
def searchdir(module, component):
    for item in dir(module):
        if component in item:
            print item
        else:
            pass

It’s a simple little function but I do love using it to help me weed through a large list or to quickly find out if I should be searching else where.

I hope this helps.

Add a Comment

Your email address will not be published. Required fields are marked *