0

Does anyone know how to select objects after SendStringtoExecute? The best for me is select object using fence or a point.

Here's the part of my code:

foreach (ObjectId objId in NormalblkTblRec)
{
    if (objId.ObjectClass.Name == "AcDbArc")
    {
        Entity en1 = (Entity)trans.GetObject(objId, OpenMode.ForWrite);
        Arc arcs = (Arc)(Object)en1;
        Point3d[] arcpoints = new Point3d[] { arcs.StartPoint, arcs.EndPoint };
        Point3dCollection arcptcol = new Point3dCollection(arcpoints);
        doc.SendStringToExecute("_DIVIDE" + "\n", true, false, false);
        ed.SelectFence(arcptcol);
    }

}

The above code doesn't work. The purpose of this code is to get the coordinates of divisions of each arc (say, 10 divisions). If anyone has a better idea of doing the same purpose feel free to suggest.

Thanks a lot guys!

2 Answers2

1

Why don't you just calculate them manually? Or you can use the com document object which executes synchronously.

public static void SendCommandSynchronously(this Document doc,string command)
    {
        var acadDoc = doc.AcadDocument;
        acadDoc.GetType().InvokeMember(
            "SendCommand",
            System.Reflection.BindingFlags.InvokeMethod,
            null,
            acadDoc,
            new[] { command + "\n" });
    }

This is an extension method you can use. Or just convert to a method.

Trae Moore
  • 1,759
  • 3
  • 17
  • 32
  • I need these coordinates being generated automatically because this is an extension for AutoCAD to find all the blocks in the drawing and generate their details into an Excel file, i.e. coordinates of blocks, lines, arcs and splines, and nodes of each arc and spline, etc. This info will be used in other software. Btw, thanks for the method! I will try it out later. – Kee Jeng Ang Mar 03 '15 at 01:14
  • Just iterate the modelspace and check the types. Look at my blog, There is a link in my profile. You can do this task much easier if you do it your self. Once you have the objects, use reflection to iterate the properties. – Trae Moore Mar 04 '15 at 02:02
  • 1
    Thanks a lot! I got your point. Semi manual does make the whole thing much simpler. Thanks once again :D – Kee Jeng Ang Mar 05 '15 at 06:03
  • Helped a lot. But when I give file path in command then it cant identify the end of path and considering next argument in the path. EX: -dgnexport V8 \"C:\\Drawing990.dgn\" S Standard \"d:\\V8-Imperial-Seed3D.dgn\" – Bharat May 11 '16 at 11:12
0

Send string to execute is asynchronous meaning you won't be able to predict when it will actually run. Typically you need to pinvoke or use the send command from com. In some cases you may be able to set the selection in the editor and then run the command.

  • Yes, I understand this too but I really can't find any other way to get the coordinates programmatically. The only way I found out is by using this command. – Kee Jeng Ang Mar 03 '15 at 01:08