Well there isn't a C# forum so I figured this would be the closest related forum. I'm working on my latest project and I'm having a hell of a time debugging C# (of course it might help if I knew what I was doing). Here's the code I'm using and as far as I know it should work. I can enter my custom command in AutoCAD and it will prompt me to "Enter a Python Expression:", however it doesn't return any results. I'm assuming this is is an error in the way I'm dealing with the AutoCAD command line.
I'll keep working at it but if anyone can see something obvious that I'm doing wrong it would be great if you let me know.
#region Using directives
using System;
using System.IO;
using System.Collections;
using IronPython.Hosting;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Pynk.Wrapper;
#endregion
namespace PyAcad_net
{
public class Commands
{
//The command to type at the command line "pycommand".
[CommandMethod("pycommand", CommandFlags.Modal)]
public static void PyCommandLine_1()
{
//create a call to the command class
string args;
CommandLinePrompts.GetString( out args, "Enter a Python Expression: ", false);
PyAcad pystring = new PyAcad();
string results = pystring.pythonstring(args);
CommandLinePrompts.Message(results);
}
}
public class PyAcad
{
public PyAcad()
{
}
public string pythonstring(string Args)
{
FrameHolder pyacad = new FrameHolder();
OutputQueue results = new OutputQueue();
pyacad.ParseAndRun(Args);
string returnstring = results.ReadToEnd();
return returnstring;
}
}
}