Author Topic: How do I: VLisp->Call C# method(w/Args)->Return results to VLisp  (Read 3181 times)

0 Members and 1 Guest are viewing this topic.

NickMerchant

  • Guest
How do I: VLisp->Call C# method(w/Args)->Return results to VLisp
« on: September 27, 2010, 12:49:43 PM »
I've developed 3rd party software for AutoCAD and its verticals using Visual Lisp and ActiveX for a long time. In the past few months, I've decided to finally get serious about learning C#.net. Now that I've gained a comfortable level of confidence creating small applications in C#, I've decided to begin translating my VL application to C# for the following reasons:

-Increase programming power and flexibility
-Enable standalone development outside of AutoCAD
-Increase the longevity of my application if COM ever goes away.

My application is currently in use by quite a few engineers in the southwest United States, Mexico and India, so while I'm translating the app' I also have to ensure that the Visual Lisp and C# components can coexist peacefully. I send out updates every few months and I don't want to create any interruption to my clients. Therefor, what I need to learn to do is allow C#.net and Visual Lisp to communicate with each other. I need to be able to make a Visual Lisp function call a c#.net method with parameters and make the C# method return calculation results to the Visual Lisp function that called it. Once I've learned how to do this effectively, I'll be well on my to a complete translation of my application over time. The first application feature I translated from Visual Lisp to C#.net had to output its results to the registry, where it was subsequently read by other Visual Lisp functions for further processing. I don't feel this is the most effective way of passing data back and forth between the two languages and I'm hoping there is a way to send and receive data DIRECTLY between the languages.

Can anyone help with this general concept? Some example code would be GREATLY APPRECIATED!

Thanks in advance

LE3

  • Guest
Re: How do I: VLisp->Call C# method(w/Args)->Return results to VLisp
« Reply #1 on: September 27, 2010, 01:49:46 PM »
Have done or little need use about lisp..

But a quick google search with: LispFunction C# AutoCAD

Show quite some info i.e:

augiru.augi.com/content/library/au07/data/paper/DE211-2.pdf
[PDF] The Best of Both Worlds: .NET and LISP Can Coexist

hth

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: How do I: VLisp->Call C# method(w/Args)->Return results to VLisp
« Reply #2 on: September 27, 2010, 01:58:25 PM »
and;

AutoCADŽ .NET: Using .NET With Your LISP Applications
Event Year: Autodesk University 2009
Class ID: CP214-4
  Wayne Brill

http://au.autodesk.com/?nd=class&session_id=5045

The video demonstrates VB but the concepts are consistant for C#
C# samples available.
Probably best to download the Screencast.

You'll need to sign in to the Autodesk University site


[added:kdub] I've provided the same answer to your post at the AutoDesk Discussion Groups.
There are some examples here I believe but they would perhaps be best pursued after you've seen the Screencast and sample code
« Last Edit: September 27, 2010, 02:11:20 PM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Glenn R

  • Guest
Re: How do I: VLisp->Call C# method(w/Args)->Return results to VLisp
« Reply #3 on: September 27, 2010, 04:22:56 PM »
ObjectARX Help of course: Defining Methods That Can Be Called From AutoLISP

jmaeding

  • Bull Frog
  • Posts: 304
  • I'm just here for the Shelties.
Re: How do I: VLisp->Call C# method(w/Args)->Return results to VLisp
« Reply #4 on: September 28, 2010, 01:44:28 PM »
Hi Nick,
Just happened to see this post.
I started on a similar journey a few years ago, and think what you want is doable.
It all comes down to how complex of data structures you are sending back and forth.
I essentially wanted to send a complex nested list back and forth, as that is how I model objects in lisp.
I think the actual final set of functions you will need will not be that hard.

The biggest thing will be developing a structure for your .net libraries, as you will want to re-use as much as possible for various .net progs.  Once you get the hang of it, .net is wonderful to program in, as it helps keep large programs under control.

So what I did was decide on various libraries I wanted to set up.
You will likely want these categories at least (these will be projects with multiple source code files included):
General
General Extensions
Forms
AutoCad
AutoCad Lisp

I use the same root namespace for all libraries I write, then add on a second level for each.
So my general is HAHelper
My acad related libraries are HAHelper.Autocad

This namespace and project setup is the biggest hurdle to .net IMO. Its nice once you get it though, very structured compared to lisp.


Then you need to set up test solutions so you can test things in desired way.
So I have a General Test solution that runs items without acad.
Then one that starts acad and loads the test dll via a script.
I can provide all info needed to do this, or read other posts too - whatever is fastest.

So then you will have a solution for each real program.
A solution will reference the libraries mentioned above, as well as a project specific to the task at hand.

email me if I forget to check back, I also have code I can share as we identify things worth sharing.

I am hoping to learn a few things as others read this. The subject of references is tricky.
I have tried to organize libraries so they did not reference things I was not sure if the end user had.
It may be that i could combine my acad and general libraries though, because I think errors do not happen if the end program does not call references that may be missing on a end user's computer...
James Maeding