MotionBuilder Forum
Welcome to Autodesk’s MotionBuilder Forums. Share your knowledge, ask questions, and explore popular MotionBuilder topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

[SOLVED] Loop into a hierarchy

11 REPLIES 11
Reply
Message 1 of 12
BrunoTD
1885 Views, 11 Replies

[SOLVED] Loop into a hierarchy

Hi all,

I'm trying to loop into a hierarchy to select all bones parented to my Reference node (a NULL). For some reasons, none of the solutions given in the forum (and there is plenty of) works. actually it select the top node, the first after and stops...
I'm on Mobu 2012... Is there some changes in classes? I did the same in Mobu 7.5 ext 2 and it worked (as far as I remember).

my loop:

def selectHierarchy (pRoot):
model = FBFindModelByName (pRoot)
model.Selected = True

for child in model.Children:
child.Selected = True

pRoot = "Reference"
selectHierarchy (pRoot)


Once this solved I'll try to refine my research by searching with LongName as I have several characters in the scene.
By the way, is it me or the Python documentation for Mobu is sh....??
11 REPLIES 11
Message 2 of 12
primal_r
in reply to: BrunoTD

Looks like working code to me... (just compared to code I have that works in 2012)
Message 3 of 12
primal_r
in reply to: primal_r

... what does Python output window say?

you've probably been given an FBModelList in your FBFindModelByName or something... so try

for child in model.Children:
Message 4 of 12
primal_r
in reply to: BrunoTD

or like this:


def selectHierarchy (pRoot):
model = FBFindModelByName (pRoot)
model.Selected = True
print type(model) # <---- will tell you if it's a proper object or a list

for child in model.Children:
child.Selected = True

pRoot = "Reference"
selectHierarchy (pRoot)

Message 5 of 12
BrunoTD
in reply to: BrunoTD

Thank you Oskar ^^

That's actually the strange point... With your modification it select only the next node after the first selected (which is already an improvement as my version selects nothing!!). I'm quite new into Python and maybe I missed something important.
I did the same thing 2 years ago on Mobu 7.5 and it worked fine (it was my first very small script)... I really don't understand.
I did it step by step like the newby I am, so to be sure of what I'm doing a build small functions I call later rather than big pieces of code I would get lost easily into. A function select the Root (it's a Null object) and the other one should select all the followings. I need to be able to select the Root by code as I will have several characters in the scene.

So the whole code for this is:

def selectRoot (pLabelName):
lSel = FBFindModelByLabelName (pLabelName)
lSel.Selected = True
return lSel

def selectHierarchy (pRoot):
model = FBFindModelByName (pRoot)
model.Selected = True
print type (model) # <---- will tell you if it's a proper object or a list

for child in model.Children:
child.Selected = True

pLabelName = "male:Reference"
pNmsp = "male"
pNode = 'Reference'
selectRoot (pLabelName)
selectHierarchy (pNode)

lModelList = FBModelList ()
lSel = FBGetSelectedModels (lModelList)
Message 6 of 12
BrunoTD
in reply to: BrunoTD

Is there anyone from Autodesk reading the forum who could explain to me why a simple loop that worked in Mobu 7.5 ext2 doesn't work anymore in Mobu 2012?
I tried many possibilities, checking object type (I get FBModelSkeleton which is what I want I guess), etc... The loop stops at the first bone level found. So I guess there could be a way to force it continuing... How?
Message 7 of 12
BrunoTD
in reply to: BrunoTD

Finally I used this I found into the forum:

def selectHierarchy (pRoot):
lRoot = FBFindModelByName (pRoot)
lRoot.Selected = True
lChildlist = FBModelList()
FBGetSelectedModels (lChildlist, lRoot, True, True)
FBGetSelectedModels (lChildlist, lRoot, False, True)
for lChild in lChildlist:
lChild.Selected = True


Not really straightforward but it works fine ^^
Message 8 of 12
joel.pennington
in reply to: BrunoTD

You just needed to make your function recursive. A recursive function will go through all of the branches of a tree and select away for ya.


def recursive(topNode):
for child in topNode.Children:
child.Selected = True
recursive(child)

TheTopNode = FBFindModelByName("Reference")
recursive(TheTopNode)
Product Designer for Virtual Production
Autodesk
Message 9 of 12
BrunoTD
in reply to: joel.pennington

I did first, it sounded the most simple and straightforward but for some reasons it didn't worked... Maybe something with Mobu 2012?
Message 10 of 12
joel.pennington
in reply to: BrunoTD

That snippet of code I added was done in 2012, it worked for me!
Product Designer for Virtual Production
Autodesk
Message 11 of 12
BrunoTD
in reply to: joel.pennington

I tried again this morning and it works fine... I don't understand but thank you anyway 🙂 I will keep this piece of code preciously in a file 🙂
Message 12 of 12
BrunoTD
in reply to: BrunoTD

OK I SEE THE PROBLEM NOW!! 🙂
Instead of calling (child) as argument in my loop I called (pRoot)... Then it didn't iterate though the hierarchy but looped into the root node...

def selectHierarchy (pRoot):
for child in pRoot.Children:
child.Selected = True
selectHierarchy (pRoot) ## This line should be: selectHierarchy (child)!!!

pRoot = FBFindModelByName ("Reference")
selectHierarchy (pRoot)


Thank you for your help... 🙂

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums