Skip to main content
Known Participant
August 22, 2021
Answered

To add progress bar in the script

  • August 22, 2021
  • 1 reply
  • 2554 views

Hi All,

I want to add the progress bar in the below code which is UI functionality the part of my Folder Automation Script. As of now the main UI has been greyed out until the files move from the input folder to Output folder. Its not more interactive. Is it possible to add the progress bar until the copyfile function to complete the process?

mainUI();
function mainUI(){
    var dialog = new Window("dialog"); 
        dialog.text = "Partner Asset Automator"; 
        dialog.orientation = "column"; 
        dialog.alignChildren = ["center","top"]; 
        dialog.spacing = 10; 
        dialog.margins = 16; 

    // PANEL1
    // ======
    var panel1 = dialog.add("panel", undefined, undefined, {name: "panel1"}); 
        panel1.text = "Asset Matrix CSV file"; 
        panel1.orientation = "column"; 
        panel1.alignChildren = ["left","top"]; 
        panel1.spacing = 10; 
        panel1.margins = 10; 

    // GROUP1
    // ======
    var group1 = panel1.add("group", undefined, {name: "group1"}); 
        group1.orientation = "row"; 
        group1.alignChildren = ["left","center"]; 
        group1.spacing = 10; 
        group1.margins = 0; 

    var editPath1 = group1.add('edittext {properties: {name: "edittext1", multiline: true, scrollable: true}}'); 
        editPath1.preferredSize.width = 350; 
        editPath1.preferredSize.height = 40; 

    var pathBrowse1 = group1.add("button", undefined, undefined, {name: "button1"}); 
        pathBrowse1.text = "Browse"; 

    // PANEL2
    // ======
    var panel2 = dialog.add("panel", undefined, undefined, {name: "panel2"}); 
        panel2.text = "WW_Handoffs Folder"; 
        panel2.orientation = "column"; 
        panel2.alignChildren = ["left","top"]; 
        panel2.spacing = 10; 
        panel2.margins = 10; 

    // GROUP2
    // ======
    var group2 = panel2.add("group", undefined, {name: "group2"}); 
        group2.orientation = "row"; 
        group2.alignChildren = ["left","center"]; 
        group2.spacing = 10; 
        group2.margins = 0; 

    var editPath2 = group2.add('edittext {properties: {name: "edittext2", multiline: true, scrollable: true}}'); 
        editPath2.preferredSize.width = 350; 
        editPath2.preferredSize.height = 40; 

    var pathBrowse2 = group2.add("button", undefined, undefined, {name: "button2"}); 
        pathBrowse2.text = "Browse"; 

    // PANEL3
    // ======
    var panel3 = dialog.add("panel", undefined, undefined, {name: "panel3"}); 
        panel3.text = "Output Folder"; 
        panel3.orientation = "column"; 
        panel3.alignChildren = ["left","top"]; 
        panel3.spacing = 10; 
        panel3.margins = 10; 

    // GROUP3
    // ======
    var group3 = panel3.add("group", undefined, {name: "group3"}); 
        group3.orientation = "row"; 
        group3.alignChildren = ["left","center"]; 
        group3.spacing = 10; 
        group3.margins = 0; 

    var editPath3 = group3.add('edittext {properties: {name: "edittext3",  multiline: true, scrollable: true}}'); 
        editPath3.preferredSize.width = 350; 
        editPath3.preferredSize.height = 40; 

    var pathBrowse3 = group3.add("button", undefined, undefined, {name: "button3"}); 
        pathBrowse3.text = "Browse"; 

    // GROUP4
    // ======
    var group4 = dialog.add("group", undefined, {name: "group4"}); 
        group4.orientation = "row"; 
        group4.alignChildren = ["left","center"]; 
        group4.spacing = 10; 
        group4.margins = 0; 

    var Start_Button = group4.add("button", undefined, undefined, {name: "button4"}); 
        Start_Button.text = "Start"; 

    var Stop_Button = group4.add("button", undefined, undefined, {name: "button5"}); 
        Stop_Button.text = "Cancel"; 

    //--------------------------------------------------------------------------------
    pathBrowse1.onClick = function(){
        AssetCSV_File = File.openDialog("Choose the Asset Matrix CSV File");
        if(AssetCSV_File != null){   
            editPath1.text = AssetCSV_File.fullName;
        }
    }
    //--------------------------------------------------------------------------------
    pathBrowse2.onClick = function(){
        Handoffs_Folder = Folder.selectDialog("Choose the WW_Handoffs Folder");
        if(Handoffs_Folder != null){   
            editPath2.text = Handoffs_Folder.fullName;
        }
    }
    //--------------------------------------------------------------------------------
    pathBrowse3.onClick = function(){
        OutputFolder = Folder.selectDialog("Choose the Output Folder");
        if(OutputFolder != null){   
            editPath3.text = OutputFolder.fullName;
        }
    }
    //--------------------------------------------------------------------------------
    Start_Button.onClick = function(){
        if(editPath1.text == "" || editPath2.text == "" || editPath3.text == ""){
            alert("Select the respective text fields and run the script...");
        }else{
            mainFlag = true;
            dialog.close(1);
        }
    }

    //--------------------------------------------------------------------------------
    Stop_Button.onClick = function(){
        dialog.close(0);
        alert("Process Cancelled...")
    }

    dialog.show();
}

//--------------------------------------------
if(mainFlag == true){
    GettingInputFromCSV_UI(File(AssetCSV_File.fullName));
    if(Replacement_Content_csv.length>0){//Replacement_Content_csv // Rules_styleMapping_csv
        for(var a=0;a<Replacement_Content_csv.length;a++){
            FolderNames.push(String(Replacement_Content_csv[a][0]));
            SubFolderNames.push(String(Replacement_Content_csv[a][1]));
        }
    }
// Progress bar need to add for this function
    folderCreation();
    copyFiles();
    alert("Process Completed...")
}

 

This topic has been closed for replies.
Correct answer brian_p_dts

what is progressbar value and how to update? Could you please explain in detail?

 


I provided above. For that case: 

var w = new Window('palette');
w.pbar = w.add('progressbar', undefined, 0, 2);
w.pbar.preferredSize.width = 300;
w.show();

folderCreation();
w.pbar.value++;
copyFiles();

w.pbar.value++;

1 reply

Peter Kahrel
Community Expert
Community Expert
August 23, 2021

File copying is very quick, usually just a few seconds. Are you sure you want a progress bar for that?

Rocky@Author
Known Participant
August 23, 2021

Copy File function copy the files from multiple input folder and paste into respective output folder based on the CSV file. It take more time to complete, for that only I have looking for the progress bar to more interactive for the user instead of the main UI greyed out until the process done.

brian_p_dts
Community Expert
Community Expert
August 23, 2021

We would need to know what your folderCreation and copyFiles functions look like but generally a progressbar looks like this, where lengthOfFolders is the numerical value for the maximum number of files to process: 

var w = new Window('palette');
        w.pbar = w.add('progressbar', undefined, 0, lengthOfFolders);
        w.pbar.preferredSize.width = 300;
        w.show(); 
for each operation {
        w.pbar.value++;
}

 

Peter also covers progressbars extensively in Script UI for Dummies