รหัสต่อไปนี้ใช้งานได้สำหรับฉันในขณะนี้ ฉันหวังว่ามันจะสามารถใช้เป็นจุดเริ่มต้นสำหรับคุณได้ โปรดให้ฉันเพิ่มหมายเหตุในบางบรรทัด:
1- ไฟล์ คือโฟลเดอร์ที่สคริปต์จะค้นหาเลเยอร์ นี่ควรเป็นโฟลเดอร์ที่อยู่ถัดจากโปรเจ็กต์ .aep ของคุณ (หรือเปลี่ยนบรรทัดนี้ตามลำดับ)
10-46- การเริ่มต้นฟังก์ชันที่มีประโยชน์บางอย่าง เช่น รับหมายเลขรายการโฟลเดอร์หรือคอมพ์ตามชื่อ สิ่งเหล่านี้จะถูกเพิ่มไว้ในกรณีที่คุณต้องการแทนที่ค่าฮาร์ดโค้ด (ฉันทำไม่ได้เนื่องจากไม่มีเวลา)
โปรดทราบว่าบรรทัด 55, 68, 69 หรือ 72 มีหมายเลขรายการของการเรียบเรียง/โฟลเดอร์ฮาร์ดโค้ด ซึ่งหมายความว่าสคริปต์นี้จะทำงานได้ตราบใดที่โปรเจ็กต์ After Effects ของคุณ รายการแรกคือคอมพ์ และ รายการที่สองคือโฟลเดอร์
บรรทัด 58 แจ้งให้ป้อนไฟล์ txt ของคุณพร้อมชื่อเลเยอร์และตำแหน่ง
ฉันคิดว่าส่วนที่เหลือค่อนข้างชัดเจนจากความคิดเห็น แต่แจ้งให้เราทราบหากคุณมีคำถามเพิ่มเติม
var originFolder = "\\files";
var path = app.project.file.path;
var originFolderPath = Folder(path + originFolder);
var originFolderFiles = originFolderPath.getFiles();
var myProject = app.project;
// Functions to handle the importing of files and folders
function processFile(theFile) {
try {
var importOptions = new ImportOptions(theFile);
importSafeWithError(importOptions);
} catch (error) {
}
}
function importSafeWithError(importOptions) {
try {
app.project.importFile(importOptions);
} catch (error) {
alert(error.toString() + importOptions.file.fsName, scriptName);
}
}
function processFolder(folder) {
var filesInFolder = folder.getFiles();
for (index in filesInFolder) {
if (filesInFolder[index] instanceof File) {
processFile(filesInFolder[index]);
}
}
}
function getFolderByName(folderName) { // Given a folder name, returns the item index in the project
for (var i = 1; i <= myProject.numItems; i++) {
if ((myProject.item(i) instanceof FolderItem) && (myProject.item(i).name == folderName)){
return myProject.item(i);
}
}
}
function getCompByName(compName) { // Given a folder name, returns the item index in the project
for (var i = 1; i <= myProject.numItems; i++) {
if ((myProject.item(i) instanceof CompItem) && (myProject.item(i).name == compName)){
return myProject.item(i);
}
}
}
// Fun starts here
processFolder(originFolderPath); // Import the files of the folder originFolder
for (var i = 1; i <= myProject.numItems; i++) { // Put the imported files inside item(2) --> folder
if (myProject.item(i) instanceof FootageItem) {
myProject.item(i).parentFolder = myProject.item(2); // Note that the folder must be item(2)
}
}
var textFile = File.openDialog("Select text file."); // select the text file you want to open
if (textFile != null){
textFile.open("r");
}
var text;
while (!textFile.eof){
text = textFile.readln();
}
var textArr = text.split(', '); // Separate the different values in an array
for (var i = 1; i <= myProject.item(2).numItems; i++){ // Add the layers to the comp
myProject.item(1).layers.add(myProject.item(2).item(i)); // Note that the comp must be item(1)
}
comp = myProject.item(1); // Setting the comp that contains our layers
for (var i = 1; i<= comp.numLayers; i++){ // Flipping the layer order so Layer 1 is the first one
comp.layer(i).moveToBeginning();
}
u = 0;
for (var i = 1; i <= comp.numLayers; i++){ // Setting the position of each layer
u = u+3; // Skipping every 3rd item to ignore the "Layer X" values on the txt file
var posArr = [0,0]; // Create a new array for the position of the layer
origX = parseInt(u-2); // Select the appropiate item of the array, skipping "Layer X"
origY = parseInt(u-1);
posArr[0] = textArr[origX];
posArr[1] = textArr[origY];
layer = comp.layer(i);
layer.property("Position").setValue(posArr); // Applying the new X,Y array to the position value
}
จำเป็นต้องรักษาจุดยึดเดิมของแต่ละชั้นไว้หรือไม่? เพราะจะทำสิ่งต่อไปนี้ได้ง่าย:
(Photoshop) ไฟล์ > ส่งออก > เลเยอร์เป็นไฟล์...
และบันทึกแต่ละเลเยอร์เป็น PNG ขนาดแคนวาส จากนั้นนำเข้าเป็นชุดลงในองค์ประกอบด้วยสคริปต์ After Effects ปัญหาคือจุดยึดทั้งหมดจะอยู่ตรงกลางองค์ประกอบภาพ ซึ่งฉันเดาว่าไม่ดีสำหรับคุณ
อีกทางเลือกหนึ่งคือการนำเข้าไฟล์ PSD โดยตรงใน After Effects หากคุณนำเข้าไฟล์ PSD เป็นองค์ประกอบแทนวิดีโอ และเลือก "รักษาขนาดเลเยอร์" คุณจะได้เลเยอร์ PSD แต่ละเลเยอร์ในเลเยอร์ After Effects และอยู่ในตำแหน่งที่ถูกต้อง นี่ไม่ใช่ตัวเลือกสำหรับกรณีการใช้งานของคุณใช่ไหม
person
sqr
schedule
20.11.2019