forked from zlovatt/zl_Scriptlets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDefault Folders v2.0.jsx
132 lines (111 loc) · 3.55 KB
/
Default Folders v2.0.jsx
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
/**
* Creates a number of folders (or, if ran as a window, lets you customzie folder names to create)
*
* Based on DefaultFolders by Impudent1 from http://aenhancers.com/viewtopic.php?t=37
*
* If run via `Window`, Shows a UI to set folder names
* If run via `File > Script`, creates folders from preferences
*
* @author Zack Lovatt <zack@lova.tt>
* @version 2.0.2
*/
(function defaultFolders(thisObj) {
var defaultFolderNames = [
"Cross Referenced Solids",
"Pre Comps",
"Source Footage",
"Guides/Adjustment Layers",
"Render Queue Comps",
"Work In Progress"
];
/**
* Creates folders from folderNames array
*
* @param {String[]} folderNames Array of folder names to create
*/
function createFolders(folderNames) {
for (var ii = 0, il = folderNames.length; ii < il; ii++) {
var folderName = folderNames[ii];
if (folderName === "") continue;
app.project.items.addFolder(folderName);
}
}
/**
* Gets folder names from prefs (if present), or defaults
*
* @returns {String[]} Array of folder names
*/
function getFolderNames() {
if (app.settings.haveSetting("DefaultFolderPrefs", "Folder1")) {
return [
app.settings.getSetting("DefaultFolderPrefs", "Folder1"),
app.settings.getSetting("DefaultFolderPrefs", "Folder2"),
app.settings.getSetting("DefaultFolderPrefs", "Folder3"),
app.settings.getSetting("DefaultFolderPrefs", "Folder4"),
app.settings.getSetting("DefaultFolderPrefs", "Folder5"),
app.settings.getSetting("DefaultFolderPrefs", "Folder6")
];
}
return defaultFolderNames;
}
/**
* Sets folder names to prefs from parameter
*
* @param {String[]} Array of folder names
*/
function setFolderNames(folderNames) {
for (var ii = 0, il = folderNames.length; ii < il; ii++) {
app.settings.saveSetting("DefaultFolderPrefs", "Folder" + (ii + 1), folderNames[ii]);
}
}
/**
* Creates the UI
*
* @param {object} thisObj Environment
* @returns {Window} SUI Palette
*/
function createUI(thisObj) {
var win = thisObj instanceof Panel ? thisObj : new Window("palette", "Default Folders");
win.add("statictext", undefined, "Set default project folders.");
var grpFolders = win.add("group");
grpFolders.orientation = "column";
var folderNames = getFolderNames();
for (var ii = 0, il = folderNames.length; ii < il; ii++) {
var folderName = folderNames[ii];
var etFolder = grpFolders.add(
"edittext",
undefined,
folderName
);
etFolder.characters = 30;
}
var grpMeta = win.add("group");
grpMeta.orientation = "row";
var btnOK = grpMeta.add("button", undefined, "Create!");
btnOK.onClick = function() {
app.beginUndoGroup("Default Folder Maker");
var uiFolderNames = [];
for (var ii = 0, il = grpFolders.children.length; ii < il; ii++) {
uiFolderNames.push(grpFolders.children[ii].text);
}
setFolderNames(uiFolderNames);
createFolders(uiFolderNames);
app.endUndoGroup();
};
var btnReset = grpMeta.add("button", undefined, "Reset");
btnReset.onClick = function() {
for (var ii = 0, il = grpFolders.children.length; ii < il; ii++) {
var etFolder = grpFolders.children[ii];
etFolder.text = defaultFolderNames[ii];
}
}
return win;
}
var win = createUI(thisObj);
if (win instanceof Window) {
var folderNames = getFolderNames();
createFolders(folderNames);
} else {
win.layout.layout(true);
}
})(this);