.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

VB.Net DocumentCreated Event

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
516 Views, 2 Replies

VB.Net DocumentCreated Event

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.
2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: Anonymous

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.
Message 3 of 3
cgay
in reply to: Anonymous

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost