Author Topic: Programming with IronPython  (Read 23669 times)

0 Members and 1 Guest are viewing this topic.

Krasyn

  • Guest
Re: Programming with IronPython
« Reply #15 on: August 26, 2008, 12:32:27 PM »
i tried to draw a circle with COM via PyAcad.Net and it worked.
Code: [Select]
from System import Array,Type
import clr
clr.AddReferenceToFileAndPath(r"c:\Program Files\IronPython\Tutorial\AutoCAD.dll") #path to the assembly generated from acax17enu.tlb by tlbimp.exe from netsdk
from AutoCAD import *
import Autodesk.AutoCAD.ApplicationServices as ap
doc = ap.Application.DocumentManager.MdiActiveDocument.AcadDocument
acadApp = doc.Application
doc.ActiveSpace == AcActiveSpace.acModelSpace
pnt = Array.CreateInstance(Type.GetType("System.Double"),3)
for i,coord in enumerate(doc.Utility.GetPoint(Prompt = "\ncenter of the circle: ")):
pnt.SetValue(coord,i)
circle = doc.ModelSpace.AddCircle(pnt,100)
circle.color = ACAD_COLOR.acMagenta
acadApp.ZoomExtents()

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: Programming with IronPython
« Reply #16 on: August 26, 2008, 01:26:09 PM »
i tried to draw a circle with COM via PyAcad.Net and it worked.
...

Ah You’re Awesome!  8-)

…And Welcome To theSwamp  :-)

tjr

  • Guest
Re: Programming with IronPython
« Reply #17 on: August 27, 2008, 01:03:17 AM »
i tried to draw a circle with COM via PyAcad.Net and it worked.
Code: [Select]
from System import Array,Type
import clr
clr.AddReferenceToFileAndPath(r"c:\Program Files\IronPython\Tutorial\AutoCAD.dll") #path to the assembly generated from acax17enu.tlb by tlbimp.exe from netsdk
from AutoCAD import *
import Autodesk.AutoCAD.ApplicationServices as ap
doc = ap.Application.DocumentManager.MdiActiveDocument.AcadDocument
acadApp = doc.Application
doc.ActiveSpace == AcActiveSpace.acModelSpace
pnt = Array.CreateInstance(Type.GetType("System.Double"),3)
for i,coord in enumerate(doc.Utility.GetPoint(Prompt = "\ncenter of the circle: ")):
pnt.SetValue(coord,i)
circle = doc.ModelSpace.AddCircle(pnt,100)
circle.color = ACAD_COLOR.acMagenta
acadApp.ZoomExtents()
Very nice work.

Also very nice to see some people doing some exploring with the PyAcad.NET code.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: Programming with IronPython
« Reply #18 on: August 27, 2008, 01:43:10 AM »
Something like this would work for Bricscad as well

Krasyn

  • Guest
Re: Programming with IronPython
« Reply #19 on: August 27, 2008, 07:26:04 AM »
Thank you. I'm going to rewrite some VBA examples (AutoCAD ActiveX and VBA Reference) in Python later in my spare time
I think PyAcad.Net is  cool but
we need full-featured IronPython IDE (with visual UI designer) integrated in AutoCAD. A script launcher is not enough.



MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: Programming with IronPython
« Reply #20 on: August 27, 2008, 07:35:09 AM »
There are a couple of options for an IronPython IDE, SharpDevelop has an IronPython addin and you can also integrate IronPython into VS2005 and VS2008 (you can just ue the vs2008 ide shell for free for this one).

I have a few links at work, I'll post them tomorrow if you're interested.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

tjr

  • Guest
Re: Programming with IronPython
« Reply #21 on: August 27, 2008, 10:30:30 PM »
Thank you. I'm going to rewrite some VBA examples (AutoCAD ActiveX and VBA Reference) in Python later in my spare time
I think PyAcad.Net is  cool but
we need full-featured IronPython IDE (with visual UI designer) integrated in AutoCAD. A script launcher is not enough.
As Mick said you can always visually layout your UI using SharDevelop 3.0 which as IronPython support. You could also create all the from skeleton in C# or VB.NET, compile it to a dll and inherit it in an IronPython class. That is very trivial.

