Author Topic: DocumentManager.DocumentActivationEnabled  (Read 2663 times)

0 Members and 1 Guest are viewing this topic.

GUIDO ROOMS

  • Guest
DocumentManager.DocumentActivationEnabled
« on: August 19, 2012, 06:57:41 AM »
Last week I was having problems with switching documents from a modal dialog.
Alexander Rivilis kindly pointed out to me that before attempting to switch documents, I had to  set
DocumentActivationEnabled to true. This was right. The problem went.

Today I was trying to add a new document from a modal dialog, so I went:

Code - Visual Basic: [Select]
  1.     Private Sub BtnAddDocument_Click(sender As System.Object, e As System.EventArgs) Handles BtnAddDocument.Click
  2.         Try
  3.             Application.DocumentManager.DocumentActivationEnabled = True
  4.             Dim AddedDoc As Document = Application.DocumentManager.Add("acadiso.dwt")
  5.             '...add it to a list etc...
  6.        Catch ex As Exception
  7.             ShowError("Error while adding a new drawing." & vbLf & ex.Message)
  8.             Exit Sub
  9.         End Try
  10.     End Sub
  11.  

When afterwards I tried to draw in this new active document, I got error messages to the effect that the
context was invalid. I also noticed that if the above handler was called a second time, I got the same errors.
That is, I could only add one new document from tis handler!?
Gotten used to playing at blind man's buff with the .net api, I stumbled on the following solution:

Code - Visual Basic: [Select]
  1.   Application.DocumentManager.DocumentActivationEnabled = True
  2.   Dim AddedDoc As Document = Application.DocumentManager.Add("acadiso.dwt")
  3.   'and now...
  4.  Application.DocumentManager.DocumentActivationEnabled = False
  5.  

So, you apparently have to turn DocumentActivationenabled off after turning it on.
This may be old hat for the knowledeable among you, but I thought it might be of assistance to
beginners. That's why I posted it here.

I don't think I could have inferred the solution from the crappy documentation, so I used the old
trial and error method.

Note: using vb express 2010 and autocad 2010 (cancelled all our subscriptions and keeping an eye on bricscad, hehe!)

GUIDO ROOMS

  • Guest
Re: DocumentManager.DocumentActivationEnabled
« Reply #1 on: August 19, 2012, 11:50:58 AM »
Correction and summing up:
It's setting DocumentManager.DocumentActivationEnabled to true when it's already true that's
causing trouble. So testing it first solves the problem.

This reminds me of a comparable problem (or shall I call it a bug): when I try to thaw a layer which
is not frozen, this causes an exception to be thrown.

Again, this is autocad 2010. I don't know about higher versions...