Identify the Start Tab (Autocad 2016)

Identify the Start Tab (Autocad 2016)

Anonymous
Not applicable
921 Views
3 Replies
Message 1 of 4

Identify the Start Tab (Autocad 2016)

Anonymous
Not applicable

I have a program that implements a documentbecamecurrent handler. In this I access the current documents database. When I click on the Start Tab it fires the event handler then crashes when I try to access the document database.

 

Is the start tab a document?

Is there a way to identify that the user has clicked on the start tab?

0 Likes
Accepted solutions (1)
922 Views
3 Replies
Replies (3)
Message 2 of 4

ActivistInvestor
Mentor
Mentor
Accepted solution

@Anonymous wrote:

I have a program that implements a documentbecamecurrent handler. In this I access the current documents database. When I click on the Start Tab it fires the event handler then crashes when I try to access the document database.

 

Is the start tab a document?

Is there a way to identify that the user has clicked on the start tab?


Crashes with?  A NullReferenceException ?

 

If so, you have to first check the Document to ensure it's not null before you try to use it.

 

 

Message 3 of 4

Norman_Yuan
Mentor
Mentor

Is the start tab a document?


No, it is not a document. It is DocumentWindow, which has a property "Document", which is an "object", which can only be Autodesk.AutoCAD.ApplicationServices.Document when the DocumentWindow is drawing window. When it is "Start", or custom window (yes, you can create one of your own), then the "Document" property is anything else, but an Autodesk.AutoCAD.Application.Document.

 


Is there a way to identify that the user has clicked on the start tab?


Yes, you can identify if the active DocumentWindow is a drawing window or "Start"/custom window. Something like:

 

if (Application.DocumentWindowCollection.Count>0)

{

  var doc = Application.DocumentWindowCollection.ActiveDocumentWindow.Document;

  if (!(doc is Autodesk.AutoCAD.ApplicationServices.Document)

  {

     var msg=string.Format("This is non-drawing window: \"{0}\"", Application.DocumentWindowCollection,ActiveDocumentWindow.Title);

     CadApp.ShowAlert(msg);

  }

}

else

{

  //There isn't any DocumentWindow open!

}

 

However, it is likely that in your DocumentCollection.DocumentBecameCurrent event handler, you do not need to identify whether user clicked "Start" tab or not (you could, if you choose to do so, of course), and simply let the code, as Activist_Investor pointed out, test if the MdiActiveDocument is null or not, before using it. You may want to show your code to indicate where the crash occurs.

Norman Yuan

Drive CAD With Code

EESignature

Message 4 of 4

Anonymous
Not applicable

Thanks for your help guys. It was a null reference exception and testing MdiActiveDocument for null is what I needed.

0 Likes