Author Topic: Send string to execute synchronously  (Read 5908 times)

0 Members and 1 Guest are viewing this topic.

TJK44

  • Guest
Send string to execute synchronously
« on: June 20, 2012, 02:43:30 PM »
Just messing around with this to see how it works. Having an issue where i'm trying to execute a bunch of commands in a row and its just not doing anything.

Code: [Select]
                    Dim rb As New ResultBuffer()
                    rb.Add(New TypedValue(5005, "_move"))
                    rb.Add(New TypedValue(5005, "all"))
                    rb.Add(New TypedValue(5005, pt2.X.ToString & "," & pt2.Y.ToString & "," & pt2.Z.ToString))
                    rb.Add(New TypedValue(5005, "0,0,0"))

                    rb.Add(New TypedValue(5005, "zoom"))
                    rb.Add(New TypedValue(5005, "e"))

                    rb.Add(New TypedValue(5005, "qsave"))

                    rb.Add(New TypedValue(5005, "filedia"))
                    rb.Add(New TypedValue(5005, "0"))

                    rb.Add(New TypedValue(5005, "saveas"))
                    rb.Add(New TypedValue(5005, "2007"))
                    rb.Add(New TypedValue(5005, "C:\test1.dwg"))

                    rb.Add(New TypedValue(5005, "saveas"))
                    rb.Add(New TypedValue(5005, "2007"))
                    rb.Add(New TypedValue(5005, "C:\test2.dwg"))

                    rb.Add(New TypedValue(5005, "filedia"))
                    rb.Add(New TypedValue(5005, "1"))

                    rb.Add(New TypedValue(5005, "close"))
                    acedCmd(rb.UnmanagedObject)

I was able to get this little bit to work, but nothing long and complicated.

Code: [Select]
        <DllImport("acad.exe", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Cdecl, EntryPoint:="acedCmd")> _
        Private Shared Function acedCmd(ByVal vlist As System.IntPtr) As Integer
        End Function

        Public Sub ZoomToExtnts()
            Dim rb As New ResultBuffer()
            rb.Add(New TypedValue(5005, "_ZOOM"))
            rb.Add(New TypedValue(5005, "_e"))
            acedCmd(rb.UnmanagedObject)
        End Sub

Thanks,

Ted

Jeff H

  • Needs a day job
  • Posts: 6151
Re: Send string to execute synchronously
« Reply #1 on: June 21, 2012, 10:36:28 AM »
Search for Tony's T CommandLine example.
 
 
That is PInvoking acedcmd not calling SendStringExecute so you can pass points, doubles, etc..... and do not send a string for every argument.


gile

  • Gator
  • Posts: 2520
  • Marseille, France
Re: Send string to execute synchronously
« Reply #3 on: June 25, 2012, 06:49:22 AM »
Have a look here.

Using the Command() method:

Code - C#: [Select]
  1. Command("_move", "_all", pt2, Point3d.Origin);
  2. Command("_zoom", "_extents");
  3. Command("_qsave");
  4. ...
Speaking English as a French Frog

Benzirpi

  • Guest
Re: Send string to execute synchronously
« Reply #4 on: June 25, 2012, 09:41:39 AM »
I didn't try myself, but just this morning I was reading a entry on Kean Walmsley's blog (http://through-the-interface.typepad.com/through_the_interface/blocks/). There, he tells about a little trick from Viru Aithal from DevTech India  in order to use reflection to call SendCommand() synchronous COM method without creating a dependency on the AutoCAD Type Library.


Code: [Select]
doc = Application.DocumentManager.Open(res.StringResult, false);

../..

object ActiveDocument = doc.AcadDocument;
object[] data = { "_.BLOCKICON " + blk.Name  + "\n" };
ActiveDocument.GetType().InvokeMember("SendCommand",
                                      System.Reflection.BindingFlags.InvokeMethod,
                                      null, ActiveDocument, data
                                     );

Delegate

  • Guest
Re: Send string to execute synchronously
« Reply #5 on: June 25, 2012, 10:37:31 AM »

Similarly as I have recently found from The Master you can do this:

Code - C#: [Select]
  1. namespace AutoCAD_CSharp_plug_in1
  2. {  
  3.     public class MyCommands
  4.     {        
  5.         [CommandMethod("MyCommand")]
  6.         public void MyCommand()
  7.         {          
  8.                 string data = "_.ZOOM " + "E ";
  9.                 Application.DocumentManager.MdiActiveDocument.Commands(data);        
  10.            
  11.         }
  12.     }
  13.  
  14.     public static class MyDocExtensions
  15.     {
  16.         public static void Commands(this Document doc, string data)
  17.         {            
  18.             dynamic acadDoc = doc.AcadDocument;
  19.             acadDoc.SendCommand(data);
  20.         }
  21.     }
  22.  
  23. }

I didn't try myself, but just this morning I was reading a entry on Kean Walmsley's blog (http://through-the-interface.typepad.com/through_the_interface/blocks/). There, he tells about a little trick from Viru Aithal from DevTech India  in order to use reflection to call SendCommand() synchronous COM method without creating a dependency on the AutoCAD Type Library.


Code: [Select]
doc = Application.DocumentManager.Open(res.StringResult, false);

../..

object ActiveDocument = doc.AcadDocument;
object[] data = { "_.BLOCKICON " + blk.Name  + "\n" };
ActiveDocument.GetType().InvokeMember("SendCommand",
                                      System.Reflection.BindingFlags.InvokeMethod,
                                      null, ActiveDocument, data
                                     );