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

Add handlers on Drawing open

6 REPLIES 6
Reply
Message 1 of 7
Anonymous
1704 Views, 6 Replies

Add handlers on Drawing open

Hi,
i had an idea of adding some event handlers, without user interaction.
At first, i thought i will write a CommandMethod and run it as a command from acad.lsp, but then i found an article about running VBA macros at startup using only VBA, which brought me to the idea, that this could be done using only .NET
Is it actually possible to run some .NET code at AutoCAD startup without having to use LISP?

Thanks
6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: Anonymous

Download this file, and look at the included files
ExtensionApplicationInfo.cs and MyApplication.cs
to see how it's done:

http://www.caddzone.com/LayerHelper.zip


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2011

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6399520@discussion.autodesk.com...
Hi,
i had an idea of adding some event handlers, without user interaction.
At first, i thought i will write a CommandMethod and run it as a command from
acad.lsp, but then i found an article about running VBA macros at startup using
only VBA, which brought me to the idea, that this could be done using only .NET
Is it actually possible to run some .NET code at AutoCAD startup without having
to use LISP?

Thanks
Message 3 of 7
Anonymous
in reply to: Anonymous

if i understand it right, the code is for automatic registering commands, instead of using netload

but I want a different thing, let me give an example:

i can have an Acad.lsp that contains a line: (princ "Welcome and have a nice day working on this drawing.")

that way, everytime you open a drawing or start a new one, you get this message in the command line

this can be done in .NET using the handler for EndOpen event, but first i need to add the handler and i want the handler to be added automatically on every Autocad start

if this can be done using that code, you provided, than i probably didn't understand the code
Message 4 of 7
_gile
in reply to: Anonymous

Hi,

You can try something like this, but it have to be registred or netloaded via acad.lsp to be loaded at each AutoCAD session start.

{code}using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;

namespace DocumentCreatedEventSample
{
public class Welcome : IExtensionApplication
{
private DocumentCollection docMan = Application.DocumentManager;

public void Initialize()
{
docMan.DocumentCreated += new DocumentCollectionEventHandler(docMan_DocumentCreated);
DoIt();
}

public void Terminate()
{
}

void docMan_DocumentCreated(object sender, DocumentCollectionEventArgs e)
{
DoIt();
}

private void DoIt()
{
Application.ShowAlertDialog(
"Welcome and have a nice day working on this drawing.");
}
}
}
{code}


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 5 of 7
Anonymous
in reply to: Anonymous

The code is not only for automatic registering of commands
but also for automatic registering of an assembly to load when
AutoCAD starts, which is what you must to do in order for your
code to add the needed event handler.

You can use the ExtensionApplicationInfo class to register
your assembly to load automatically when AutoCAD starts
(as per the example in MyApplication.cs)

Then, in your IExtensionApplication's Initialize() method you
can add the handler for the DocumentCreated event.

_gile's post shows what you need to insofar as adding the
handler for the event.


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2011

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6399901@discussion.autodesk.com...
if i understand it right, the code is for automatic registering commands,
instead of using netload

but I want a different thing, let me give an example:

i can have an Acad.lsp that contains a line: (princ "Welcome and have a nice day
working on this drawing.")

that way, everytime you open a drawing or start a new one, you get this message
in the command line

this can be done in .NET using the handler for EndOpen event, but first i need
to add the handler and i want the handler to be added automatically on every
Autocad start

if this can be done using that code, you provided, than i probably didn't
understand the code
Message 6 of 7
Anonymous
in reply to: Anonymous

thank you, that's exactly what i needed

Tony, now i see that it's also in your code, but it was too much for me to find it there, because i didn't know exactly what i was looking for

this is how it looks in VB, just in case someone else needed it:

Public Class Welcome
Implements Autodesk.AutoCAD.Runtime.IExtensionApplication


Private docMan As DocumentCollection = Application.DocumentManager

Public Sub Initialize() Implements IExtensionApplication.Initialize

AddHandler docMan.DocumentCreated, AddressOf docMan_DocumentCreated
DoIt()

End Sub


Public Sub Terminate() Implements IExtensionApplication.Terminate

End Sub


Sub docMan_DocumentCreated(ByVal sender As Object, ByVal e As DocumentCollectionEventArgs)

DoIt()

End Sub


Private Sub DoIt()

Application.ShowAlertDialog("Welcome and have a nice day working on this drawing.")

End Sub

End Class
Message 7 of 7
Anonymous
in reply to: Anonymous

how can i add code to look readable like yours?

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