Displaying a dialog on AutoCAD startup using .NET

This post is based on some information provided by Peter Muigg, a developer in Germany Austria who has long been a friend of Autodesk. In fact, if memory serves me well – and do step in if I'm mis-remembering, Peter – back in 1995 when I first joined the company, Peter delivered German-language ObjectARX training on behalf of Autodesk.

Peter reached out with this tip just before the holiday break: he needed to display a dialog on AutoCAD startup, but found that it was too soon to do so on IExtentionApplication.Initialize() (it's assumed this module is either demand- or auto-loaded, by the way – manual loading doesn't tend to exhibit this issue).

I typically use the approach of posting a command/queueing up a LISP expression to execute on startup to do this, but Peter has successfully used the Application.Idle event, instead.

Here's Peter's C# code:

using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.Runtime;

using System;

 

public class App : IExtensionApplication

{

  static MyPalette _palette;

 

  public void Initialize()

  {

    // ... other stuff

 

    // Create a hook on the "Idle" event of the application class

 

    Application.Idle += new EventHandler(Application_Idle);

 

  }

 

  void Application_Idle(object sender, EventArgs e)

  {

    // Remove the event handler as it is no longer needed

 

    Application.Idle -= Application_Idle;

    _palette = new MyPalette();

    _palette.Visible = true;

  }

 

  // ...

}

The code itself shouldn't need any explanation – it's both simple and elegant. Thanks for sharing it, Peter!

Update:

Peter has since clarified he's based in Innsbruck, so I've updated the post accordingly. My apologies for getting that wrong, especially being based in neighbouring Switzerland! 🙁

6 responses to “Displaying a dialog on AutoCAD startup using .NET”

  1. Can I use this approach to load a cuix file using the SendStringToExecute method into the Application.Idle event callback?

  2. Hi Gdiael,

    I don't see why not. If wanting to load a CUIX on startup, I strongly suggest also looking into the Autoloader.

    Kean

  3. Hi Kean, Thank you very much!! Its a very interesting tool! I read the customization guide.

    But I have a question, my plugin has two .dll files. One for autocad 2012 and another for autocad 2013. I have to create a .bundle folder for each version, or is there some way to load each .dll file only in the correct version of autocad, with them in the same folder.

    With my current installer (I made from your tutorial) I create registry entries specific to each version.
    PS Sorry for my English. I'm from Brazil.

  4. Hello again, Kean.
    Sorry, I realized that I can place multiple components blocks in the same .xml file, after watched the video about the autoloader in your blog, thank you for your attention.
    Your blog is very good, and help me so much.

  5. I have gone through your blog this is such a good topic. I really enjoyed a lot and the blog is really very interesting.

    Cad Educators

  6. WILFREDO ZAMUDIOMOREALES Avatar
    WILFREDO ZAMUDIOMOREALES

    Hello I have problems with the syntax in VB.net
    "Application.Idle + = new EventHandler (Application_Idle);"

Leave a Reply

Your email address will not be published. Required fields are marked *