I see some links on this forum and on the official forum to some classes that Tony created and shared with the community. Unfortunately those links all point to his website which is no longer available. Are those classes still available for public download? I would really love to use them as a learning experience of the power of dotnet and the Autocad API. Thanks.
Hi Tony,
I was mainly thinking of your commandline class and your overrule example. Your localsystemvariables class is available on this forum. That one has already been a great help just in thinking about the bigger picture and making sure that you can see the forest even when you are standing among the trees. Thanks again.
CommandLine.cs was written before Autodesk added the RunCommand method to the Editor class (it's a non-public method, so you have to use reflection to call it, which is quite simple to do). I'll try to get the original Overrule sample code posted, if I can find it.Why is the "RunCommand" not public?
This can be used in lieu of CommandLine.cs:Code - C#: [Select]
"RunCommand", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public );
Command: netload
Command: test
Filedia
Enter new value for FILEDIA <1>: 0
Command: (princ "Hello from the Command [1]") LISP command is not available.
Command: _line Specify first point: 0,0
Specify next point or [Undo]: 100,100
Specify next point or [Undo]:
Command: Filedia
Enter new value for FILEDIA <0>: 1
Command: (princ "Hello from the Command [3]") LISP command is not available.
Command: Hello from the WriteMessage [4]
Command: (princ "Hello from the SendStringToExecute [2]") Hello from the
SendStringToExecute [2]"Hello from the SendStringToExecute [2]"
Command: (princ)
Command: (princ "Hello from the SendStringToExecute [5]") Hello from the
SendStringToExecute [5]"Hello from the SendStringToExecute [5]"
Command: (princ)
The Command() method doesn't execute LISP.Thank you.
There are several ways to execute LISP functions from .NET.
You can P/Invoke acedInvoke() (there's a sample I wrote floating around)
You can P/Invoke acedEvaluateLisp()
You can use VL.Application.
Forget about using SendStringToExecute().
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl)]
private static extern int acedInvoke(IntPtr args, out IntPtr result);
public ResultBuffer InvokeLisp(ResultBuffer args, ref int stat)
{
IntPtr rb = IntPtr.Zero;
stat = acedInvoke(args.UnmanagedObject, out rb);
if (stat == (int)PromptStatus.OK && rb != IntPtr.Zero)
return (ResultBuffer)DisposableWrapper.Create(typeof(ResultBuffer), rb, true);
return null;
}
private void PrintResbuff(ResultBuffer res)
{
string s = "\n--------------------";
foreach (TypedValue val in res)
{
s += string.Format("\n{0}->{1}", val.TypeCode, val.Value.ToString());
}
s += "\n---------------------";
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(s);
}
var args = new ResultBuffer();
int stat = 0;
args.Add(new TypedValue((int)LispDataType.Text, "Lisp_Function"));
args.Add(new TypedValue((int)LispDataType.ObjectId, myObject.ObjectId)); //// My fake LISP routine needs an ObjectId and A Point3d
args.Add(new TypedValue((int)LispDataType.Point3d, new Point3d(0, 0, 0)));
ResultBuffer res = InvokeLisp(args, ref stat);
if (stat == 5100 && res != null)
PrintResbuff(res);
res.Dispose();
Hi,
No more need to P/Invoke acedInvoke() since A2011 as the Application.Invoke() managed method wraps it.