TheSwamp
Code Red => .NET => Topic started by: UWPMVG on May 12, 2014, 02:32:12 AM
-
I´m trying to track the active drawing for a tool palette that I´ve created using .NET.
I´m using this tutorial: http://forums.autodesk.com/autodesk/attachments/autodesk/152/26712/1/CP205-2_Mike_Tuersley.pdf (http://forums.autodesk.com/autodesk/attachments/autodesk/152/26712/1/CP205-2_Mike_Tuersley.pdf)
On page 17 it says:
Add the following code to the DoIt sub routine:
If m_DocData Is Nothing Then m_DocData = New MyDocData
AddHandler AcApp.DocumentManager.DocumentActivated, AddressOf Me.DocumentManager_DocumentActivated
AddHandler AcApp.DocumentManager.DocumentToBeDeactivated, AddressOf Me.DocumentManager_DocumentToBeDeactivated
The last part of the code "Me.DocumentManager_DocumentActivated" gives an error. I don´t understand what "Me" is recalling to.
"Me" are not used anywhere else in the guide.
Can someone help?
-
"Me" [VB.NET] is "this" [C#], as I understand.
-
The ToolPalette I´m creating is named SectionViewer and the error message I recieves for "Me.DocumentManager_DocumentActivated" is that it is not a member or part of "SectionViewer.Commands" or something like that. I´m not at my computer at home right now.
-
The ToolPalette I´m creating is named SectionViewer and the error message I recieves for "Me.DocumentManager_DocumentActivated" is that it is not a member or part of "SectionViewer.Commands" or something like that. I´m not at my computer at home right now.
Did you copy the DocumentManager_DocumentActivated method into your code source file? :) This method are located on the same page (17).
-
Yes, I did. I put in the code where all other code for different objects on my ToolPalette is located.
-
I erased all the code that I copied from the tutorial and added the following to my Public Class Commands:
AddHandler AcApp.DocumentManager.DocumentActivated, AddressOf Me.DocumentManager_DocumentActivated
and then
Private Sub DocumentManager_DocumentActivated(ByVal sender As Object, ByVal e As DocumentCollectionEventArgs)
m_Container1.txtADwg.Text = e.Document.Name
End Sub
That seems to work if I in Civil 3D 2015 opens up a couple of tabs before I execute my code, but if I opens up a new tab while my tool palette is up and running, Civil 3D stops responding and after some time "Fatal Error".
Am I missing something?
-
We're going to need to see more code, it is usually something small that gets you.
After autocad crashes from a fatal error you can get useful info about what caused the crash. The window that opens up about error reporting has an option to 'View Report Details' if you hit that then select the 'dmpuserinfo.xml' file and select 'View file contents' there is a section about half way down titled '<AppCDATA>' which will tell you what was on the call stack when your code failed (usually)
While I like that Autodesk has released these tutorials showing how to do advanced tasks, I disagree with how they are releasing them with the intended audience being novice programmers. There are numerous pitfalls you will come across creating a background application aimed at tracking MDIActiveDocument, I've personally put about 400 hrs into mine and can't begin to track the number of fatal error messages I've dealt with. If I have time later I'll see if it will be too much work to abstract the core of my application to post.
-
I figured out what caused the "Fatal Error"!
Civil 3D 2015 has a new feature when clicking on "Add a tab". It then gives the user the opportunity to choose whether to start a new drawing in that tab or open an existing one.
"m_Container1.txtADwg.Text = e.Document.Name" can't then get an correct value.
How can I get around this?
-
You would be better off to look into the DocumentWindow object and the DocumentWindowCollection.DocumentAdded event instead of the previous route. With the latest updates to AutoCAD and the introduction the the non drawing document things are different as you've seen.
-
I have not managed to find any information about the Event (DocumentWindowCollection.DocumentAdded) you mentioned. Do you have any examples?
-
Download the documentation it holds the answers you seek.
-
What year are you using?
-
Download the documentation it holds the answers you seek.
Where can I find that documentation?
What year are you using?
I´m using Civil 3D 2015 and Visual Studio Express 2013.
-
Download the documentation it holds the answers you seek.
Where can I find that documentation?
What year are you using?
I´m using Civil 3D 2015 and Visual Studio Express 2013.
2015 you can not change active document during a command. The command must finish in a document before it will change.
-
2015 you can not change active document during a command. The command must finish in a document before it will change.
My understanding of the OP is that this is palette code in the application context and not command code in the document context. I have not switched my palettes to 2015 so this could be a potential issue I'll be dealing with shortly.
-
I will keep looking for a solution for this problem. If any of you comes up with something, let me know. :-)
-
I found the solution with help from Kean Walmsley.
The following code works:
AddHandler AcApp.DocumentManager.DocumentActivated, AddressOf Me.DocumentManager_DocumentActivated
...
Private Sub DocumentManager_DocumentActivated(ByVal sender As Object, ByVal e As DocumentCollectionEventArgs)
If Application.DocumentManager.MdiActiveDocument IsNot Nothing Then
MsgBox("Active drawing has changed!")
End If
End Sub