.NET

Reply
Active Contributor
davidgarner
Posts: 26
Registered: ‎04-14-2005
Message 1 of 7 (104 Views)

Mimic acad.lsp and acaddoc.lsp in .Net

104 Views, 6 Replies
03-16-2006 04:44 PM
As you may know, acad.lsp is loaded automatically when AutoCAD opens. acaddoc.lsp is loaded each time a drawing is loaded. I'm porting ancient LISP code to .Net (c#) and was wondering what to do with all this code and how to get it to run automatically from an assembly.

Is there some event in .Net that can be trapped to run code at these instances?

In a .Net assembly can the constructor be used and caused to run when the assembly is loaded?

Bottom line is I'm looking for the design pattern to use for code that needs to run automatically during both of the above mentioned occurrences.

David Garner
Chong Partners Architecture.
Employee
mikel.martin
Posts: 283
Registered: ‎03-16-2006
Message 2 of 7 (104 Views)

Re: Mimic acad.lsp and acaddoc.lsp in .Net

03-16-2006 09:03 PM in reply to: davidgarner
I am not sure if this what you are looking for, but in AutoCAD 2006 (limited 2005) you can create .NET programs as a dll and with some regestry settings set a command that will cause the dll to load and run. These commands will always be avaible and require no loading through lisp.


Mikel Martin
User Experience Architect
PLM / Data Management
Autodesk, Inc.
*Bobby C. Jones
Message 3 of 7 (104 Views)

Re: Mimic acad.lsp and acaddoc.lsp in .Net

03-17-2006 07:25 AM in reply to: davidgarner
Hi David,
Have a class in your assembly implement the IExtensionApplication interface.
This interface has an Initialize() method which is called when your assembly
is loaded.

I haven't used these yet, hopefully someone else can give some clearer
directions, but the DocumentCollection object has events for catching
document creation. The DocumentManager property of the Application object
will give you a DocumentCollection object.
--
Bobby C. Jones
http://www.acadx.com


wrote in message news:5113639@discussion.autodesk.com...
As you may know, acad.lsp is loaded automatically when AutoCAD opens.
acaddoc.lsp is loaded each time a drawing is loaded. I'm porting ancient
LISP code to .Net (c#) and was wondering what to do with all this code and
how to get it to run automatically from an assembly.

Is there some event in .Net that can be trapped to run code at these
instances?

In a .Net assembly can the constructor be used and caused to run when the
assembly is loaded?

Bottom line is I'm looking for the design pattern to use for code that needs
to run automatically during both of the above mentioned occurrences.

David Garner
Chong Partners Architecture.
Distinguished Contributor
RonnieWilkins
Posts: 454
Registered: ‎04-07-2003
Message 4 of 7 (104 Views)

Re: Mimic acad.lsp and acaddoc.lsp in .Net

03-17-2006 07:27 AM in reply to: davidgarner
using System;
using System.Collections.Generic;
using System.Text;

using AcRx = Autodesk.AutoCAD.Runtime;

namespace ClassLibrary1
{
public class Class1 : AcRx.IExtensionApplication
{
#region IExtensionApplication Members

public void Initialize()
{
//Add Code here that you wish to run when the program is loaded
throw new Exception("The method or operation is not implemented.");
}

public void Terminate()
{
//This method must exist, but is never called
throw new Exception("The method or operation is not implemented.");
}

#endregion
}
}
Ronnie Wilkins, Jr.
AMS CAD + CAFM Solutions
Sr. Solutions Developer
Autodesk Certified Instructor: Inventor
Distinguished Contributor
RonnieWilkins
Posts: 454
Registered: ‎04-07-2003
Message 5 of 7 (104 Views)

Re: Mimic acad.lsp and acaddoc.lsp in .Net

03-17-2006 09:37 AM in reply to: davidgarner
Updated to show how to run code each time a document is opened or a new document is created.

using System;
using System.Collections.Generic;
using System.Text;

using AcAp = Autodesk.AutoCAD.ApplicationServices;
using AcDb = Autodesk.AutoCAD.DatabaseServices;
using AcRx = Autodesk.AutoCAD.Runtime;

namespace ClassLibrary1
{
public class Class1 : AcRx.IExtensionApplication
{
public void DocumentAdded(object sender,AcAp.DocumentCollectionEventArgs e)
{
//Add code here that should run each time a drawing is opened
//or a new one is created.
AcAp.Application.ShowAlertDialog("A new document was added");
}

#region IExtensionApplication Members
public void Initialize()
{
//Add Code here that you wish to run when the program is loaded
AcAp.Application.DocumentManager.DocumentCreated += new AcAp.DocumentCollectionEventHandler(DocumentAdded);
}

public void Terminate()
{
//This method must exist, but is never called
}
#endregion
}
}
Ronnie Wilkins, Jr.
AMS CAD + CAFM Solutions
Sr. Solutions Developer
Autodesk Certified Instructor: Inventor
Active Contributor
davidgarner
Posts: 26
Registered: ‎04-14-2005
Message 6 of 7 (104 Views)

Re: Mimic acad.lsp and acaddoc.lsp in .Net

03-17-2006 09:37 AM in reply to: davidgarner
Thanks, just the direction I was looking for.

It's difficult to find stuff in the documentation unless one was previously an objectARX programmer. Hopefully ACAD will update their documentation. At the very least they could comment their wrapper code properly so at least some vague information would show up in the browser.
*Bobby C. Jones
Message 7 of 7 (104 Views)

Re: Mimic acad.lsp and acaddoc.lsp in .Net

03-20-2006 09:29 AM in reply to: davidgarner
> public void Terminate()
> {
> //This method must exist, but is never called
> }

Actually the Terminate method is called.
--
The not so Anon G.
http://www.acadx.com
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!