Also if anyone has the time and wants to try their hand at a simple pyacad.net script editor that runs in AutoCAD as a separate project I certainly wouldn't object. Might even be easy with dotnetfireball.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: Programming with IronPython
« Reply #22 on: August 27, 2008, 11:00:53 PM »
After looking at the code, I think it would be easy enough for Tim to add references to AutoCAD’s COM Api, so you wouldn’t have to do this
clr.AddReferenceToFileAndPath(…)

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: Programming with IronPython
« Reply #23 on: August 27, 2008, 11:05:59 PM »
Check this out, I added a new layout “MyLayout” to Bricscad, using this code, my DRXNET and PyBCadDotNet  :laugh:

Code: [Select]
#thanks to kwb just because
import System
import BricscadApp as OdAp
import BricscadDb as OdDb
import DRXNET.OdAp as ObApB

application = ObApB.Application.AcadApplication
document = application.ActiveDocument
myLayout = document.Layouts.Add("MyLayout")


It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: Programming with IronPython
« Reply #24 on: August 27, 2008, 11:30:19 PM »
and a line  :-o

Code: [Select]
#thanks to kwb
import System
import BricscadApp as OdAp
import BricscadDb as OdDb
import DRXNET.OdAp as ObApB

from System import Array,Type

application = ObApB.Application.AcadApplication
document = application.ActiveDocument;

pt1 = Array.CreateInstance(Type.GetType("System.Double"),3)
pt1.SetValue(0, 0)
pt1.SetValue(0, 1)
pt1.SetValue(0, 2)

pt2 = Array.CreateInstance(Type.GetType("System.Double"),3)
pt2.SetValue(100, 0)
pt2.SetValue(100, 1)
pt2.SetValue(0, 2)

line = document.ModelSpace.AddLine(pt1,pt2);
line.Update();

tjr

  • Guest
Re: Programming with IronPython
« Reply #25 on: August 27, 2008, 11:30:42 PM »
After looking at the code, I think it would be easy enough for Tim to add references to AutoCAD’s COM Api, so you wouldn’t have to do this
clr.AddReferenceToFileAndPath(…)
I'm still having trouble understanding why anyone would want to get at AutoCAD through COM in PyAcad.NET when you have the entire .NET API available to you.

tjr

  • Guest
Re: Programming with IronPython
« Reply #26 on: August 27, 2008, 11:34:10 PM »
Check this out, I added a new layout “MyLayout” to Bricscad, using this code, my DRXNET and PyBCadDotNet  :laugh:

Code: [Select]
#thanks to kwb just because
import System
import BricscadApp as OdAp
import BricscadDb as OdDb
import DRXNET.OdAp as ObApB

application = ObApB.Application.AcadApplication
document = application.ActiveDocument
myLayout = document.Layouts.Add("MyLayout")
This is a perfect example of the kind of stuff I love to see. It's the true hacker spirit.

You never cease to amaze or inspire Dan.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: Programming with IronPython
« Reply #27 on: August 27, 2008, 11:37:40 PM »
After looking at the code, I think it would be easy enough for Tim to add references to AutoCAD’s COM Api, so you wouldn’t have to do this
clr.AddReferenceToFileAndPath(…)
I'm still having trouble understanding why anyone would want to get at AutoCAD through COM in PyAcad.NET when you have the entire .NET API available to you.

Why not? For simple scripts, like adding a layout, it’s much easier to use COM. While I don’t use COM much, I know it’s in the toolbox

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: Programming with IronPython
« Reply #28 on: August 27, 2008, 11:38:09 PM »
Check this out, I added a new layout “MyLayout” to Bricscad, using this code, my DRXNET and PyBCadDotNet  :laugh:

Code: [Select]
#thanks to kwb just because
import System
import BricscadApp as OdAp
import BricscadDb as OdDb
import DRXNET.OdAp as ObApB

application = ObApB.Application.AcadApplication
document = application.ActiveDocument
myLayout = document.Layouts.Add("MyLayout")
This is a perfect example of the kind of stuff I love to see. It's the true hacker spirit.

You never cease to amaze or inspire Dan.

Thanks I just wanted to see If I could do it  :-)

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: Programming with IronPython
« Reply #29 on: August 27, 2008, 11:48:23 PM »
here is ths C# code