Kean Walmsley

July 2009

Sun Mon Tue Wed Thu Fri Sat
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  

Twitter Updates

    follow me on Twitter



    « Using a jig from .NET to multiply insert AutoCAD blocks - Part 2 | Main | Getting the type of an AutoCAD solid using .NET »

    May 25, 2007

    TrackBack

    TrackBack URL for this entry:
    http://www.typepad.com/services/trackback/6a00d83452464869e200d835483fe953ef

    Listed below are links to weblogs that reference Displaying a progress meter during long operations in AutoCAD using .NET:

    Comments

    Kean.
    I've been using the following method to display a ProgressMeter in AutoCAD from .NET, avoiding P/Invoke. Should I change to use your method or is this the other internal method you speak of?

    int numItems = 100;
    int counter = 0;
    // Create progress meter
    ProgressMeter pm = new ProgressMeter();
    // Set it's caption
    pm.Start("Plotting Roads");
    // Set it's maximum value
    pm.SetLimit(numItems);
    // Now our lengthy operation
    while (counter < numItems)
    {
    	//
    	// Do my process here
    	//
    	
    	// Sleep a little bit
    	System.Threading.Thread.Sleep(1);
    	
    	// Update Screen
    	Application.UpdateScreen();
    	
    	// Increment Progress Meter...
    	pm.MeterProgress();
    	// ...and our loop counter
    	counter++;
    }
    // We're done, clear the Progress Meter
    pm.Stop();
    

    Hi Chris,

    Oops - my research was inadequate on this one... I missed the inbuilt class (and took Fenton's word for this one not being available).

    Please do what you're doing now - I'll check after the weekend what's what with the inbuilt class (perhaps it was introduced more recently, and Fenton was answering the question for an older release).

    More soon...

    Kean

    Hi Chris,

    OK - I see that Autodesk.AutoCAD.Runtime.ProgressMeter got exposed back in 2007. I'll update the post to reflect that.

    Thanks again,

    Kean

    Hi Kean,

    Why the need for Application.DoEvents. Also, where in the Autodesk documentation does it state that Application.DoEvents is supposed to be used in conjunction with the ProgressMeter Class?

    Thanks,

    Ron

    Hi Ron,

    It doesn't have to be used - it's just a choice of mine. I tend to use it to allow AutoCAD to still receive events (such as to repaint etc.) while undergoing long operations. But it's nothing to do with AutoCAD, it's a general Windows programming approach.

    Try commenting that line out and then switching between AutoCAD and another app while running the "PB" command. Even if you add some code to repaint the display you get some imperfect behaviour, so I tend for this option.

    If anyone has a better approach or a conflicting opinion, I'd be happy to hear it. :-)

    Cheers,

    Kean

    Hi Kean,

    If you don't mind I have one more question. Is there a reason that you're using System.Threading.Thread.Sleep()?

    Please excuse my question if it seems basic, but I am trying very hard to learn AutoCAD with .NET and when I see something that warrants asking a question I just have to ask.

    Ron

    Hi Ron,

    Not at all - it's a very valid question.

    That line is only there to make the operation take long enough for you to watch the progress meter move slowly (or somewhat slowly) across. If it isn't there you just see a flash.

    Feel free to keep the (post-related) questions coming - I'm sure there are others out there with similar thoughts.

    Kean

    Hi Kean,

    Just one more thing.
    Depending on how heavy is the process behind the progress bar if you leave AutoCAD window and get back the screen and the progress bar could appear frozen.

    As you have suggested inside a comment at my Blog´s article, we need do yield AutoCAD during the process. At that time, you have pointed to use:

    System.Windows.Forms.Application.DoEvents();

    In this case, we can call DoEvents() over AutoCAD application during the loop or is there a better way to do that?

    Regards,
    Fernando.

    Hi Fernando,

    Yes - from my perspective DoEvents is the way to go, just as the above two code fragments have shown.

    It's probably also worth thinking about trapping the escape key, to allow the task to be cancelled. I wrote this post showing how to do this, but I haven't tried to plug the two together, as yet.

    Cheers,

    Kean

    Verify your Comment

    Previewing your Comment

    This is only a preview. Your comment has not yet been posted.

    Working...
    Your comment could not be posted. Error type:
    Your comment has been posted. Post another comment

    The letters and numbers you entered did not match the image. Please try again.

    As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

    Having trouble reading this image? View an alternate.

    Working...

    Post a comment

    Feed & Share

    Search