-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImport+.jsx
156 lines (133 loc) · 4.2 KB
/
Import+.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
{
function createImportPlusPanel(thisObj) {
var panel =
thisObj instanceof Panel
? thisObj
: new Window("palette", "Import+", undefined, {
resizeable: true
});
var tabbedPanel = panel.add("tabbedpanel");
tabbedPanel.alignment = ["fill", "fill"];
var browseTab = tabbedPanel.add("tab", undefined, "Browse");
browseTab.orientation = "column";
browseTab.alignChildren = ["fill", "top"];
var browseButton = browseTab.add(
"button",
undefined,
"Browse and Import Files"
);
browseButton.alignment = "center";
browseButton.onClick = function () {
var files = File.openDialog(
"Select files to copy and import",
undefined,
true
);
if (files) handleFileImport(files);
};
var organizeButton = browseTab.add(
"button",
undefined,
"Organize and Relink Files"
);
organizeButton.alignment = "center";
organizeButton.onClick = function () {
handleOrganizeAndRelink();
};
function handleFileImport(files) {
var project = app.project;
if (!project.file) {
alert("Please save your project first!");
return;
}
var projectPath = project.file.fsName;
var projectDir = projectPath.substring(
0,
projectPath.lastIndexOf("/") + 1
);
var footageFolder = new Folder(projectDir + "/(Footage)");
if (!footageFolder.exists) {
if (!footageFolder.create()) {
alert("Failed to create /(Footage) folder.");
return;
}
}
app.beginUndoGroup("Import Files");
for (var i = 0; i < files.length; i++) {
try {
var sourceFile = new File(files[i]);
var destinationFile = new File(
footageFolder.fsName + "/" + sourceFile.name
);
sourceFile.copy(destinationFile);
var importOptions = new ImportOptions(destinationFile);
project.importFile(importOptions);
} catch (e) {}
}
app.endUndoGroup();
}
function handleOrganizeAndRelink() {
var project = app.project;
if (!project.file) {
alert("Please save your project first!");
return;
}
var projectPath = project.file.fsName;
var projectDir = projectPath.substring(
0,
projectPath.lastIndexOf("/") + 1
);
var footageFolder = new Folder(projectDir + "/(Footage)");
if (!footageFolder.exists) {
if (!footageFolder.create()) {
alert("Failed to create /(Footage) folder.");
return;
}
}
app.beginUndoGroup("Organize and Relink Files");
for (var i = 1; i <= project.numItems; i++) {
var item = project.item(i);
if (item instanceof FootageItem && item.file) {
try {
var sourceFile = item.file;
var destinationFile = new File(
footageFolder.fsName + "/" + sourceFile.name
);
if (!destinationFile.exists) {
sourceFile.copy(destinationFile);
}
item.replace(destinationFile);
} catch (e) {}
}
}
app.endUndoGroup();
alert(
"All files have been organized and relinked to the /(Footage) folder."
);
}
var infoTab = tabbedPanel.add("tab", undefined, "Info");
infoTab.orientation = "column";
infoTab.alignChildren = ["fill", "top"];
var infoText = infoTab.add("statictext", undefined, undefined, {
multiline: true
});
infoText.text =
"How Import+ Works:\n\n" +
"- Use the 'Browse and Import Files' button to add new files.\n" +
"- Use the 'Organize and Relink Files' button to copy all imported files to the '(Footage)' folder and relink them.\n\n" +
"Benefits:\n" +
"- Keeps your files organized in one place.\n" +
"- Ensures After Effects can always find your assets.";
infoText.alignment = ["fill", "top"];
panel.layout.layout(true);
panel.onResizing = panel.onResize = function () {
this.layout.resize();
};
return panel;
}
var panel = createImportPlusPanel(this);
if (panel instanceof Window) {
panel.center();
panel.show();
}
}