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

Closing default opened Document after Net Loading a DLL

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
thomas.croux
846 Views, 2 Replies

Closing default opened Document after Net Loading a DLL

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;
                        Takm.Infrastructure.Commanding.TakmCommands.DisplayShellCommand.Execute(true);
                    }

 

            foreach (Document doc in Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager)
            {
                if (doc != _kleverageDocument)
                {
                    try
                    {
                        doc.CloseAndDiscard();
                    }
                    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. 😉

 

tom.

 

2 REPLIES 2
Message 2 of 3
amanero
in reply to: thomas.croux

Hello,

 

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
Message 3 of 3
thomas.croux
in reply to: amanero

Hello Luis Alberto !

 

Thanks a lot, this is the good solution ! It works great ! Smiley Wink

Thank you so much !

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