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

Mimic acad.lsp and acaddoc.lsp in .Net

6 REPLIES 6
Reply
Message 1 of 7
davidgarner
348 Views, 6 Replies

Mimic acad.lsp and acaddoc.lsp in .Net

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.
6 REPLIES 6
Message 2 of 7
mikel_martin
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
Autodesk, Inc.
Message 3 of 7
Anonymous
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.
Message 4 of 7
RonnieWilkins
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.
Message 5 of 7
RonnieWilkins
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.
Message 6 of 7
davidgarner
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.
Message 7 of 7
Anonymous
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

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