Copy link to clipboard
Copied
After Effects CC 2019
What I'm trying to make is to rename the selected layer in current comp.
But now I found that activeItem.selectedLayers would only refresh when I open this script.
How to make the selection refresh in realtime?
/*
Naming Manager
#V1.1 fix Dockable problem
*/
function NamingManagerScript(thisObj) {
function NamingManagerUI(thisObj) {
var NamingManagerPanel = (thisObj instanceof Panel) ? thisObj : new Window("palette", "Dockable Script", undefined, {
resizeable: true,
closeButton: true
});
res = "group{orientation:'column',\
AutoIncre_grp: Group{orientation:'row',\
AutoIncre_text: StaticText{text: 'Auto Increment'},\
AutoIncre_text_Checkbox: Checkbox{text: 'On/Off'},\
AutoIncre_Input_text: EditText{text: '$num',enabled:false},\
},\
Prefix_grp: Group{orientation:'row',\
Prefix_text: StaticText{text:'Prefix Input'},\
Prefix_Input_text: EditText{text:'', size:[100,20]},\
Prefix_Button: Button{text:'Execute'},\
},\
Suffix_grp: Group{orientation:'row',\
Suffix_text: StaticText{text:'Suffix Input'},\
Suffix_Input_text: EditText{text:'', size:[100,20]},\
Suffix_Button: Button{text:'Execute'},\
},\
Replace_grp: Group{orientation:'row',\
Replace_text_01: StaticText{text: 'Replace from'},\
Replace_Input_text_01: EditText{text: '', size:[100,20]},\
Replace_text_02: StaticText{text: 'to'},\
Replace_Input_text_02: EditText{text: '', size:[100,20]},\
Replace_Button: Button{text: 'Execute'},\
},\
Whole_grp: Group{orientation:'row',\
Whole_text: StaticText{text: 'Whole Input'},\
Whole_Input_text: EditText{text: '', size:[100,20]},\
Whole_Button: Button{text: 'Execute'},\
},\
},\
";
NamingManagerPanel.grp = NamingManagerPanel.add(res);
var lyrsArray = app.project.activeItem.selectedLayers;
//lyrsArray is not updated on realtime, maybe should be write a rule to force it update
var cntArray = lyrsArray.length;
function AddAutoIncre() {
j = i + 1;
lyrsArray[i].name = lyrsArray[i].name.replace("$num", j);
}
function AddPrefix() {
for (i = 0; i < cntArray; i++) {
lyrsArray[i].name = NamingManagerPanel.grp.Prefix_grp.Prefix_Input_text.text + lyrsArray[i].name;
if (AutoIncre_text_Checkbox.value == true) {
AddAutoIncre();
}
}
}
function AddSuffix() {
for (i = 0; i < cntArray; i++) {
lyrsArray[i].name = NamingManagerPanel.grp.Suffix_grp.Suffix_Input_text.text + lyrsArray[i].name;
if (AutoIncre_text_Checkbox.value == true) {
AddAutoIncre();
}
}
}
function AddReplace() {
for (i = 0; i < cntArray; i++) {
lyrsArray[i].name = lyrsArray[i].name.replace(NamingManagerPanel.grp.Replace_grp.Replace_Input_text_01.text, NamingManagerPanel.grp.Replace_grp.Replace_Input_text_02.text);
if (AutoIncre_text_Checkbox.value == true) {
AddAutoIncre();
}
}
}
function AddWhole() {
for (i = 0; i < cntArray; i++) {
lyrsArray[i].name = NamingManagerPanel.grp.Whole_grp.Whole_Input_text.text;
if (AutoIncre_text_Checkbox.value == true) {
AddAutoIncre();
}
}
}
//Add onClick Events
NamingManagerPanel.grp.Prefix_grp.Prefix_Button.onClick = function() {
AddPrefix();
};
NamingManagerPanel.grp.Suffix_grp.Suffix_Button.onClick = function() {
AddSuffix();
};
NamingManagerPanel.grp.Replace_grp.Replace_Button.onClick = function() {
AddReplace();
};
NamingManagerPanel.grp.Whole_grp.Whole_Button.onClick = function() {
AddWhole();
};
NamingManagerPanel.layout.layout(true);
return NamingManagerPanel;
}
var NamingManagerScriptPal = NamingManagerUI(thisObj);
if (NamingManagerScriptPal != null && NamingManagerScriptPal instanceof Window) {
NamingManagerScriptPal.center();
NamingManagerScriptPal.show();
}
}
NamingManagerScript(this);
Kind of that.
You may can use the evenlistener "mouseover" on your UI, to trigger the update function. Of course this only makes sense, if the user is about to interact with your script anyway and if the function isn't heavy and isn't changing anything in your project. You don't want AE to freeze, or altering your work when just moving your mouse over the UI.
mainPanel.addEventListener("mouseover", UpdateTextCreateProcessComp);
In this case, mainPanel is my top-most UI element (hierarchy),
...Copy link to clipboard
Copied
All scripts in AE are modal. There is no such thing as realtime updates. It always requires the push of a button or call to a specific function to trigger something in AE for the simple fact that by itself it has no such thing as event listeners that would update the UI interactively. It's a limitation you have to live with.
Mylenium
Copy link to clipboard
Copied
So that means I have to like :
1.Add a button named "Refresh"
2.Write a function that everytime "Refresh" Button is pressed, re-assign the current selection of my layers to the varieble LayersArray
3.Use the new LayersArray to do what the script does
Did I understand what you mean:P?
Copy link to clipboard
Copied
Kind of that.
You may can use the evenlistener "mouseover" on your UI, to trigger the update function. Of course this only makes sense, if the user is about to interact with your script anyway and if the function isn't heavy and isn't changing anything in your project. You don't want AE to freeze, or altering your work when just moving your mouse over the UI.
mainPanel.addEventListener("mouseover", UpdateTextCreateProcessComp);
In this case, mainPanel is my top-most UI element (hierarchy), it's the most outer border of my script UI and you'll definitely enter it, when moving the mouse into the UI.
UpdateTextCreateProcessComp does a lot of things, including checking what items are selected in comp/project panel and updates a dropdown and static text, if those items are layers/comps.
This update is hidden from the user, since there is no button to manual triggering it. You just have a dropdown, which always represent the current status of the selection when you are going to interact with the script.
I think this is a bit more elegant, than having a "refresh"-button.
*Martin
Copy link to clipboard
Copied
Problem solved! Much thanks to you and Mylenium!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now