Author Topic: Idea: System.Windows.Forms from lisp via IronPython.  (Read 4661 times)

0 Members and 1 Guest are viewing this topic.

tjr

  • Guest
Idea: System.Windows.Forms from lisp via IronPython.
« on: March 12, 2008, 01:20:03 PM »
I was just looking at the nice set of tools that Daniel created and shared and I really liked the examples he put out with the "crptextbox" and such, you know quick and dirty little GUI's for use in lisp.

This got my mind wandering a bit, in the later versions of the .NET API for AutoCAD you can create a "LispFunction" that can be called from lisp and returns a valid lisp value. Now I'm not going to lie, I don't know lisp at all nor am I really familiar with the LispFunction portion of the .NET API, however looking at Daniel's crpPropBox example it appears that lisp has the equivalent of a python dictionary, (("A1" . "A2") ("B1" . "B2") ("C1" . "C2")("D1" . "D2")), which essentially means you can map values to keys.

Now I was thinking if "LispFunction" can return dictionaries that are variable length it would be fairly easy to beat up the code Daniel gave me for PyAcad.NET to create a "LispFunction" that you pass a python file and some lisp variables, it runs it through the python engine and returns a dictionary of values.

If this is doable I think this is something that would be pretty awesome for the lisper's out there. It would allow them to reach out into the wide world of .NET and all the libraries it has to offer (Winforms, WPF, Standard Lib, etc).

Thoughts?

sinc

  • Guest
Re: Idea: System.Windows.Forms from lisp via IronPython.
« Reply #1 on: March 12, 2008, 05:48:02 PM »
You mean other than the obvious?  (If you think C# is "horrid", you should try writing a complex program in Lisp...)

Glenn R

  • Guest
Re: Idea: System.Windows.Forms from lisp via IronPython.
« Reply #2 on: March 12, 2008, 06:17:27 PM »
 :evil:

tjr

  • Guest
Re: Idea: System.Windows.Forms from lisp via IronPython.
« Reply #3 on: March 12, 2008, 07:05:04 PM »
You mean other than the obvious?  (If you think C# is "horrid", you should try writing a complex program in Lisp...)
Yeah I don't know who would want to do something like that. :)

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: Idea: System.Windows.Forms from lisp via IronPython.
« Reply #4 on: March 12, 2008, 11:23:37 PM »
I have done this many times with C#, It’s a great way to create nice looking GUIs for lisp. You could do this with PyAcad.NET too,  If CC. execute can except/return parameters, Or use a static global variable inside your PyAcad.NET module to hold the  buffer , or use a global lisp variable and wrap acedPutSym()and acedGetSym.

Code: [Select]
   [System.Security.SuppressUnmanagedCodeSecurity]
    [DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl)]
    extern static private int acedPutSym(string args, IntPtr result);

    [System.Security.SuppressUnmanagedCodeSecurity]
    [DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl)]
    extern static private int acedGetSym(string args, out IntPtr result);


    static public ResultBuffer AcadGetSym(string varname, ref int stat)
    {
      IntPtr rb = IntPtr.Zero;
      stat = acedGetSym(varname, out rb);
      if (rb != IntPtr.Zero)
        return (ResultBuffer)DisposableWrapper.Create(typeof(ResultBuffer), rb, true);
      return null;
    }
    static public int AcadPutSym(string varname, ResultBuffer rb)
    {
      return acedPutSym(varname, rb.UnmanagedObject);
    }

Personally, I think using the "static variable" idea would be the best method for modal forms.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: Idea: System.Windows.Forms from lisp via IronPython.
« Reply #5 on: March 18, 2008, 12:46:46 PM »
or like this  :-o

Code: [Select]
#thanks to kwb for the C# code to translate
clr.AddReference('PyAcadDotNet')
import Autodesk.AutoCAD.DatabaseServices as dbs
import PyAcadDotNet.AcadInterface as pdn

try:
    print pdn.RbIn.ToString()
   
    buff =  dbs.ResultBuffer()
    buff.Add(dbs.TypedValue(5005,"Hola"))
    buff.Add(dbs.TypedValue(5005,"Shmola"))
    pdn.RbOut = buff
   
except:
    print "error"

PS. What happened to the Killers Avatar
« Last Edit: March 18, 2008, 12:57:08 PM by Daniel »

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: Idea: System.Windows.Forms from lisp via IronPython.
« Reply #6 on: March 18, 2008, 01:02:14 PM »
So now you should be able to return any type that lisp can handle

Code: [Select]
#thanks to kwb for the C# code to translate
clr.AddReference('PyAcadDotNet')
import Autodesk.AutoCAD.DatabaseServices as dbs
import PyAcadDotNet.AcadInterface as pdn

try:
    print pdn.RbIn.ToString()
   
    #list
    #buff =  dbs.ResultBuffer()
    #buff.Add(dbs.TypedValue(5005,"Hola"))
    #buff.Add(dbs.TypedValue(5005,"Shmola"))
    #pdn.RbOut = buff
   
    #bool
    #pdn.RbOut = True
   
    #int
    #pdn.RbOut = 1
   
    #double
    #pdn.RbOut = 3.123456
   
    #string
    pdn.RbOut = "Back at you"
   
except:
    print "error"


tjr

  • Guest
Re: Idea: System.Windows.Forms from lisp via IronPython.
« Reply #7 on: March 18, 2008, 01:17:37 PM »
Whoa...awesome Daniel. I actually started looking at the code you pasted several days ago this morning and was working on incorporating it into PyAcad.NET this morning. I guess I will have a lot less work to do now. Thanks, I'll work with the code you posted.

Note: If you PM me I'd be more than willing to give you commit access to the project's Google code SVN repository.


P.S. Killers Avatar? No, sir. Iron Maiden, but was deleted when I deleted my account.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: Idea: System.Windows.Forms from lisp via IronPython.
« Reply #8 on: March 18, 2008, 01:22:09 PM »
Note: If you PM me I'd be more than willing to give you commit access to the project's Google code SVN repository.
Will do  8-)


P.S. Killers Avatar? No, sir. Iron Maiden, but was deleted when I deleted my account.
Yes Iron Maiden, Killers Album …too bad

tjr

  • Guest
Re: Idea: System.Windows.Forms from lisp via IronPython.
« Reply #9 on: March 18, 2008, 02:07:40 PM »
P.S. Killers Avatar? No, sir. Iron Maiden, but was deleted when I deleted my account.
Yes Iron Maiden, Killers Album …too bad
[/quote]
bah. I thought you meant the band the Killers. My bad, brain damage kicking in.