Finding a Character’s NameSpace with MotionBuilder Python
Posted On April 25, 2017

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(i):
##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)
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.
2 Comments
Hey this is great stuff to share. I would suggest that you pass the variable i through the function arguments.
def CharacterInfo(i):
then in the for loop call CharacterInfo(i)
if not then the function character info will fail if not called in the for loop using i
Hey Damon. Great advice! It’s a typo that I will fix right away.
Thanks for the feed back and let me know if you have any requests on future posts.
Thank you.