.NET

Reply
Active Contributor
cadmaxza
Posts: 36
Registered: ‎06-23-2004
Message 1 of 3 (234 Views)

VB.Net DocumentCreated Event

234 Views, 2 Replies
01-31-2006 12:08 AM
Hi,

I need to add a custom process at the DocumentCreated event. Please help, what is missing from this code?

Imports System
Imports Autodesk.AutoCAD.ApplicationServices

Public Class Class1

Implements Autodesk.AutoCAD.Runtime.IExtensionApplication

Private Shared WithEvents m_docMan As DocumentCollection

Private Shared Sub m_docMan_DocumentCreated(ByVal sender As Object, _
ByVal e As Autodesk.AutoCAD.ApplicationServices.DocumentCollectionEventArgs) _
Handles m_docMan.DocumentCreated
m_docMan = Application.DocumentManager

''''' write custom actions here...

End Sub
End Class

Thx.

Kevin.
*Nemorarius
Message 2 of 3 (234 Views)

Re: VB.Net DocumentCreated Event

01-31-2006 09:23 AM in reply to: cadmaxza
m_DocMan is Nothing until you assign a value to it.
Add Shared Sub New constructor to your class and assign a value to m_DocMan.


wrote in message news:5072856@discussion.autodesk.com...
Hi,

I need to add a custom process at the DocumentCreated event. Please help,
what is missing from this code?

Imports System
Imports Autodesk.AutoCAD.ApplicationServices

Public Class Class1

Implements Autodesk.AutoCAD.Runtime.IExtensionApplication

Private Shared WithEvents m_docMan As DocumentCollection

Private Shared Sub m_docMan_DocumentCreated(ByVal sender As Object, _
ByVal e As
Autodesk.AutoCAD.ApplicationServices.DocumentCollectionEventArgs) _
Handles m_docMan.DocumentCreated
m_docMan = Application.DocumentManager

''''' write custom actions here...

End Sub
End Class

Thx.

Kevin.
Distinguished Contributor
cgay
Posts: 125
Registered: ‎08-02-2005
Message 3 of 3 (234 Views)

Re: VB.Net DocumentCreated Event

01-31-2006 10:13 AM in reply to: cadmaxza
Kevin,

I would be very surprised if the code you have there would even compile. The reason is that you are using an Implements statement, but you are not fulfilling the contract by actually implementing the interface. I think the solution to your problem is to implement the interface(IExtensionApplication) fully and when you do, add an event handler to the Initialize method.

Here is some example code..........

[code]
Imports Autodesk.AutoCAD.Runtime
Imports AcadApp = Autodesk.AutoCAD.ApplicationServices.Application
[/code]
< extensionapplication="">
[code]
Public Class MyApp
Implements IExtensionApplication

'This Attribute doesn't show up well in the Discussion Group
'Replace *** with <
'Replace @@@ with >
***Assembly: ExtensionApplication(GetType(MyApp))@@@

Public Sub Initialize() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Initialize
AddHandler AcadApp.DocumentManager.DocumentCreated, AddressOf DocumentCreated
End Sub

Public Sub Terminate() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Terminate
'I think that this will always generate an error because by the time this code
'is called, the document manager is destroyed.
'but if AutoDesk someday add a .NET unload option, you may need this to remove
'your event from the call stack
Try
RemoveHandler AcadApp.DocumentManager.DocumentCreated, AddressOf DocumentCreated
Catch ex As Exception

End Try
End Sub

Private Sub DocumentCreated(ByVal sender As Object, ByVal e As Autodesk.AutoCAD.ApplicationServices.DocumentCollectionEventArgs)
'Do stuff here when a document is created
End Sub
End Class

[/code]


Good luck,
C

Message was edited by: CougerAC Message was edited by: CougerAC
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.