Author Topic: [IronPython] Using C# derived form in your Ipy script  (Read 6655 times)

0 Members and 1 Guest are viewing this topic.

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
[IronPython] Using C# derived form in your Ipy script
« on: May 14, 2009, 11:58:54 PM »
As mentioned in other threads and elsewhere, it's possible to create your winforms dialogs etc in VS or Sharpdevelop so you have a nice ide to place and arrange controls with. Just compile the class lib and import it into your Ipy module.
You then need to derive from it and add your event handlers and change properties as required.

Here's a quick example based on Daniel's count layers demo.

Code: [Select]
import sys
sys.path.append('C:\\Program Files\\AutoCAD 2009')
sys.path.append('D:\\_Dev\\IPyCADv1.1\\IPyCADv1.1\\bin\\Debug')
sys.path.append('C:\\DCS_3D\\ipyscripts')
import clr
clr.AddReferenceToFile('acdbmgd.dll')
clr.AddReferenceToFile('acmgd.dll')
clr.AddReferenceToFile('IpyForm.dll')

from IpyForm import *
import Autodesk.AutoCAD.DatabaseServices as dbs
import Autodesk.AutoCAD.ApplicationServices.Application as app

class My_form(IpyForm):
        def __init__(self):
                IpyForm.__init__(self)
                self.Text = "IronPython Demo"
                self.Controls["label1"].Text = "Wow it's Python"
                self.Controls["label2"].Text = "0"
                self.Controls["button1"].Text = "Count Layers"
                self.Controls["button2"].Text = "Close"
                self.Controls["button1"].Click += self.lay_click
                self.Controls["button2"].Click += self.close_click

        def count_layers(self):
                try:
                        db = dbs.HostApplicationServices.WorkingDatabase
                        print db.ToString()
                        tm = db.TransactionManager
                        tr = tm.StartTransaction()
                        ltbl = tm.GetObject(db.LayerTableId, dbs.OpenMode.ForRead, False)
                        i = 0
                        for layer in ltbl:
                                i = i + 1
                        tr.Commit()
                        tr.Dispose()
                        return i       
                except:
                        tr.Dispose()
                        print "error"

        def close_click(self,*args):
                self.Close()

        def lay_click(self,*args):
                self.Controls["label2"].Text = str(self.count_layers())


my_form = My_form()
app.ShowModalDialog(my_form)


And the piccy of the form as designed in VS2005
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8661
  • AKA Daniel
Re: [IronPython] Using C# derived form in your Ipy script
« Reply #1 on: May 15, 2009, 12:02:49 AM »
Pretty slick!  8-)

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: [IronPython] Using C# derived form in your Ipy script
« Reply #2 on: May 15, 2009, 12:23:02 AM »
Yep, pretty simple :)
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8661
  • AKA Daniel
Re: [IronPython] Using C# derived form in your Ipy script
« Reply #3 on: May 15, 2009, 07:25:47 AM »
What do you guys think about BOO?

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: [IronPython] Using C# derived form in your Ipy script
« Reply #4 on: May 15, 2009, 10:01:17 AM »
I think BOO is very cool (Tim Wiley introduced us to it looooooong ago). The only thing that concerns me is wasted development investment should it wither and die.

PS: Nice demo Mick. :)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Spike Wilbury

  • Guest
Re: [IronPython] Using C# derived form in your Ipy script
« Reply #5 on: May 15, 2009, 10:09:21 AM »
I think BOO is very cool (Tim Wiley introduced us to it looooooong ago). The only thing that concerns me is wasted development investment should it wither and die.

PS: Nice demo Mick. :)

Wasn't other Tim now using other identity: r  ?

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: [IronPython] Using C# derived form in your Ipy script
« Reply #6 on: May 15, 2009, 10:14:40 AM »
I dunno, maybe he goes by Ringo -- he does march to a different drummer.

Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Spike Wilbury

  • Guest
Re: [IronPython] Using C# derived form in your Ipy script
« Reply #7 on: May 15, 2009, 10:16:56 AM »
I dunno, maybe he goes by Ringo -- he does march to a different drummer.



He he.....

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8661
  • AKA Daniel
Re: [IronPython] Using C# derived form in your Ipy script
« Reply #8 on: May 15, 2009, 10:18:38 AM »
Seems a good way to go, its statically typed and supports attributes, no fuss, no muss, just netload and run.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: [IronPython] Using C# derived form in your Ipy script
« Reply #9 on: May 15, 2009, 10:20:20 AM »
the clean python like syntax / syntactic sugar is very appetizing and surprisingly lo cal :D
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8661
  • AKA Daniel
Re: [IronPython] Using C# derived form in your Ipy script
« Reply #10 on: May 15, 2009, 10:24:57 AM »
Syntactic Sucralose :|

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: [IronPython] Using C# derived form in your Ipy script
« Reply #11 on: May 15, 2009, 10:27:00 AM »
wow, "boo seems good" to "boo will give you cancer" in just a couple posts; i be confused
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8661
  • AKA Daniel
Re: [IronPython] Using C# derived form in your Ipy script
« Reply #12 on: May 15, 2009, 10:29:27 AM »
 :laugh:

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8661
  • AKA Daniel
Re: [IronPython] Using C# derived form in your Ipy script
« Reply #13 on: May 15, 2009, 10:34:50 AM »
Installing BoolLangStudio now

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8661
  • AKA Daniel
Re: [IronPython] Using C# derived form in your Ipy script
« Reply #14 on: May 15, 2009, 11:19:22 AM »
nope BooLangStudio is DOA with VC2008sp1  too bad

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: [IronPython] Using C# derived form in your Ipy script
« Reply #17 on: May 16, 2009, 05:31:07 AM »
I think BOO is very cool (Tim Wiley introduced us to it looooooong ago). The only thing that concerns me is wasted development investment should it wither and die.

PS: Nice demo Mick. :)

Thanks.

Call me old fashioned but I just like Python :)

I haven't looked at Boo too much but I don't think Python is going anywhere soon and it's working well with .net so I'll stick with it for a while I think.
Ideally I'd like to hide the .net interface in helper modules that I can replace with C arx extension modules at a later date if I need more speed or to lock down some of the source code, that's the plan anyway :)
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

tjr

  • Guest
Re: [IronPython] Using C# derived form in your Ipy script
« Reply #18 on: May 18, 2009, 08:08:16 PM »
I dunno, maybe he goes by Ringo -- he does march to a different drummer.


Thanks. :)

tjr

  • Guest
Re: [IronPython] Using C# derived form in your Ipy script
« Reply #19 on: May 18, 2009, 08:12:31 PM »
Ideally I'd like to hide the .net interface in helper modules that I can replace with C arx extension modules at a later date if I need more speed or to lock down some of the source code, that's the plan anyway :)
If you're looking to hide some source code I believe you can compile to a .dll using pyc.py and then import it into IronPython. Don't hold me to this though.