.NET

Reply
Active Member
thomas.croux
Posts: 8
Registered: ‎05-15-2013
Message 1 of 3 (386 Views)
Accepted Solution

Closing default opened Document after Net Loading a DLL

386 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;
                        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. :smileywink:

 

tom.

 

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.

Valued Contributor
amanero
Posts: 75
Registered: ‎12-03-2003
Message 2 of 3 (369 Views)

Re: Closing default opened Document after Net Loading a DLL

05-31-2013 04:03 AM 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
Active Member
thomas.croux
Posts: 8
Registered: ‎05-15-2013
Message 3 of 3 (347 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 !

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

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