Quantcast
Channel: Adobe Community : Discussion List - After Effects Scripting
Viewing all articles
Browse latest Browse all 2143

Progress Bars On AE CC15

$
0
0

Hi there,

 

 

I'm creating a script that duplicates a folder and all of its items and goes through each comp and replaces its layers, fixes expressions etc... I'm quite a beginner and have been doing quite well till yesterday, creating the progress bar for my script is where I'm stuck. My script's UI is dock-able and it has a button that triggers the script and creates a palette window where the progress bar is shown on. Inside the for loops that takes most of the time that the script needs (the script takes 2-3 minutes for the project I'm testing the script on), I increase both of the maxvalue and the value of the progress bar. So far nothing wrong, but in AE CC15 (my OS is Windows 10) the palette window crashes (I mean by that it shows "(Not Responding)" on the palette window's title bar) after a few seconds thus the progress bar doesn't update itself anymore. When the script finishes the operation, the progress bar goes to its max value right away. I tested the script on AE CS5.5 and that doesn't happen.

 

Why does the palette window crash? Is this a bug in CC15?

 

I don't want to share all of my code here, I don't want my script's source code to be online, so here is something I can share:

{  function TrueFoldersDuplicatorScript (thisObj) {  function CreateProgressBar () { // This function creates the progress bar's palette window  var w = new Window("palette", "Progress", undefined);  var res = "group{orientation:'column', alignment:['fill','fill'],\  Grp: Group{orientation:'row', alignment:['fill','fill'],\  pb: Progressbar{text: 'Progressbar', alignment:['fill','fill']},\  percenText: StaticText{text: '', alignment:['center','center']},\  },\  pbText: StaticText{text: '', alignment:['fill','fill']},\  okb: Button{text: 'Ok'},\  }";  w.grp = w.add(res);  w.grp.Grp.pb.maxvalue = 0;  w.grp.Grp.pb.minimumSize = [250, 10];  w.grp.Grp.pb.value = 0;  w.grp.pbText.text = "Please wait...";  w.grp.Grp.percenText.text = "00.00%";  w.grp.okb.enabled = false;  w.grp.okb.onClick = function () {this.window.close()}  w.center();  w.show();  return {  theText: function(STR){w.grp.pbText.text = STR; w.update()},  thePercnText: function(str){w.grp.Grp.percenText.text = str; w.update()},  w:w,  SetMax: function(max){w.grp.Grp.pb.maxvalue += max; w.update()}, //Resets the max value  Increment: function(){w.grp.Grp.pb.value += 1; w.update()}, //Increases the value   Finished: function(){w.grp.okb.enabled = true;},  pbValue: function(){return w.grp.Grp.pb.value},  pbMaxValue: function(){return w.grp.Grp.pb.maxvalue},  }  }  function ButtonOnClickDuplicateFunction (panel) {  var SelectedItems = app.project.selection;  if (SelectedItems.length === 1 && SelectedItems[0] instanceof FolderItem) {  var PB = CreateProgressBar (); // Calling the function that creates the palette window  var SelectedItems = app.project.selection;  for (var c = 0; c < SelectedItems.length; c++) {  if (SelectedItems[c] instanceof FolderItem) {  var newFolder = DuplicateFolder(SelectedItems[c], PB); //Duplicates the original folder and its content  var copyFolderItems = allItemsInFolder(newFolder); //Every comp, solid, footage in the new folder  var origFolderItems = allItemsInFolder(SelectedItems[c]); ////Every comp, solid, footage in the original folder  PB.SetMax(copyFolderItems.length); //Increases the max value  PB.thePercnText((Math.round((PB.pbValue() / PB.pbMaxValue()) * 10000) / 100).toString() + "%");  for (var k = 0; k < copyFolderItems.length; k++) {  if (copyFolderItems[k] instanceof CompItem) {  PB.SetMax(copyFolderItems[k].numLayers);  PB.thePercnText((Math.round((PB.pbValue() / PB.pbMaxValue()) * 10000) / 100).toString() + "%");  for (var j = 1; j <= copyFolderItems[k].numLayers; j++) {  //Replaces each comp's layers in the new folder using layer.replaceSource()  PB.Increment(); //Increases the value  PB.thePercnText(((Math.round((PB.pbValue() / PB.pbMaxValue()) * 10000) / 100).toString() + "%"));  }  }  PB.Increment();  PB.thePercnText(((Math.round((PB.pbValue() / PB.pbMaxValue()) * 10000) / 100).toString() + "%"));  }  PB.SetMax(copyFolderItems.length);  PB.thePercnText((Math.round((PB.pbValue() / PB.pbMaxValue()) * 10000) / 100).toString() + "%");  for (var g = 0; g < copyFolderItems.length; g++) { //Fixes all the expressions in the new folder  if (copyFolderItems[g] instanceof CompItem) {  for (var t = 1; t <= copyFolderItems[g].numLayers; t++) {  fixExpressions(copyFolderItems[g].layer(t), copyFolderItems, origFolderItems);  }  }  PB.Increment();  PB.thePercnText(((Math.round((PB.pbValue() / PB.pbMaxValue()) * 10000) / 100).toString() + "%"));  }  }  }  PB.Finished();  PB.thePercnText((Math.round((PB.pbValue() / PB.pbMaxValue()) * 10000) / 100).toString() + "%");  PB.theText("All Done!");  }  function DuplicateFolder(Folder, PrB) {  var newFolder = app.project.items.addFolder(Folder.name);  PrB.SetMax(Folder.numItems);  for (var b = 1; b <= Folder.numItems; b++) {  //Duplicates every item in a folder  PrB.Increment();  }  return newFolder;  }  function allItemsInFolder(aFolder) {  var Items = new Array();  //returns an array with everything in a folder  }  function fixExpressions (aProp, copyFolderItems, origFolderItems) {  //Fixes expressions  }  }  function numCopiesTextChange() {  numCopiesTextValue = this.text;  }  function TrueFolderDuplicatorScript_buildUI(thisObj) { //The dock-able UI of the script  var panel = (thisObj instanceof Panel) ? thisObj : new Window("palette", "Window Name", undefined, {resizeable:true});  var res = "group{orientation:'column', alignment:['left','top'],\  mainPanel: Panel {orientation:'column', alignment:['fill','fill'],\  FirstGroup: Group{orientation:'row', alignment:['fill','bottom'],\  numCopies: EditText{text: '1', alignment:['left','fill']},\  numCopiesText: StaticText{text: 'Copies', alignment:['left','center']},\  },\  SecGroup: Group{orientation:'row', alignment:['fill','bottom'],\  solidsCheckBox: Checkbox{text: 'Duplicate Solids', value: true, alignment:['left','fill']},\  footageCheckBox: Checkbox{text: 'Duplicate Footage', value: false, alignment:['left','fill']},\  },\  replaceButton: Button{text: 'Duplicate!', alignment:['center','bottom']},\  },\  }";  panel.grp = panel.add(res);  panel.grp.mainPanel.FirstGroup.numCopies.minimumSize = [23,15];  panel.layout.layout(true);  panel.grp.minimumSize = panel.grp.size;  panel.layout.resize();  panel.onResizing = panel.onResize = function () {this.layout.resize();}  solidsCheckBoxValue = true;  footageCheckBoxValue = false;  panel.grp.mainPanel.SecGroup.solidsCheckBox.onClick = function () {solidsCheckBoxValue = panel.grp.mainPanel.SecGroup.solidsCheckBox.value};  panel.grp.mainPanel.SecGroup.footageCheckBox.onClick = function () {footageCheckBoxValue = panel.grp.mainPanel.SecGroup.footageCheckBox.value};  panel.grp.mainPanel.FirstGroup.numCopies.onChange = panel.grp.mainPanel.FirstGroup.numCopies.onChanging = numCopiesTextChange;  panel.grp.mainPanel.replaceButton.onClick = function () {  app.beginUndoGroup("Duplicate Folder");  ButtonOnClickDuplicateFunction(panel);  app.endUndoGroup();  }  return panel;  }  var TrueFolderDuplicatorScriptPal = TrueFolderDuplicatorScript_buildUI(thisObj);  if(TrueFolderDuplicatorScriptPal != null && TrueFolderDuplicatorScriptPal instanceof Window) {  TrueFolderDuplicatorScriptPal.center();  TrueFolderDuplicatorScriptPal.show();  }  }  TrueFoldersDuplicatorScript(this);

}

Thanks!

 

Message was edited by: Osama Sa


Viewing all articles
Browse latest Browse all 2143


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>