.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Progress meter is not shown in Civil 3D 2015

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
aknigin
2116 Views, 8 Replies

Progress meter is not shown in Civil 3D 2015

I try to use the buil-in progress meter in Civil 3D, using the .NET API. It works OK up to 2014 version, but in 2015 version the progress bar is not shown for some reason. Below is the simple code I used for testing.

[CommandMethod("mymeter")]
        public static void myMeterFunction()
        {
            ProgressMeter pm = new ProgressMeter();
            pm.Start("Test");
            pm.SetLimit(100);
            try
            {
                for (int i = 0; i < 100; i++)
                {
                    pm.MeterProgress();
                    System.Threading.Thread.Sleep(20);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                pm.Stop();
            }
        }

 

Tags (2)
8 REPLIES 8
Message 2 of 9
norman.yuan
in reply to: aknigin

From my experience of using ProgressMeter, sometimes it shows OK, sometimes it does not show well (meaning the progress bar does not update promptly or smoothly, depending on AutoCAD version and the work AutoCAD is doing.

 

In the case AutoCAD 2015, it might be that Autodesk did something to optimize AutoCAD performence, which somehow affects the UI update, or event it because of OS (Windows version) is trying to optimize the process, in which repainting UI usually takes lower priority.

 

You could try to force UI update in the loop by adding System.Windows.Forms.Application.DoEvents(). This code works for me with AutoCAD Map 2015 (yes, the progress bar is not seeable with your code before I added DoEvents() in the loop):

 

[CommandMethod("Prog")]
public static void RunMyCadCommand()
{
    Document dwg = CadApp.DocumentManager.MdiActiveDocument;
    Editor ed = dwg.Editor;

    try
    {
        using (ProgressMeter pm = new ProgressMeter())
        {
            pm.SetLimit(100);
            pm.Start("Test");
            try
            {
                for (int i = 0; i < 100; i++)
                {
                    pm.MeterProgress();
                    System.Windows.Forms.Application.DoEvents();

                    System.Threading.Thread.Sleep(20);
                }
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
            finally
            {
                pm.Stop();
            }
        }
    }
    catch (System.Exception ex)
    {
        ed.WriteMessage("\nError: {0}\n{1}", ex.Message, ex.StackTrace);
    }
    finally
    {
        Autodesk.AutoCAD.Internal.Utils.PostCommandPrompt();
    }
}

 HTH

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 9
aknigin
in reply to: norman.yuan

Norman,

I do call DoEvents in my real code (the example code is just an example), but it does not help every time, as you also mentioned. For example, if I add this call to the code above, the progress bar appears somewhere on 10% of the overall progress. Maybe there is also another remedy for that, because I don't like the idea of show custom progress dialog or something like this.

Message 4 of 9
FRFR1426
in reply to: aknigin

I think it's designed that way. Progress bar does not show immediately. If the operation is fast, no need to annoy the user with a progress bar. If it takes too long, the progress bar appears.

 

Like you, I don't like how it works, because users think that AutoCAD hangs.

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr
Message 5 of 9
FRFR1426
in reply to: FRFR1426

Done this little command for testing:

 

[CommandMethod("PM")]
public void ProgressMeter()
{
    using (var pm = new ProgressMeter())
    {
        pm.SetLimit(10);
        pm.Start();
        for (int i = 0; i < 10; i++)
        {
            Thread.Sleep(1000);
            pm.MeterProgress();
        }
        pm.Stop();
    }
}

On AutoCAD 2011 it works perfectly. On 2015, I have to add a DoEvents after pm.Start()  to make the bar appear. And it is visible at 20%, not before....

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr
Message 6 of 9
aknigin
in reply to: FRFR1426

Whatever, we ended up with dialog window with progress bar on it. It would be great to have built-in progress bar, but at the moment it almost useless because it shows user nothing.

Message 7 of 9
JamesMaeding
in reply to: aknigin

I am finding the progressbar is not dependable also.

I tend to use it for 5 steps or so, and some acticities take 20 seconds.

I added to DoEvents with no luck.

 

Can we unmark the items tagged as solution? Cause its not one.

 


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

Message 8 of 9
hericson
in reply to: aknigin

This is a very good thread, it explains my problem exactly, even if it is several years old. Anyone got any news how to solve this?

Message 9 of 9
norman.yuan
in reply to: hericson

As you already read from this thread, AutoCAD's ProgressBar exposed from API is really not that reliable/consistent for updating progress, and its behaviour changes slightly from AutoCAD versions/OS versions.

 

I found that using modal form to show progress (using ProgressBar control, or other controls, Win Form, or WPF) is the only way to guarantee progress is updated on UI. However, good coding practice does not want to mix pure, lengthy AutoCAD processing code with UI code. So, if your are interested, this article might be a bit of help:

 

https://drive-cad-with-code.blogspot.com/2015/04/showing-progress-for-long-code.html 

 

Norman Yuan

Drive CAD With Code

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost