Active Member
Posts: 8
Registered: ‎05-15-2013
Message 1 of 3 (344 Views)
Accepted Solution

Closing default opened Document after Net Loading a DLL

344 Views, 2 Replies
05-31-2013 01:23 AM

Hello everybody !


Context :

  • AutoCAD Map 3D 2013
  • Visual Studio 2010
  • .NET 4.0, C#, WPF
  • FDO
  • Oracle DataStore

Requirement :

When I start AutoCAD Map 2013, a default document called "Drawing1.dwg" is opened. I use the command NETLOAD to load my assemblies. Final Users don't NETLOAD, an entry in the registry does the job automatically. During Initialization, my application downloads from the database a Template DWT file to initiate automatically the connection to the DataSource, and shows the different layers and styles configured by the customer. A new drawing based on this DWT is then generated.

However, the first default document remains opened. It can be sometimes annoying for the user to have both documents opened. I've never found a nice solution to close this first default document.


My technical implementation, not working :

In the Initialize method coming from IExtensionApplication, I start my application (loading business classes, user interfaces, etc...). Once started, I download the DWT, and add a new Document to the DocumentCollection (Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager). To this new Document, I handle many events such as CommandWillStart, CommandEnded, CommandFailed, etc... At this time, my Application asks to the user to log in. And finally, I browse the whole DocumentCollection to try to close all documents that are not the new one based on the DWT.


        DocumentCollection doc_coll = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager;
        _kleverageDocument = doc_coll.Add(dwtFilePath);


                    if (_kleverageDocument != null)
                        _kleverageDocument.ImpliedSelectionChanged += new EventHandler(doc_ImpliedSelectionChanged);
                        _kleverageDocument.CommandWillStart += new CommandEventHandler(doc_CommandWillStart);
                        _kleverageDocument.CommandEnded += new CommandEventHandler(doc_CommandEnded);
                        _kleverageDocument.CommandFailed += doc_CommandFailed;


            foreach (Document doc in Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager)
                if (doc != _kleverageDocument)
                    catch (System.Exception ex)



When I call the CloseAndDiscard method for each of the other Documents, I always get an Exception telling me that the document is currently drawing. Actually, the command "NETLOAD" is stil running. How can I do ?



I tried another way, by using handled events on DocumentManager :

                    Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.DocumentActivationChanged += DocumentManager_DocumentActivationChanged;
                    Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.DocumentBecameCurrent += DocumentManager_DocumentBecameCurrent;

But it's not really working better ... The behavior is quite strange.


Can someone help me ?

Thanks a lot. :smileywink:




Valued Contributor
Posts: 73
Registered: ‎12-03-2003
Message 2 of 3 (327 Views)

Re: Closing default opened Document after Net Loading a DLL

05-31-2013 04:03 AM in reply to: thomas.croux



I would suggest to listen to the "Application.Idle" event. Probably it will be fired once AutoCAD is finally loaded so you will be able to make what you need to do.

Luis Alberto Manero, Geograma.com
Active Member
Posts: 8
Registered: ‎05-15-2013
Message 3 of 3 (305 Views)

Re: Closing default opened Document after Net Loading a DLL

05-31-2013 08:09 AM in reply to: amanero

Hello Luis Alberto !


Thanks a lot, this is the good solution ! It works great ! :smileywink:

Thank you so much !

Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.