Author Topic: Track Active Drawing  (Read 4539 times)

0 Members and 1 Guest are viewing this topic.

UWPMVG

  • Mosquito
  • Posts: 17
Track Active Drawing
« 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

On page 17 it says:

Add the following code to the DoIt sub routine:
Code: [Select]
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?

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Track Active Drawing
« Reply #1 on: May 12, 2014, 02:38:21 AM »
"Me" [VB.NET] is "this" [C#], as I understand.

UWPMVG

  • Mosquito
  • Posts: 17
Re: Track Active Drawing
« Reply #2 on: May 12, 2014, 03:36:18 AM »
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.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Track Active Drawing
« Reply #3 on: May 12, 2014, 04:11:21 AM »
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).

UWPMVG

  • Mosquito
  • Posts: 17
Re: Track Active Drawing
« Reply #4 on: May 12, 2014, 04:16:14 AM »
Yes, I did. I put in the code where all other code for different objects on my ToolPalette is located.

UWPMVG

  • Mosquito
  • Posts: 17
Re: Track Active Drawing
« Reply #5 on: May 16, 2014, 03:18:00 PM »
I erased all the code that I copied from the tutorial and added the following to my Public Class Commands:
Code: [Select]
AddHandler AcApp.DocumentManager.DocumentActivated, AddressOf Me.DocumentManager_DocumentActivated

and then

Code: [Select]
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?

WILL HATCH

  • Bull Frog
  • Posts: 450
Re: Track Active Drawing
« Reply #6 on: May 16, 2014, 05:31:22 PM »
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.

UWPMVG

  • Mosquito
  • Posts: 17
Re: Track Active Drawing
« Reply #7 on: May 17, 2014, 03:47:58 PM »
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?

WILL HATCH

  • Bull Frog
  • Posts: 450
Re: Track Active Drawing
« Reply #8 on: May 17, 2014, 06:34:30 PM »
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.

UWPMVG

  • Mosquito
  • Posts: 17
Re: Track Active Drawing
« Reply #9 on: May 18, 2014, 03:16:07 PM »
I have not managed to find any information about the Event (DocumentWindowCollection.DocumentAdded) you mentioned. Do you have any examples?

WILL HATCH

  • Bull Frog
  • Posts: 450
Re: Track Active Drawing
« Reply #10 on: May 18, 2014, 04:15:52 PM »
Download the documentation it holds the answers you seek.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Track Active Drawing
« Reply #11 on: May 18, 2014, 07:07:52 PM »
What year are you using?

UWPMVG

  • Mosquito
  • Posts: 17
Re: Track Active Drawing
« Reply #12 on: May 19, 2014, 02:08:36 PM »
Quote
Download the documentation it holds the answers you seek.

Where can I find that documentation?

Quote
What year are you using?

I´m using Civil 3D 2015 and Visual Studio Express 2013.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Track Active Drawing
« Reply #13 on: May 19, 2014, 05:00:27 PM »
Quote
Download the documentation it holds the answers you seek.

Where can I find that documentation?

Quote
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.

WILL HATCH

  • Bull Frog
  • Posts: 450
Re: Track Active Drawing
« Reply #14 on: May 19, 2014, 06:29:26 PM »
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.

UWPMVG

  • Mosquito
  • Posts: 17
Re: Track Active Drawing
« Reply #15 on: May 20, 2014, 03:51:38 PM »
I will keep looking for a solution for this problem. If any of you comes up with something, let me know. :-)

UWPMVG

  • Mosquito
  • Posts: 17
Re: Track Active Drawing
« Reply #16 on: May 26, 2014, 01:30:34 PM »
I found the solution with help from Kean Walmsley.

The following code works:

Code: [Select]
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