1
2
3
4
5
6
7
8
9
10
11
12
13
14from pyfbsdk import *
15from pyfbsdk_additions import *
16
17import os
18import os.path
19
20TOOL_NAME = "Action Script Manager"
21ACTION_SCRIPT_PATH = os.path.join(
FBSystem().ConfigPath,
"Scripts")
22ACTION_SCRIPT_FILE = os.path.join(ACTION_SCRIPT_PATH, "ActionScript.txt")
23
24class ActionScriptMgr(
FBTool):
25 def RowClicked(self,control,event):
26
27 if self.path_spread.GetRow(event.Row).RowSelected:
28 self.current_row = event.Row
29 else:
30 self.current_row = -1
31 path = self.path_spread.GetCellValue(event.Row, 0)
32
33
34
35 if path:
36 self.path_edit.Text = path
37
38 def Browse(self,control,event):
40 filepopup.Caption = "Select a script"
41 filepopup.Style = pyfbsdk.FBFilePopupStyle.kFBFilePopupOpen
42 filepopup.Filter = "*.py"
43 result = filepopup.Execute()
44 if result:
45 self.path_edit.Text = os.path.join(filepopup.Path,filepopup.FileName)
46 del filepopup
47
48 def Add(self,control,event):
49 if self.current_row == -1:
50 return
51 self.path_spread.SetCellValue(self.current_row,0,self.path_edit.Text)
52 self.UpdateScript(self.current_row)
53
54 def Remove(self,control,event):
55
56 if self.current_row == -1:
57 return
58 self.path_spread.SetCellValue(self.current_row,0,"")
59 self.UpdateScript(self.current_row)
60
61 def UpdateScript(self,row):
62 config =
FBConfigFile(
"ActionScript.txt",ACTION_SCRIPT_PATH)
63
64 spread_row = self.path_spread.GetRow(row)
65 key = spread_row.Caption
66 value = self.path_spread.GetCellValue(row,0)
67 if value:
68
69
70 value = os.path.relpath(value,ACTION_SCRIPT_PATH)
71 config.Set("ScriptFiles",key,value)
72
73 def CellChanged(self,control,event):
74
75 self.UpdateScript(event.Row)
76
77 def Populate(self):
78
79
80 old_cwd = os.getcwd()
81 os.chdir(ACTION_SCRIPT_PATH)
82
83 self.current_row = -1
84 self.nb_row = 0
85 config =
FBConfigFile(
"ActionScript.txt",ACTION_SCRIPT_PATH)
86 for i in range(12):
87 key = "Script%d" % (i + 1)
88 value = config.Get("ScriptFiles",key)
89 self.path_spread.RowAdd(key,self.nb_row)
90 if value:
91 self.path_spread.SetCellValue(self.nb_row,0,os.path.abspath(value))
92 self.nb_row += 1
93 os.chdir(old_cwd)
94
95 def __init__(self):
96
97 FBTool.__init__(self,TOOL_NAME)
98
99 FBAddTool(self)
100
101 x = FBAddRegionParam(0,FBAttachType.kFBAttachLeft,"")
102 y = FBAddRegionParam(0,FBAttachType.kFBAttachTop,"")
103 w = FBAddRegionParam(0,FBAttachType.kFBAttachRight,"")
104 h = FBAddRegionParam(0,FBAttachType.kFBAttachBottom,"")
105 self.AddRegion("main","main", x, y, w, h)
106
107 vbox = FBVBoxLayout()
108 self.SetControl("main",vbox)
109
110 widget_height = 30
111 button_width = 60
112
114 l.Caption = "Action Scripts"
115 vbox.Add(l, widget_height)
116
118 self.path_spread.Caption = "Actions"
119 self.path_spread.ColumnAdd("Path")
120 self.path_spread.GetColumn(0).Width = 550
121 self.path_spread.OnRowClick.Add(self.RowClicked)
122 self.path_spread.OnCellChange.Add(self.CellChanged)
123 vbox.AddRelative(self.path_spread,1.0)
124
125 hbox = FBHBoxLayout()
126
128 hbox.AddRelative(self.path_edit,1.0)
129
131 b.Caption = "Browse..."
132 b.OnClick.Add(self.Browse)
133 hbox.Add(b, button_width)
134
135 vbox.Add(hbox,widget_height)
136
137 hbox = FBHBoxLayout()
139 b.Caption = "Set"
140 b.OnClick.Add(self.Add)
141 hbox.Add(b, button_width)
142
144 b.Caption = "Remove"
145 b.OnClick.Add(self.Remove)
146 hbox.Add(b, button_width)
147
148
150 l.Caption = "You will need to restart MotionBuilder for changes to takes place!"
151 l.Style = FBTextStyle.kFBTextStyleBold
152 hbox.Add(l, 400)
153
154 vbox.Add(hbox,widget_height)
155
156 self.StartSizeX = 800
157 self.StartSizeY = 425
158
159
160 self.Populate()
161
162
163
164
165
166
167if TOOL_NAME in FBToolList:
168 tool = FBToolList[TOOL_NAME]
169 ShowTool(tool)
170else:
171 tool=ActionScriptMgr()
172 ShowTool(tool)
173
174
175
176
177
Interface to the application config files.
Definition: pyfbsdk_generated.h:4732
Text edit box.
Definition: pyfbsdk_generated.h:5998
Text label.
Definition: pyfbsdk_generated.h:9829
Base spreadsheet class.
Definition: pyfbsdk_generated.h:17486
Provides access to the underlying system, and the MotionBuilder scene.
Definition: pyfbsdk_generated.h:18771