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: 

How do you exit a script on an error without closing MotionBuilder...?

3 REPLIES 3
Reply
Message 1 of 4
Anonymous
612 Views, 3 Replies

How do you exit a script on an error without closing MotionBuilder...?

Excuse my ignorance - I'm still on a sharp learning curve...!

If I do this (based on an example I found on the web)...

import sys

myModel = FBFindModelByName('TEST')
if myModel == None :
FBMessageBox( "Message", "Can't find Object", "OK", None, None )
sys.exit ()
else :
lParent = myModel.Parent


On an error - MotionBuilder closes...

I just want to exit the script - not the program...

Any ideas...?
3 REPLIES 3
Message 2 of 4
Jacques.LIAO
in reply to: Anonymous


sys.exit ()


could you remove this line?
Jacques LIAO
Freelancer / Consultant programmer for MotionBuilder and Virtual production
Message 3 of 4
kimhutchison
in reply to: Anonymous

Wrap your code inside a function and use return to break out, like so:
from pyfbsdk import *
def CheckModel( lModelName ):
myModel = FBFindModelByName(lModelName)
if myModel == None :
FBMessageBox( "Message", "Can't find Object", "OK", None, None )
return
else :
lParent = myModel.Parent
CheckModel('TEST')


or raise an exception:

from pyfbsdk import *
myModel = FBFindModelByName('TEST')
if myModel == None :
FBMessageBox( "Message", "Can't find Object", "OK", None, None )
raise Exception( "Can't find Object" )
else :
lParent = myModel.Parent
Message 4 of 4
Anonymous
in reply to: Anonymous

Thanks Kim...

Wrapping it inside a function would be more appealing as it is run using FBMenu as an additional option in our current workspace - and I would have more control over what happens next...

Cheers

P

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

Post to forums  

Autodesk Design & Make Report