[IronPython] IronPython Attribute Workaround

Tim Riley riltim at gmail.com
Mon Jul 23 22:16:05 CEST 2007


I am messing around with some code that will allow me to use
IronPython to automate AutoCAD software via it's .NET API. I already
have hacked up some ugly C# code that creates an instance of a
PythonEngine and executes a python file a select via an open file
dialog box. All works well with this.

The next step I'd like to take is to attempt to create a mechanism for
registering AutoCAD commands via python code (so I don't have to
select a file every time I want to run it. AutoCAD's .NET API allows
you to register a command that is callable from the AutoCAD via a
CommandMethod attribute[1]. Since IP doesn't support attributes I'd
like to develop some sort of decorator that would clone the
functionality of the CommandMethod attribute. So I could execute
python code like:

@commandmethod("test")
def tester:
    print "test worked"

and it would register the test command so  I could call it from the
command line.

[1] As an example:
http://through-the-interface.typepad.com/through_the_interface/2007/07/updating-a-spec.html


Tim

On 7/23/07, Michael Foord <fuzzyman at voidspace.org.uk> wrote:
> Tim Riley wrote:
> > Michael:
> >
> > Thanks for the reply. However when reading it my eyes glazed over. Is
> > there any way you could provide a simple man like myself with some
> > example code for me to peruse?
> >
>
> What do you want to achieve? Write the IronPython code you would like -
> and I will try and provide a C# stub that you can subclass. (You will
> need a C# compiler - Visual Studio Express C# is probably the most
> straightforward if you are using Windows.)
>
> Michael Foord
> http://www.voidspace.org.uk/ironpython/index.shtml
>
> > Tim
> >
> > On 7/23/07, Michael Foord <fuzzyman at voidspace.org.uk> wrote:
> >
> >> Tim Riley wrote:
> >>
> >>> I know that IronPython doesn't support attributes but does anyone know
> >>> of a workaround that will allow IP code to use them?
> >>>
> >>>
> >> The IronPython team are strangely quiet every time someone asks this... ;-)
> >>
> >> A lot of people would like an answer to this question. Currently the
> >> only way is to use stub C# classes.
> >>
> >> Michael Foord
> >> http://www.voidspace.org.uk/ironpython/index.shtml
> >>
> >>
> >>
> >>> _______________________________________________
> >>> users mailing list
> >>> users at lists.ironpython.com
> >>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> >>>
> >>>
> >>>
> >> _______________________________________________
> >> users mailing list
> >> users at lists.ironpython.com
> >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> >>
> >>
> > _______________________________________________
> > Users mailing list
> > Users at lists.ironpython.com
> > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> >
> >
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>



More information about the Ironpython-users mailing list