Code Red > .NET

Creating a "CommandMethod" through code.

<< < (2/3) > >>

TR:
What I'm currently doing is not really close to what me final goal is. Right now I'm just running python files via an Open File Dialog because it was easy to do for testing out code. However my real goal is to develop a loader or something like how lisp is now. It can be loaded and define commands. Once it's loaded the command can then be executed at any time.

If I could figure out how to create a command I would turn it into a decorator and use it like this in code:

--- Code: ---@commandmethod('testcommand')
def mytest():
    print "test command worked"

--- End code ---

Thus testcommand entered on the command line would call the mytest function and print to the command line.

TR:
I've been doing some digging using Lutz Roeder's .NET Reflector and it seems that the CommandMethod attribute registers the command using the acmgd.Autodesk.AutoCAD.Runtime.ICommandLineCallable interface. However I have yet to figure out how to use this to register a command via python code. Any thoughts?

MickD:
Tim, how does Iron Python 'integrate' with .net, after a quick look I couldn't find anything definite to say whether it runs in the clr or through the python interpreter still.
The reason I ask is that if it's still interpreted I don't think you will have much luck working as closely as you like, either you will have to create a command in .net to call a method in your python scripts or get a python script to call a .net command - swings and roundabouts really...

I know it's not the solution you're after but perhaps you can create a 'pyrun' command in .net say that asks the user for a method to run from python and runs it. To make it more like a real command the user can create a 2/3 line lisp that achieves the same as a real command, just create a lisp for each method. In fact you could get python to write such a lisp file quite easily as you know ;).

Anyway, food for thought, hope you work it out.

TR:
Mick:

I'm not 100% certain but I think it runs in the CLR. From the old IronPython page:
--- Quote ---Integrated with the Common Language Runtime - IronPython code can easily use CLR libraries and Python classes can extend CLR classes.
--- End quote ---

I'm also thinking this as I am able to consume any .NET library via IP's built in clr module.

MickD:
ok, thanks Tim, so you can write .net in Python syntax/language - cool!

In that case, how about writing real basic 'commands' to register with acad in a c#/vb dll that call methods in your ref'd in  IP dll?
Again it's not as direct as you would like but it may work, the command methods would basically be a template/copy and paste affair for those not familiar with c#/vb with a little instruction.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version