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:
Private Sub BtnAddDocument_Click(sender As System.Object, e As System.EventArgs) Handles BtnAddDocument.Click
Try
Application.DocumentManager.DocumentActivationEnabled = True
Dim AddedDoc As Document = Application.DocumentManager.Add("acadiso.dwt")
'...add it to a list etc...
Catch ex As Exception
ShowError("Error while adding a new drawing." & vbLf & ex.Message)
Exit Sub
End Try
End Sub
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:
Application.DocumentManager.DocumentActivationEnabled = True
Dim AddedDoc As Document = Application.DocumentManager.Add("acadiso.dwt")
'and now...
Application.DocumentManager.DocumentActivationEnabled = False
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!)