-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenPipeline.mel
341 lines (327 loc) · 13 KB
/
openPipeline.mel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
/* This file downloaded from Highend3d.com
''
'' Highend3d.com File Information:
''
'' Script Name: openPipeline
'' Author:
'' Last Updated: May 12, 2008
'' Update/Change this file at:
'' http://Highend3d.com/maya/downloads/mel_scripts/data_management/4450.html
''
'' Please do not alter any information above this line
'' it is generated dynamically by Highend3d.com and will
'' be changed automatically on any updates.
*/
// openPipeline
//
// Developed by:
// Rob O'Neill ([email protected])
// Paris Mavroidis ([email protected])
// Meng-Han Ho ([email protected])
//
//###########################################
// Name: sourceModule
// Description: Finds all the mel files in a path (and potentially subpath) and sources them
// Input: path - The path to look in (string)
// Returns: none
//###########################################
global proc sourceModule(string $path)
{
string $melFiles[] = `getFileList -folder $path -filespec "*.mel"`;
string $eachFile;
print ("----- Sourcing " + $path + "------\n");
print ("//////////////////////////////////////////////////////\n");
for ($eachFile in $melFiles)
{
string $scriptFile = ($path + $eachFile);
string $cmdString = ("source \"" + $scriptFile + "\"");
print ("//// Source: " + $cmdString + "\n");
catch(`eval $cmdString`);
}
}
//###########################################
// Name: openPipelineSetMainPath
// Description: Sets the text for the project file path text field
// Input: path - The path to set the field to (string)
// type - Not used (string)
// Returns: none
// Note: Called directly by the browse file dialog
//###########################################
global proc openPipelineSetMainPath(string $path, string $type)
{
textField -e -tx $path mainPathTextField;
}
//###########################################
// Name: openPipelineSetProjPathField
// Description: Sets the text for the script path text field
// Input: path - The path to set the field to (string)
// type - Not used (string)
// Returns: none
// Note: Called directly by the browse file dialog
//###########################################
global proc openPipelineSetProjPathField(string $path, string $type)
{
textField -e -tx $path mainProjPathTextField;
}
//###########################################
// Name: openPipelineProjPathFieldToggle
// Description: Toggles the text field for setting the project file path between Default and Custom
// Input: none
// Returns: none
//###########################################
global proc openPipelineProjPathFieldToggle()
{
global string $openPipeline_projectFilePath;
int $editable = `textField -q -editable mainProjPathTextField`;
if ($editable)
{
textField -e -editable 0 -tx "[Default]" mainProjPathTextField;
button -e -l "Edit" -w 60 op_projPathToggleButton;
button -e -enable 0 op_projPathBrowseButton;
}
else
{
textField -e -editable 1 -tx $openPipeline_projectFilePath mainProjPathTextField;
button -e -l "Default" -w 60 op_projPathToggleButton;
button -e -enable 1 op_projPathBrowseButton;
}
}
//###########################################
// Name: openPipelineSetupExec
// Description: Sets up the Project File Path and the Script Path depending on user input
// This method checks the user's input for validity
// and then edits the 'openPipeline.mel' script to reflect the changes
// to global variables $openPipeline_projectFilePath and $openPipeline_scriptPath
// Input: none
// Returns: none
//###########################################
global proc openPipelineSetupExec()
{
string $newProjFilePath;
string $newScriptPath;
$newScriptPath = `textField -q -tx mainPathTextField`;
if (!endsWith($newScriptPath,"/"))
$newScriptPath += "/";
if (`textField -q -editable mainProjPathTextField`)
{
$newProjFilePath = `textField -q -tx mainProjPathTextField`;
}
else
{
$newProjFilePath = $newScriptPath + "openPipeline/";
}
string $mainFile = $newScriptPath + "openPipeline.mel";
string $error = "";
if (!openPipelineIsValidScriptPath($newScriptPath))
$error += ("Script path not valid. Make sure path \"" + $newScriptPath + "\" exists and contains the \"openPipeline\" folder.\n");
else if (!openPipelineIsValidProjFilePath($newProjFilePath))
$error += ("Project File path not valid. Make sure path \"" + $newProjFilePath + "\" exists.\n");
else if (!openPipelineIsEditableFile($mainFile))
$error += "openPipeline.mel not editable\n ";
if (!size($error))
{
string $newCode[];
int $fileId=`fopen $mainFile "r"`;
int $i=0;
string $nextLine= `fgetline $fileId`;
//read code and replace global variable assignments to new values
while ( size( $nextLine ) > 0 )
{
string $test1 = match("^[ ]*global[ ]+string[ ]+$openPipeline_projectFilePath[ ]*[=]{1}*",$nextLine);
string $test2 = match("^[ ]*global[ ]+string[ ]+$openPipeline_scriptPath[ ]*[=]{1}*",$nextLine);
if (size($test1))
$newCode[$i] = " global string $openPipeline_projectFilePath = \""+$newProjFilePath+"\";\n";
else if (size($test2))
$newCode[$i] = " global string $openPipeline_scriptPath = \""+$newScriptPath+"\";\n";
else
$newCode[$i] = $nextLine;
$nextLine= `fgetline $fileId`;
$i++;
}
fclose $fileId;
$fileId=`fopen $mainFile "w"`;
for ($line in $newCode)
fprint $fileId $line;
fclose $fileId;
deleteUI openPipelineInitSetupWindow;
//restart openPipeline with new values
global string $openPipeline_scriptPath;
$openPipeline_scriptPath = $newScriptPath;
global string $openPipeline_projectFilePath;
$openPipeline_projectFilePath = $newProjFilePath;
string $scriptsFolderName = "openPipeline";
//Check if the paths are valid
if ((!endsWith($openPipeline_scriptPath,"/"))&&(size($openPipeline_scriptPath)))
$openPipeline_scriptPath += "/";
if ((!endsWith($openPipeline_projectFilePath,"/"))&&(size($openPipeline_projectFilePath)))
$openPipeline_projectFilePath += "/";
string $error = "";
if (!openPipelineIsValidScriptPath($openPipeline_scriptPath))
{
$error+="Script path has not yet been set or is not valid.\n";
}
if (!openPipelineIsValidProjFilePath($openPipeline_projectFilePath))
{
$error+="Project File path has not yet been set or could not be found.\n";
}
//If paths are valid, run the openPipeline UI
if (!size($error))
{
sourceModule($openPipeline_scriptPath+$scriptsFolderName+"/");
catch(`eval "openPipelineUI"`);
}
//If paths are not valid, run openPipeline setup.
else
{
openPipelineSetup();
}
}
else
{
confirmDialog -title "openPipeline - Project Setup Error" -bgc .9 .9 .9
-message ("Could not complete openPipeline setup:\n"+$error)
-button "Ok" -defaultButton "Ok";
}
}
//###########################################
// Name: openPipelineSetup
// Description: Creates the openPipeline Setup UI
// Input: none
// Returns: none
//###########################################
global proc openPipelineSetup()
{
global string $openPipeline_scriptPath;
global string $openPipeline_projectFilePath;
string $defPath = $openPipeline_scriptPath;
string $windowExists = `window -q -exists openPipelineInitSetupWindow`;
if ($windowExists == 1)
{
deleteUI openPipelineInitSetupWindow;
}
string $title_txt = "openPipeline Setup";
if (`filetest -d $defPath`)
workspace -dir $defPath;
window -w 300 -h 200 -sizeable 0 -mxb 0 -rtf 0 -title $title_txt openPipelineInitSetupWindow;
columnLayout -width 280 -rs 5 -co "both" 10;
text -fn "boldLabelFont" -label "Script Path Setup:" -align "left" -width 280;
text -label "Please specify the folder in which the \"openPipeline.mel\" file and the\n\"openPipeline\" folder are located." -align "left" -width 380;
textField -h 20 -text $defPath -width 380 mainPathTextField ;
rowLayout -nc 2 -cw2 320 60 ;
text -label "";
button -label "Browse..." -c "fileBrowserDialog -m 4 -fc \"openPipelineSetMainPath\" -an \"Find Location\" " -w 60;
setParent..;
separator -style "none" -height 10;
text -fn "boldLabelFont" -label "Project File Setup:" -align "left" -width 280;
text -label "By default, the Project File will be located in the \"openPipeline\" folder.\nYou may set a different location for the Project File here." -align "left" -width 380;
textField -h 20 -editable 0 -text "[Default]" -width 380 mainProjPathTextField ;
rowLayout -nc 3 -cw3 260 60 60 ;
text -label "";
button -label "Edit" -c "openPipelineProjPathFieldToggle" -w 60 op_projPathToggleButton;
button -label "Browse..." -en 0 -c "fileBrowserDialog -m 4 -fc \"openPipelineSetProjPathField\" -an \"Find Location\" " -w 60 op_projPathBrowseButton;
setParent..;
separator -h 10 -style "none";
rowLayout -nc 2 -cw2 190 190;
button -label "Accept" -w 190 -c "openPipelineSetupExec";
button -label "Cancel" -w 190 -c "deleteUI openPipelineInitSetupWindow";
if (size($openPipeline_projectFilePath))
{
openPipelineProjPathFieldToggle();
textField -e -text $openPipeline_projectFilePath mainProjPathTextField;
}
window -e -w 405 -h 350 openPipelineInitSetupWindow;
showWindow;
}
//###########################################
// Name: openPipelineIsValidScriptPath
// Description: Checks if the given folder is a valid script path
// a valid script path contains the file 'openPipeline.mel'
// and contains a folder name 'openPipeline'
// Input: folder - The path to be checked (string)
// Returns: 1 if path is a valid script path, 0 if not (int)
//###########################################
global proc int openPipelineIsValidScriptPath(string $folder)
{
int $valid = 1;
if (!endsWith($folder,"/"))
$folder += "/";
string $fileName = $folder+"openPipeline.mel";
string $folderName = $folder +"openPipeline";
if (!`filetest -d $folder`)
$valid = 0;
else if (!`filetest -r $fileName`)
$valid = 0;
else if (!`filetest -d $folderName`)
$valid = 0;
return $valid;
}
//###########################################
// Name: openPipelineIsValidProjFilePath
// Description: Checks if the given folder is a valid project path
// The path needs to be an existing path.
// Input: folder - The path to be checked (string)
// Returns: 1 if path is valid, 0 if not (int)
//###########################################
global proc int openPipelineIsValidProjFilePath(string $folder)
{
int $valid = `filetest -d $folder`;
return $valid;
}
//###########################################
// Name: openPipelineIsEditableFile
// Description: Checks of the given file is readable and writeable
// This is used to check if the openPipeline.mel file can be read and edited.
// Input: filename - Full path to the file to be checked (string)
// Returns: 1 if file is readable and writeable, 0 if not (int)
//###########################################
global proc int openPipelineIsEditableFile(string $filename)
{
int $result = 1;
if (!`filetest -w $filename`)
{
$result = 0;
}
else if (!`filetest -r $filename`)
{
$result = 0;
}
return $result;
}
//###########################################
// Name: openPipeline
// Description: Main openPipeline procedure
// Input: none
// Returns: none
//###########################################
global proc openPipeline()
{
//the following two lines are edited by the script whenever the user changes the Script Path or the Project File Path
global string $openPipeline_scriptPath = "/Volumes/vfxstore01/syswide/MEL/syswide/";
global string $openPipeline_projectFilePath = "/Volumes/vfxstore01/syswide/MEL/syswide/openPipeline/";
string $scriptsFolderName = "openPipeline";
//Check if the paths are valid
if ((!endsWith($openPipeline_scriptPath,"/"))&&(size($openPipeline_scriptPath)))
$openPipeline_scriptPath += "/";
if ((!endsWith($openPipeline_projectFilePath,"/"))&&(size($openPipeline_projectFilePath)))
$openPipeline_projectFilePath += "/";
string $error = "";
if (!openPipelineIsValidScriptPath($openPipeline_scriptPath))
{
$error+="Script path has yet been set or is not valid.\n";
}
if (!openPipelineIsValidProjFilePath($openPipeline_projectFilePath))
{
$error+="Project File path has not yet been set or could not be found.\n";
}
//If paths are valid, run the openPipeline UI
if (!size($error))
{
sourceModule($openPipeline_scriptPath+$scriptsFolderName+"/");
catch(`eval "openPipelineUI"`);
}
//If paths are not valid, run openPipeline setup.
else
{
openPipelineSetup();
}
}