[IronPython] Strange Embedding Questions

Dino Viehland dinov at exchange.microsoft.com
Tue Apr 11 21:56:15 CEST 2006

You should be able to set Multiselect on the FileOpenDialog to enable choosing of more than one file (although that may not be exactly what you're wanting).

Unfortunately we don't have a way to define the CommandMethod from Python because we don't yet support static compilation & custom attributes (but it's starting to seem like it's one of our most popular feature requests).

What you might be able to do is either compile a wrapper assembly on the fly per-py file that knows about the .py file that the user wants (I'm assuming AutoCAD uses reflection to discover the command methods in an assembly and you can't instantiate new instances of the class w/ CommandMethod w/ different filenames - which would seem like the easiest solution).

Do you want to help develop Dynamic languages on CLR?<http://members.microsoft.com/careers/search/details.aspx?JobID=6D4754DE-11F0-45DF-8B78-DC1B43134038> (http://members.microsoft.com/careers/search/details.aspx?JobID=6D4754DE-11F0-45DF-8B78-DC1B43134038)
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Tim Riley
Sent: Tuesday, April 11, 2006 12:16 PM
To: Discussion of IronPython
Subject: [IronPython] Strange Embedding Questions

I have an application that I am working on which basically will provide IronPython as a scripting language for AutoCAD. I have a command now that will allow me to select an external python file and run it in AutoCAD, manipulating objects and such. This works fine for testing purposes but in order to release this as a tool that people will use for production purposes I need to develop some sort of loading mechanism that will allow me to do something like load 12 python files at once and call them as needed instead of having an Open File Dialog box pop up every time a user wants to run a script.

My next issue which is somewhat coupled with the first. In AutoCAD I would develop a custom command in C# using attributes like this:

       [CommandMethod("pyfile", CommandFlags.Transparent)]
       public void pythonfile()
           // Create a new instance of PythonEngine and set variables.
           PythonEngine engine = new PythonEngine();
           engine.AddToPath(Environment.CurrentDirectory );
           // Send Stdout and Stderr to the AutoCAD command line.
           engine.SetStdout(new AcadCommandLine());
           engine.SetVariable("null", null);

           // Display an OpenFileDialog and run the script.
       OpenFileDialog ofd = new OpenFileDialog();
       ofd.Filter = "Python files (*.py)|*.py|All files (*.*)|*.*" ;

       // Run the file selected by the open file dialog box.


Basically I need to come up with some method of defining that CommandMethod Attribute from python file. I'm not necessarily concerned how ugly of a hack it will be but I need a method of defining custom commands from an external file.

Anyone have any thoughts/ideas on this. I'm not necessarily looking for a full code solution, however some pointer would be extremely helpful.

Thanks for reading,
Tim Riley
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20060411/e66ff2e5/attachment.html>

More information about the Ironpython-users mailing list