Script UI layer selection not updating after restarting AE
I am making a dockable UI and I have two StaticText objects in my UI where I display certain information and one of them is number of selected layers.
I also have a refresh button that updates their text values.
When I restart or open another project while the script is docked it doesn't recognize any kind of layer selections. I have to close the script and open it again for the selection to work.
function curios_buildUI(thisObj)
{
var myPanel = (thisObj instanceof Panel) ? thisObj : new Window("palette", "Curios Name Changer", undefined, {resizeable:true});
res = "group{orientation:'column', alignment:['fill','center'], alignChildren:['fill','fill'],\
groupOne: Group{orientation:'row',\
staticText1: StaticText{text: 'Imported: 0', characters: 12},\
staticText2: StaticText{text: 'Selected: 0', characters: 11},\
},\
groupTwo: Group{orientation:'row',\
button1: Button{text: 'Import'},\
button2: Button{text: 'Execute'},\
},\
groupThree: Group{orientation:'row',\
button3: Button{text: 'Refresh'},\
button4: Button{text: 'Help?'},\
},\
}";
myPanel.grp = myPanel.add(res);
//Defaults
myPanel.grp.groupOne.staticText1.text = "Imported: " + 0;
myPanel.grp.groupOne.staticText2.text = "Selected: " + 0;
updateTexts();
//Sizing
myPanel.layout.layout(true);
myPanel.grp.minimumSize = myPanel.grp.size;
myPanel.layout.resize();
myPanel.onResizing = myPanel.onResize = function()
{
this.layout.resize();
}
myPanel.grp.groupThree.button3.onClick = function()
{
updateTexts();
}
function updateTexts()
{
var select;
try
{
select = mainComp.selectedLayers;
}
catch (e) {}
myPanel.grp.groupOne.staticText1.text = "Imported: " + names.length;
if(select != null)
myPanel.grp.groupOne.staticText2.text = "Selected: " + select.length;
else
myPanel.grp.groupOne.staticText2.text = "Selected: " + 0;
}
myPanel.layout.layout(true);
return myPanel;
}