UI/Unbind_example.py

UI/Unbind_example.py
1 # Copyright 2009 Autodesk, Inc. All rights reserved.
2 # Use of this software is subject to the terms of the Autodesk license agreement
3 # provided at the time of installation or download, or which otherwise accompanies
4 # this software in either electronic or hard copy form.
5 #
6 # Script description:
7 # This script shows how and why you can receive UnbindExceptionError.
8 #
9 
10 
11 from pyfbsdk import *
12 from pyfbsdk_additions import *
13 from unbind import *
14 
15 # Tool creation will serve as the hub for all other controls
16 t = FBCreateUniqueTool("Label Example")
17 
18 l = FBLabel()
19 l.Caption = "This is a label!!!!"
20 
21 t.StartSizeX = 200
22 t.StartSizeY = 100
23 
24 x = FBAddRegionParam(10,FBAttachType.kFBAttachLeft,"")
25 y = FBAddRegionParam(10,FBAttachType.kFBAttachTop,"")
26 w = FBAddRegionParam(100,FBAttachType.kFBAttachNone,"")
27 h = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
28 
29 t.AddRegion("Label","Label", x, y, w, h)
30 
31 t.SetControl("Label",l)
32 
33 def OnUnbind(control, event):
34  print "***** ", control, " has been Unbound *****"
35 
36 l.OnUnbind.Add(OnUnbind)
37 
38 # At that point, the tool is destroy, the internal Label are also destroy.
39 # Python is notify about its internal Undinbing.
41 
42 # if you make this call, you get an exception because this Python wrapper is not linked
43 # to a MotionBuilder label anymore.
44 
45 print "Trying to access an unbound Ui Control... this will raise an exception"
46 l.Caption