Thanks once again to Viru Aithal for the inspiration behind this post, although I did write most of the code, this time. :-)
Adding a splash screen can give a touch of class to your application, assuming it's done non-intrusively. This post focuses on how best to do so within AutoCAD, and use the time it's displayed to perform initialization for your application.
The first thing you need to do is add a Windows Form to your project:
You should select the standard "Windows Form" type, giving an appropriate name (in this case I've used "SplashScreen", imaginatively enough).
Once this is done, you should set the background for the form to be your preferred bitmap image, by browsing to it from the form's BackgroundImage property:
Now we're ready to add some code. Here's some C# code that shows how to show the splash-screen from the Initialize() method:
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Prompts; // This is the name of the module
namespace SplashScreenTest
{
public class Startup : IExtensionApplication
{
public void Initialize()
{
SplashScreen ss = new SplashScreen();
// Rather than trusting these properties to be set
// at design-time, let's set them here
ss.StartPosition =
System.Windows.Forms.FormStartPosition.CenterScreen;
ss.FormBorderStyle =
System.Windows.Forms.FormBorderStyle.None;
ss.Opacity = 0.8;
ss.TopMost = true;
ss.ShowInTaskbar = false;
// Now let's disply the splash-screen
Application.ShowModelessDialog(
Application.MainWindow,
ss,
false
);
ss.Update();
// This is where your application should initialise,
// but in our case let's take a 3-second nap
System.Threading.Thread.Sleep(3000);
ss.Close();
}
public void Terminate()
{
}
}
}
Some notes on the code:
- I used a sample application called "Prompts" - you should change the using directive to refer to your own module name.
- We're setting a number of properties dynamically (at runtime), rather than stepping through how to set them at design-time.
- We've set the splash screen to be 80% opaque (or 20% transparent). This is easy to adjust.
- Some of the additional properties may be redundant, but they seemed sensible to set (at least to me).
Here's the result... I've set up my application to demand-load when I invoke a command, which allowed me to load a DWG first to show off the transparency of the splash-screen (even though the above code doesn't actually define a command - so do expect an "Unknown command" message, if you do exactly the same thing as I have). You may prefer to set the module to load on AutoCAD startup, otherwise.
Update:
Roland Feletic brought it to my attention that this post needed updating for AutoCAD 2010. Thanks, Roland!
I looked into the code, and found that the call to ShowModelessDialog needed changing to this:
Application.ShowModelessDialog(
Application.MainWindow.Handle,
ss,
false
);
I also found I had to add an additional assembly reference to PresentationCore (a .NET Framework 3.0 assembly).





Subscribe via RSS
Hi Kean,
Which reference I make for management of the API of the AutoCad.
Regards.
Posted by: Kélcyo Pereira | June 14, 2007 at 01:19 PM
Hi Kélcyo,
I'm sorry - I don't understand the question...
If you're asking which assembly references to add to your project, then you need acdbmgd.dll and acmgd.dll.
Regards,
Kean
Posted by: Kean | June 14, 2007 at 05:14 PM
As a non-coder, how do I find out HOW an ex-colleague made a splash screen and then remove it from the launch of AutoCAD?
Posted by: Tony | June 14, 2007 at 06:17 PM
There are many ways he or she may have coded it, so there's no fixed answer, I'm afraid. A programmer should be able to work it out pretty quickly, though, by looking at the project.
Kean
Posted by: Kean | June 14, 2007 at 06:37 PM
My intention is to search given of an archive txt to work in autocad.
Therefore I do not obtain to make one I dialogue to select the archive.
Posted by: Kélcyo Pereira | June 14, 2007 at 06:59 PM
Because, when use following code, error?
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.GraphicsInterface
Imports Autodesk.AutoCAD.ApplicationServices
Imports System.Windows.Forms
Public Class kpsCommands
Implements Autodesk.AutoCAD.Runtime.IExtensionApplication
' Define command 'Asdkcmd1'
_
Public Sub Asdkcmd1()
Dim ss As FrmSplash = New FrmSplash()
Autodesk.Autocad.ApplicationServices.Application.ShowModelessDialog(Autodesk.AutoCAD.ApplicationServices.Application.MainWindow, ss, False)
End Sub
End Class
It requests premission! It has some thing with the security reference. System.Security.Permission....
Regards.
Kelcyo
Posted by: Kélcyo Pereira | June 15, 2007 at 05:23 PM
Hi Kélcyo,
I don't know why this is happening on your system. Are you executing code from the dialog itself, rather than just using it as a splashscreen?
Regards,
Kean
Posted by: Kean | June 18, 2007 at 10:56 AM