.NET

Reply
*Tim Riley
Post 1 of 1

IronPython wrapper for AutoCAD.

92 Views, 0 Replies
10-17-2005 02:08 PM
Has anyone looked into IronPython[1] at all? I'm not much of a C#'er but
from what I understand it should be possible to create a wrapper for
IronPython.Hosting in C# and from there load it as a managed assembly into
AutoCAD. The ultimate intent of this would be the ability to use Python as a
scripting language for AutoCAD.

So far I have been able to evaluate python expressions from the command line
using the code below. However this is a far cry from anything of value, it
was more of a (lame) test.

********************code**********************

using System;

using System.Collections;

using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.DatabaseServices;

using Autodesk.AutoCAD.Runtime;

using IronPython.Hosting;

namespace PyAcadDotNet

{

public class AcadInterface

{

[CommandMethod("pyeval")]

public void pythoneval()

{

PythonEngine engine = new PythonEngine();

string required = "Enter a python Expression to evaluate:";

CommandLinePrompts.GetString(out required, required, false);

char[] newline = {'\\', 'n'};

string compare = required.TrimEnd(newline);

object results = engine.Evaluate(compare);

CommandLinePrompts.Message(results.ToString());

}

[CommandMethod("pyfile")]

public void pythonfile(string filename)

{

//add code here.

}

}

}

********************/code**********************

********************Output*********************

Command: pyeval

Enter a python Expression to evaluate:2+2

4

Command:

********************/Output********************



Does anyone think this project would be feasible or am I just a dreamer?
I'll keep trying to get something going but if anyone is interested in
helping shoot me an email to riltim___@___gmail.com. I have a SubVersion
repository for anyone interesting in coding to use.

[1]
http://www.gotdotnet.com/workspaces/workspace.aspx?id=ad7acff7-ab1e-4bcb-99c0-57ac5a3a9742

Regards,

Tim Riley
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post