Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Help with mel progressBar, progress bar can be cancelled before it's started?

Help with mel progressBar, progress bar can be cancelled before it's started?

malcolm_341
Collaborator Collaborator
1,124 Views
9 Replies
Message 1 of 10

Help with mel progressBar, progress bar can be cancelled before it's started?

malcolm_341
Collaborator
Collaborator

I have a basic progress bar example here straight from the Maya help file. I'm having a problem though if I press Esc before I run the script the -isCancelled state is set to true which makes no sense, since the progress bar doesn't exist yet. What am I doing wrong here, because if I run this script once and let it finish everything is fine, but if I then press Esc before running it and run it again it thinks I tried to escape it in the middle of the loop which makes no sense. This seems totally broken?

 

 

global string $gMainProgressBar;
int $number = 100000;

progressBar -edit -beginProgress -isInterruptable true -status "Example Calculation ..." -maxValue $number $gMainProgressBar;

int $i;
for($i=0; $i < $number; $i++)
{
    if(`progressBar -query -isCancelled $gMainProgressBar`)
	break;
	progressBar -edit -step 1 $gMainProgressBar;
}

progressBar -edit -endProgress $gMainProgressBar;

 

0 Likes
1,125 Views
9 Replies
Replies (9)
Message 2 of 10

Kahylan
Advisor
Advisor

Hi!

 

So does the progressbar not show up if you press esc before starting the script? I tried to replicate the issue but couldn't, what Maya version are you using?

0 Likes
Message 3 of 10

malcolm_341
Collaborator
Collaborator

@Kahylanyes correct, the progress bar does not show up as if you immediately pressed escape. I've tested this thoroughly and it always happens. If I run the progress bar and press escape while the bar is in progress everything is fine, if I let the bar finish everything is fine. But if I let the bar finish and then press escape, the next time I execute the script it immediately quits and I need to run the script a second time to clear out the buffered escape press. I'm using Maya 2022.3

0 Likes
Message 4 of 10

Kahylan
Advisor
Advisor

Hmm. Thats weird, I really can't seem to reproduce the problem, I'm also on Maya 2022.3.

 

As far as I know both the -beginProgress and -endProgress flag set the -isCancelled flag to 0. So this really shouldn't happen.

 

I realised that you have some redundant variable declarations in your script, but I don't think they are causing the problem. But I took them out just in case. Could you try running this script?

int $number = 100000;
print("RUNNING");

progressBar -edit -beginProgress -isInterruptable true -status "Example Calculation ..." -maxValue $number $gMainProgressBar;

for($i=0; $i < $number; $i++)
{
    if(`progressBar -query -isCancelled $gMainProgressBar`)
	break;
	progressBar -edit -step 1 $gMainProgressBar;
	
	
}

progressBar -edit -endProgress $gMainProgressBar;

 

To see if the the printstatement gets executed on when the progressbar doesn't show up which would mean that -isCancelled doesn't reset for some reason or if it doesn't print which would mean the programm itself isn't running at all...

 

 

0 Likes
Message 5 of 10

malcolm_341
Collaborator
Collaborator

@Kahylanthanks for the test script, if I run it and press escape during the progress bar being visible everything is fine, but if I press escape before running the script it does not show the progress bar and does not print RUNNING and I have the run the script a second time before it works again. I've tried querying the isCancelled value and it's always 0 even when the script will fail to execute on the next run.

 

While the script doesn't execute if you press escape before running it, it does print this

// Result: HelpLine|MainHelpLineLayout|helpLineFrame|formLayout19|mainProgressBar

which is the same result I get if I cancel the script in progress, so for me it jumps right to the end of the script and skips the for loop that updates the progress bar

0 Likes
Message 6 of 10

Kahylan
Advisor
Advisor

Hmm. It's strange... So the printstatement tells us that for some reason the script isn't running from the top but you are righ the Result means that Maya did something. And I'm sorry but I have no clue why this is happening.

 

There is a last thing that I think would be worth trying out. Which is pack the script into a procedure and then calling the procedure at the end of the script, which is generally seen as a cleaner way of running stand alone scripts like this. I'm not sure if this will help, but it's worth a shot.

global proc displayBar(){
    global string $gMainProgressBar;
    int $number = 100000;
    print("RUNNING");
    
    
    progressBar -edit -beginProgress -isInterruptable true -status "Example Calculation ..." -maxValue $number $gMainProgressBar;
    
    for($i=0; $i < $number; $i++)
    {
        if(`progressBar -query -isCancelled $gMainProgressBar`)
    	break;
    	progressBar -edit -step 1 $gMainProgressBar;
    	
    	
    }
    
    progressBar -edit -endProgress $gMainProgressBar;
    }

displayBar();

I had to reintroduce the $progressBar variable declaration, because otherwise Maya would have searched for a local variable with the same name.

0 Likes
Message 7 of 10

malcolm_341
Collaborator
Collaborator

@Kahylanso putting it in the procedure does change the result, but doesn't fix the problem. In the procedure if you press escape before running it the script skips to the end and prints RUNNING, but nothing else happens and there is no progress bar. Very mysterious.

0 Likes
Message 8 of 10

zewt
Collaborator
Collaborator

I see this too.  I'm not sure of a workaround, but I'll report a bug.

 

Message 9 of 10

malcolm_341
Collaborator
Collaborator

@zewtThanks

0 Likes
Message 10 of 10

malcolm_341
Collaborator
Collaborator

So as a workaround you can use progressWindow instead, this isn't as nice looking, but it does not contain the bug and you can cancel the progressWindow with the Esc key and everything works correctly. Here's how to get it working.

 

string $selection[] = `ls -sl -fl`;
int $sizeProgressBar = `size $selection`;

progressWindow -title "Progress Bar" -isInterruptable true -status "" -maxValue $sizeProgressBar;

for ($item in $selection)
{
    select $item;

	//Cancel progress bar
	if(`progressWindow -query -isCancelled`)
	{
		progressWindow -edit -endProgress;
		error "Process cancelled\n";
	}
			
	//update the progress bar
	progressWindow -edit -step 1;
}

progressWindow -edit -endProgress;

 

 

0 Likes