Finding a Character’s NameSpace with MotionBuilder Python

Here is a snippet of script that I use a lot when dealing with Character’s Name Spaces within MotionBuilder.

##Setup variables to get all characters within the scene
lAllChars = FBSystem().Scene.Characters
##Setup a variable to get the length of lAllChars - this will be used to creat a loop
lNumberofChars = len(lAllChars)

##Set up the CharacterInfo Function
def CharacterInfo():
    ##Setup variables Current Character
    lCurrentCharacter = FBSystem().Scene.Characters[i]
    ##Select our Current Character
    lCurrentCharacter.Selected = True
    ##Setup variables for our Character's Names - we are going to split the vale at the ":" leaving us with jsut the NameSpace
    lCurrentCharName = lCurrentCharacter.LongName.rsplit(':', 2)[0]
    ##print NameSpace
    print lCurrentCharName

##Run a loop for the the number we created in the variable "lNumberofChars"
for i in range (lNumberofChars):
    ##Run our function
    CharacterInfo()

I often split the LongName to provide me with the NameSpace, I find it cleaner to read when I print it out – which I do often to ensure my scripts are being run on the correct characters at the correct time.

I hope this helps.

Leave a reply:

Your email address will not be published.

Site Footer