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.
<br><br>My next issue which is somewhat coupled with the first. In AutoCAD I would develop a custom command in C# using attributes like this:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [CommandMethod(&quot;pyfile&quot;, CommandFlags.Transparent)]<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void pythonfile()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// Create a new instance of PythonEngine and set variables.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;PythonEngine engine = new PythonEngine();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;engine.AddToPath(Environment.CurrentDirectory
);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// Send Stdout and Stderr to the AutoCAD command line.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;engine.SetStdout(new AcadCommandLine());<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;engine.SetVariable(&quot;null&quot;, null);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// Display an OpenFileDialog and run the script.
<br>&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;OpenFileDialog ofd = new OpenFileDialog();<br>&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;ofd.Filter = &quot;Python files (*.py)|*.py|All files (*.*)|*.*&quot; ;<br>&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;ofd.ShowDialog();<br>&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// Run the file selected by the open file dialog box.
<br>&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;engine.RunFile(ofd.FileName);<br>&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>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.
<br><br>Anyone have any thoughts/ideas on this. I'm not necessarily looking for a full code solution, however some pointer would be extremely helpful.<br><br>Thanks for reading,<br>Tim Riley