Copy link to clipboard
Copied
Heey, my name is Bram Hoekstra. I'm from the Netherlands and I'm working on a script that allows you to take notes inside of After Effects without having to leave the program. I'm curious if it's possible to save the imput that you type in an edittext field to a text file. And if it's possible to load text from a text file into the edittext field.
Thx for helping in advance.
Greetings,
Bram Hoekstra
How your program works exactly is up to you. If you have a read button and a write button somewhere, I'd recommend attaching these functions to their .onClick() methods:
...// set this variable to your file path
var myFile = new File('path/to/my/file');
// set this variable to your editText element
var myEditText = ______;
function writeText(){
// Get text
var myText = myEditText;
// Write File
myFile.open('w', undefined, undefined);
var writeResult = myFile.write(myText);
myFile.close
Copy link to clipboard
Copied
Yes, this is totally possible. Read the text in the edittext, create a new File object, and then write it to it. When reading, create a new File object, read it, and then set the edittext value to the text you read. See examples below:
// Build Window
var resStr = 'palette{orientation:"column", alignChildren:["center", "top"], text: "Write", size:[380,110],\
txt: EditText{text:"to write", alignment:["fill", "center"]},\
}';
myWin.window = new Window(resStr);
myWin.window.show();
var myFile = new File('path/to/my/file');
// Get text
var myText = myWin.txt.text;
// Write File
myFile.open('w', undefined, undefined);
var writeResult = myFile.write(myText);
myFile.close();
// Read File
myFile.open('r', undefined, undefined);
var newText = myFile.read(myText);
myFile.close();
// Set text
myWin.txt.text = newText;
Copy link to clipboard
Copied
How should I apply it to the following code?
(function(thisObj){
aen(thisObj);
function aen(thisObj){
var mainWindow = (thisObj instanceof Panel) ? thisObj : new Window("palette", "AE Note", undefined, {
resizeable: false, closeButton: true
});
var mainPanel = mainWindow.add("panel", undefined);
var noteButtonPanel = mainPanel.add("panel", undefined);
var noteButton = noteButtonPanel.add("button", undefined, "Note");
noteButton.preferredSize = [100,25];
noteButton.onClick = function(){
noteWindow.show();
};
var infoButtonPanel = mainPanel.add("panel", undefined);
var infoButton = infoButtonPanel.add("button", undefined, "Info");
infoButton.preferredSize = [100,25];
infoButton.onClick = function(){
infoWindow.show();
};
var noteWindow = new Window("palette", "AE Note - Note", undefined, {
resizeable: false, closeButton: false
});
var mainPanel = noteWindow.add("panel", undefined);
var noteFieldPanel = mainPanel.add("panel", undefined);
var mainNotesHeadGroup = noteFieldPanel.add("group", undefined, "mainNotesHeadGroup");
mainNotesHeadGroup.orientation= "row";
mainNotesHeadGroup.alignment = "left";
var mainNotesHeadGroupName = mainNotesHeadGroup.add("statictext", undefined, "Main Notes:");
var saveButton = mainNotesHeadGroup.add("button", undefined, "Save");
saveButton.preferredSize = [100,25];
saveButton.onClick = function(){
};
var loadButton = mainNotesHeadGroup.add("button", undefined, "Load");
loadButton.preferredSize = [100,25];
loadButton.onClick = function(){
};
var mainNotesField = noteFieldPanel.add("edittext", undefined);
mainNotesField.preferredSize = [282.5,75];
var sideNotesHeadGroup = noteFieldPanel.add("group", undefined);
sideNotesHeadGroup.orientation= "row";
sideNotesHeadGroup.alignment = "left";
var sideNotesHeadGroupName = sideNotesHeadGroup.add("statictext", undefined, "Side Notes:");
var saveButton = sideNotesHeadGroup.add("button", undefined, "Save");
saveButton.preferredSize = [100,25];
saveButton.onClick = function(){
};
var loadButton = sideNotesHeadGroup.add("button", undefined, "Load");
loadButton.preferredSize = [100,25];
loadButton.onClick = function(){
};
var sideNotesField = noteFieldPanel.add("edittext", undefined);
sideNotesField.preferredSize = [282.5,75];
var closeButtonPanel = mainPanel.add("panel", undefined);
var closeButton = closeButtonPanel.add("button", undefined, "Close");
closeButton.preferredSize = [100,25];
closeButton.onClick = function(){
noteWindow.hide();
};
var infoWindow = new Window("palette", "AE Note - Info", undefined, {
resizeable: false, closeButton: false
});
var mainPanel = infoWindow.add("panel", undefined);
var stepsScriptDescriptionAndCopyrightPanel = mainPanel.add("panel", undefined);
var stepsPanel = stepsScriptDescriptionAndCopyrightPanel.add("panel", undefined);
var stepOneGroup = stepsPanel.add("group", undefined, "stepOneGroup");
stepOneGroup.alignment = "left";
var stepOneName = stepOneGroup.add("statictext", undefined, "Step 1:");
var stepOneContent = stepOneGroup.add("statictext", undefined, "Click the 'Note' button.");
var stepTwoGroup = stepsPanel.add("group", undefined, "stepTwoGroup");
stepTwoGroup.alignment = "left";
var stepTwoName = stepTwoGroup.add("statictext", undefined, "Step 2:");
var stepTwoContent = stepTwoGroup.add("statictext", undefined, "Note everything down that you need to remember.");
var stepThreeGroup = stepsPanel.add("group", undefined, "stepTwoGroup");
stepThreeGroup.alignment = "left";
var stepThreeName = stepThreeGroup.add("statictext", undefined, "Step 3:");
var stepThreeContent = stepThreeGroup.add("statictext", undefined, "Click the 'Save' button.");
var stepFourGroup = stepsPanel.add("group", undefined, "stepFourGroup");
stepFourGroup.alignment = "left";
var stepFourName = stepFourGroup.add("statictext", undefined, "Step 4:");
var stepFourContent = stepFourGroup.add("statictext", undefined, "Click the 'Load' button.");
var scriptDescriptionAndCopyrightPanel = stepsScriptDescriptionAndCopyrightPanel.add("panel", undefined);
var scriptDescriptionPOne = scriptDescriptionAndCopyrightPanel.add("statictext", undefined, "This script allows you to note information down that you need to remember without leaving the program.");
var scriptDescriptionPOne = scriptDescriptionAndCopyrightPanel.add("statictext", undefined, "You can save notes to a text file and load notes from a text file.");
var copyright = scriptDescriptionAndCopyrightPanel.add("statictext", undefined, "© B-films (VFX Department) 2019 - Bram Hoekstra(CEO)");
var closeButtonPanel = mainPanel.add("panel", undefined);
var closeButton = closeButtonPanel.add("button", undefined, "Close");
closeButton.preferredSize = [100,25];
closeButton.onClick = function(){
infoWindow.hide();
};
mainWindow.onResizing = mainWindow.onResize = function(){
this.layout.resize();
};
if(mainWindow instanceof Window){
mainWindow.center();
mainWindow.show();
};
else{
mainWindow.layout.layout(true);
mainWindow.layout.resize();
};
};
})(this);
Copy link to clipboard
Copied
How your program works exactly is up to you. If you have a read button and a write button somewhere, I'd recommend attaching these functions to their .onClick() methods:
// set this variable to your file path
var myFile = new File('path/to/my/file');
// set this variable to your editText element
var myEditText = ______;
function writeText(){
// Get text
var myText = myEditText;
// Write File
myFile.open('w', undefined, undefined);
var writeResult = myFile.write(myText);
myFile.close();
}
function readText(){
// Read File
myFile.open('r', undefined, undefined);
var newText = myFile.read(myText);
myFile.close();
// Set text
myEditText = newText;
}
Copy link to clipboard
Copied
I don't understand why, but it doesn't work for me. I get this error at the following line.
var newText = myFile.read(myText);
Can you explain why I get this error?
Copy link to clipboard
Copied
My bad, I made a typo. Read returns the result, you don't pass it anything. Change that to
var newText = myFile.read();
Also, make sure you're setting the file path correctly. You can check with something like alert(myFile.exists).
Copy link to clipboard
Copied
I don't get an error this time, but it also doesn't save or loads anything into the edittext field.
Do you know how to fix this?
Copy link to clipboard
Copied
Did you set the edittext variable and a valid file path? Can you post the code you're using now?
Copy link to clipboard
Copied
(function(thisObj){
aen(thisObj);
function aen(thisObj){
var mainWindow = (thisObj instanceof Panel) ? thisObj : new Window("palette", "AE Note", undefined, {
resizeable: false, closeButton: true
});
var mainPanel = mainWindow.add("panel", undefined);
var noteButtonPanel = mainPanel.add("panel", undefined);
var noteButton = noteButtonPanel.add("button", undefined, "Note");
noteButton.preferredSize = [100,25];
noteButton.onClick = function(){
noteWindow.show();
};
var infoButtonPanel = mainPanel.add("panel", undefined);
var infoButton = infoButtonPanel.add("button", undefined, "Info");
infoButton.preferredSize = [100,25];
infoButton.onClick = function(){
infoWindow.show();
};
var noteWindow = new Window("palette", "AE Note - Note", undefined, {
resizeable: false, closeButton: false
});
var mainPanel = noteWindow.add("panel", undefined);
var noteFieldPanel = mainPanel.add("panel", undefined);
var mainNotesHeadGroup = noteFieldPanel.add("group", undefined, "mainNotesHeadGroup");
mainNotesHeadGroup.orientation= "row";
mainNotesHeadGroup.alignment = "left";
var mainNotesHeadGroupName = mainNotesHeadGroup.add("statictext", undefined, "Main Notes:");
var myFile = new File('C:\AE Note_DATA\DATA_MN.txt');
var myEditText = mainNotesField;
var saveButton = mainNotesHeadGroup.add("button", undefined, "Save");
saveButton.preferredSize = [100,25];
saveButton.onClick = function(){
var myText = myEditText;
myFile.open('w', undefined, undefined);
var writeResult = myFile.write();
myFile.close();
};
var loadButton = mainNotesHeadGroup.add("button", undefined, "Load");
loadButton.preferredSize = [100,25];
loadButton.onClick = function(){
myFile.open('r', undefined, undefined);
var newText = myFile.read();
myFile.close();
myEditText = newText;
};
var mainNotesField = noteFieldPanel.add("edittext", undefined);
mainNotesField.preferredSize = [300,100];
mainNotesField.alignment = "left";
var sideNotesHeadGroup = noteFieldPanel.add("group", undefined);
sideNotesHeadGroup.orientation= "row";
sideNotesHeadGroup.alignment = "left";
var sideNotesHeadGroupName = sideNotesHeadGroup.add("statictext", undefined, "Side Notes:");
var myFile = new File('C:\AE Note_DATA\DATA_SN.txt');
var myEditText = sideNotesField;
var saveButton = sideNotesHeadGroup.add("button", undefined, "Save");
saveButton.preferredSize = [100,25];
saveButton.onClick = function(){
var myText = myEditText;
myFile.open('w', undefined, undefined);
var writeResult = myFile.write();
myFile.close();
};
var loadButton = sideNotesHeadGroup.add("button", undefined, "Load");
loadButton.preferredSize = [100,25];
loadButton.onClick = function(){
myFile.open('r', undefined, undefined);
var newText = myFile.read();
myFile.close();
myEditText = newText;
};
var sideNotesField = noteFieldPanel.add("edittext", undefined);
sideNotesField.preferredSize = [300,100];
sideNotesField.alignment = "left";
var closeButtonPanel = mainPanel.add("panel", undefined);
var closeButton = closeButtonPanel.add("button", undefined, "Close");
closeButton.preferredSize = [100,25];
closeButton.onClick = function(){
noteWindow.hide();
};
var infoWindow = new Window("palette", "AE Note - Info", undefined, {
resizeable: false, closeButton: false
});
var mainPanel = infoWindow.add("panel", undefined);
var stepsScriptDescriptionAndCopyrightPanel = mainPanel.add("panel", undefined);
var stepsPanel = stepsScriptDescriptionAndCopyrightPanel.add("panel", undefined);
var stepOneGroup = stepsPanel.add("group", undefined, "stepOneGroup");
stepOneGroup.alignment = "left";
var stepOneName = stepOneGroup.add("statictext", undefined, "Step 1:");
var stepOneContent = stepOneGroup.add("statictext", undefined, "Click the 'Note' button.");
var stepTwoGroup = stepsPanel.add("group", undefined, "stepTwoGroup");
stepTwoGroup.alignment = "left";
var stepTwoName = stepTwoGroup.add("statictext", undefined, "Step 2:");
var stepTwoContent = stepTwoGroup.add("statictext", undefined, "Note everything down that you need to remember.");
var stepThreeGroup = stepsPanel.add("group", undefined, "stepTwoGroup");
stepThreeGroup.alignment = "left";
var stepThreeName = stepThreeGroup.add("statictext", undefined, "Step 3:");
var stepThreeContent = stepThreeGroup.add("statictext", undefined, "Click the 'Save' button.");
var stepFourGroup = stepsPanel.add("group", undefined, "stepFourGroup");
stepFourGroup.alignment = "left";
var stepFourName = stepFourGroup.add("statictext", undefined, "Step 4:");
var stepFourContent = stepFourGroup.add("statictext", undefined, "Click the 'Load' button.");
var scriptDescriptionAndCopyrightPanel = stepsScriptDescriptionAndCopyrightPanel.add("panel", undefined);
var scriptDescriptionPOne = scriptDescriptionAndCopyrightPanel.add("statictext", undefined, "This script allows you to note information down that you need to remember without leaving the program.");
var scriptDescriptionPOne = scriptDescriptionAndCopyrightPanel.add("statictext", undefined, "You can save notes to a text file and load notes from a text file.");
var copyright = scriptDescriptionAndCopyrightPanel.add("statictext", undefined, "© B-films (VFX Department) 2019 - Bram Hoekstra(CEO)");
var closeButtonPanel = mainPanel.add("panel", undefined);
var closeButton = closeButtonPanel.add("button", undefined, "Close");
closeButton.preferredSize = [100,25];
closeButton.onClick = function(){
infoWindow.hide();
};
mainWindow.onResizing = mainWindow.onResize = function(){
this.layout.resize();
};
if(mainWindow instanceof Window){
mainWindow.center();
mainWindow.show();
};
else{
mainWindow.layout.layout(true);
mainWindow.layout.resize();
};
};
})(this);
Copy link to clipboard
Copied
Always use double backslashes in Javascript/ExtendScript to represent the single backslash for Windows paths, otherwise, it's interpreted as escaping characters:
var myFile = new File('C:\\AE Note_DATA\\DATA_MN.txt');
Also, you need to define mainNotesField before setting myEditText to it, or just do away with myEditText altogether and replace references with mainNotesField.
Copy link to clipboard
Copied
It still doesn't work.
Copy link to clipboard
Copied
It finally worked after trying over and over again. Thx!!!
Copy link to clipboard
Copied
Glad to hear that! What was the fix?
Copy link to clipboard
Copied
I will show you my code:
(function(thisObj){
aen(thisObj);
function aen(thisObj){
var mainWindow = (thisObj instanceof Panel) ? thisObj : new Window("palette", "AE Note", undefined, {
resizeable: false, closeButton: true
});
var mainPanel = mainWindow.add("panel", undefined);
var noteButtonPanel = mainPanel.add("panel", undefined);
var noteButton = noteButtonPanel.add("button", undefined, "Note");
noteButton.preferredSize = [100,25];
noteButton.onClick = function(){
noteWindow.show();
};
var infoButtonPanel = mainPanel.add("panel", undefined);
var infoButton = infoButtonPanel.add("button", undefined, "Info");
infoButton.preferredSize = [100,25];
infoButton.onClick = function(){
infoWindow.show();
};
var noteWindow = new Window("palette", "AE Note - Note", undefined, {
resizeable: false, closeButton: false
});
var mainPanel = noteWindow.add("panel", undefined);
var noteFieldPanel = mainPanel.add("panel", undefined);
var mainNotesHeadGroup = noteFieldPanel.add("group", undefined, "mainNotesHeadGroup");
mainNotesHeadGroup.orientation = "row";
mainNotesHeadGroup.alignment = "left";
var mainNotesName = mainNotesHeadGroup.add("statictext", undefined, "Main Notes:");
var dataMn = new File('~\\Documents\\AE Note_DATA\\AE Note_DATA_MN.txt');
var saveButton = mainNotesHeadGroup.add("button", undefined, "Save");
saveButton.preferredSize = [100,25];
saveButton.onClick = function(){
var myText = mainNotesField.text;
dataMn.open('w', undefined, undefined);
var writeResult = dataMn.write(myText);
dataMn.close();
};
var loadButton = mainNotesHeadGroup.add("button", undefined, "Load");
loadButton.preferredSize = [100,25];
loadButton.onClick = function(){
dataMn.open('r', undefined, undefined);
var newText = dataMn.read();
dataMn.close();
mainNotesField.text = newText;
};
var mainNotesField = noteFieldPanel.add("edittext", undefined, '', {
multiline:true,
});
mainNotesField.preferredSize = [375,125];
mainNotesField.alignment = "left";
var sideNotesHeadGroup = noteFieldPanel.add("group", undefined, "sideNotesHeadGroup");
sideNotesHeadGroup.orientation = "row";
sideNotesHeadGroup.alignment = "left";
var sideNotesName = sideNotesHeadGroup.add("statictext", undefined, "Side Notes:");
var dataSn = new File('~\\Documents\\AE Note_DATA\\AE Note_DATA_SN.txt');
var saveButton = sideNotesHeadGroup.add("button", undefined, "Save");
saveButton.preferredSize = [100,25];
saveButton.onClick = function(){
var myText = sideNotesField.text;
dataSn.open('w', undefined, undefined);
var writeResult = dataSn.write(myText);
dataSn.close();
};
var loadButton = sideNotesHeadGroup.add("button", undefined, "Load");
loadButton.preferredSize = [100,25];
loadButton.onClick = function(){
dataSn.open('r', undefined, undefined);
var newText = dataSn.read();
dataSn.close();
sideNotesField.text = newText;
};
var sideNotesField = noteFieldPanel.add("edittext", undefined, '', {
multiline:true
});
sideNotesField.preferredSize = [375,125];
sideNotesField.alignment = "left";
var closeButtonPanel = mainPanel.add("panel", undefined);
var closeButton = closeButtonPanel.add("button", undefined, "Close");
closeButton.preferredSize = [100,25];
closeButton.onClick = function(){
noteWindow.hide();
};
var infoWindow = new Window("palette", "AE Note - Info", undefined, {
resizeable: false, closeButton: false
});
var mainPanel = infoWindow.add("panel", undefined);
var stepsScriptDescriptionAndCopyrightPanel = mainPanel.add("panel", undefined);
var stepsPanel = stepsScriptDescriptionAndCopyrightPanel.add("panel", undefined);
var stepOneGroup = stepsPanel.add("group", undefined, "stepOneGroup");
stepOneGroup.alignment = "left";
var stepOneName = stepOneGroup.add("statictext", undefined, "Step 1:");
var stepOneContent = stepOneGroup.add("statictext", undefined, "Click the 'Note' button.");
var stepTwoGroup = stepsPanel.add("group", undefined, "stepTwoGroup");
stepTwoGroup.alignment = "left";
var stepTwoName = stepTwoGroup.add("statictext", undefined, "Step 2:");
var stepTwoContent = stepTwoGroup.add("statictext", undefined, "Note all information that you need to remember.");
var stepThreeGroup = stepsPanel.add("group", undefined, "stepThreeGroup");
stepThreeGroup.alignment = "left";
var stepThreeName = stepThreeGroup.add("statictext", undefined, "Step 3:");
var stepThreeContent = stepThreeGroup.add("statictext", undefined, "Click the 'Save' button.");
var stepFourGroup = stepsPanel.add("group", undefined, "stepFourGroup");
stepFourGroup.alignment = "left";
var stepFourName = stepFourGroup.add("statictext", undefined, "Step 4:");
var stepFourContent = stepFourGroup.add("statictext", undefined, "Click the 'Load' button.");
var scriptDescriptionAndCopyrightPanel = stepsScriptDescriptionAndCopyrightPanel.add("panel", undefined);
var scriptDescriptionPOne = scriptDescriptionAndCopyrightPanel.add("statictext", undefined, "This script allows you to note all information that you need to remember without having to leave the program.");
var copyright = scriptDescriptionAndCopyrightPanel.add("statictext", undefined, "© B-films (VFX Department) 2019 - Bram Hoekstra(CEO)");
var closeButtonPanel = mainPanel.add("panel", undefined);
var closeButton = closeButtonPanel.add("button", undefined, "Close");
closeButton.preferredSize = [100,25];
closeButton.onClick = function(){
infoWindow.hide();
};
mainWindow.onResizing = mainWindow.onResize = function(){
this.layout.resize();
};
if(mainWindow instanceof Window){
mainWindow.center();
mainWindow.show();
};
else{
mainWindow.layout.layout(true);
mainWindow.layout.resize();
};
};
})(this);
I'm not sure how to explain but it works!!!