TheSwamp

Code Red => .NET => Topic started by: Nima2018 on February 19, 2019, 05:55:38 AM

Title: SendCommand in the .Net
Post by: Nima2018 on February 19, 2019, 05:55:38 AM
Hi,

I want load and run one of the my Already written routine in autolisp via below codes :

Code: [Select]
                string appPath = Directory.GetCurrentDirectory();
                appPath = appPath.Replace(@"\", @"/");
                string my_cmd = "(load " + Convert.ToChar(34) + appPath + "/Tci2.lsp" + "" + Convert.ToChar(34) + ") ";
                acDoc.Editor.Command(my_cmd + "\r");
                acDoc.Editor.Command("Tci2" + "\r");

But I get an error in Autocad screen . Please find out what the problem is with this code .
Meanwhile, many times I have used the phrase in the Autocad Interop Com Api and have not encountered any errors.
Is there any way in  the Autocad .net api for using SendCommand directly .
Title: Re: SendCommand in the .Net
Post by: gile on February 19, 2019, 07:09:56 AM
Hi,

Unlike SendStringToExecute() or SendCommand() which requires a string as argument, EditorCommand() method is quite similar to the command LISP function, it accepts typed arguments (string, int, double, Point3d, ObjectId, SelectionSet...)

If you want to use SendCommand(), you can acces to COM without referencing the COM libraries by using the dynamic type (late binding)
Code - C#: [Select]
  1. dynamic acadApp = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
  2. var thisDrawing = acadApp.ActiveDocument;
  3. thisDrawing.SendCommand(...);

But with plain .NET you can call LISP function using the Application.Invoke() method.
Title: Re: SendCommand in the .Net
Post by: Nima2018 on February 19, 2019, 12:21:28 PM
ِHello Dear sir (jile) and thank you for giving advice.
Please, if possible, show how to use the second method (using .NET API),
Quote
But with plain .NET you can call LISP function using the Application.Invoke() method.
as in the above code.
I recently referred to .NET and do not know much about the differences .
My acquaintance is the same as ATOLISP and VBA
Title: Re: SendCommand in the .Net
Post by: gile on February 19, 2019, 01:44:19 PM
You can see this reply (http://www.theswamp.org/index.php?topic=54554.msg590486#msg590486).