TheSwamp
Code Red => .NET => Topic started by: Peter Jamtgaard on December 03, 2012, 04:54:57 PM
Title:
Run function in Each Document
Post by:
Peter Jamtgaard
on
December 03, 2012, 04:54:57 PM
Since .NET is a application level language.
Is there a simple way to have a .net function run whenever a document is opened?
I know initialize runs once when Autocad starts but I want a function to run in each document.
I have successfully done it with an event, but I figure there is an easier way to do it.
Thanks in advance
P=
Title:
Re: Run function in Each Document
Post by:
zoltan
on
December 03, 2012, 05:11:33 PM
You can hook into the
DocumentCollection.DocumentCreated
event that will fire whenever a new document is added or opened.
Code - C#:
[Select]
public
static
void
HookApplicationEvents
(
)
{
Application
.
DocumentManager
.
DocumentCreated
+=
new
DocumentCollectionEventHandler
(
DocumentManager_DocumentCreated
)
;
}
public
static
void
UnhookApplicationEvents
(
)
{
Application
.
DocumentManager
.
DocumentCreated
-=
new
DocumentCollectionEventHandler
(
DocumentManager_DocumentCreated
)
;
}
private
static
void
DocumentManager_DocumentCreated
(
object
sender, DocumentCollectionEventArgs e
)
{
// Do some stuff.
}