Author Topic: SendCommand in the .Net  (Read 3394 times)

0 Members and 1 Guest are viewing this topic.

Nima2018

  • Newt
  • Posts: 30
SendCommand in the .Net
« 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 .

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: SendCommand in the .Net
« Reply #1 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.
Speaking English as a French Frog

Nima2018

  • Newt
  • Posts: 30
Re: SendCommand in the .Net
« Reply #2 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

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: SendCommand in the .Net
« Reply #3 on: February 19, 2019, 01:44:19 PM »
You can see this reply.
Speaking English as a French Frog