Quantcast
Viewing all articles
Browse latest Browse all 14319

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.

 

Image may be NSFW.
Clik here to view.

Viewing all articles
Browse latest Browse all 14319

Trending Articles