Author Topic: how to get update selection after run sendcommand pedit  (Read 209 times)

0 Members and 1 Guest are viewing this topic.

daboho

  • Newt
  • Posts: 35
how to get update selection after run sendcommand pedit
« on: June 28, 2022, 04:38:05 AM »
i have line ,arc and send command to change to polyline
how to make get value is polyline after send command pedit,in my code still read first selection (line)
i want to make result selection is after pedit how to update this
Code: [Select]
[CommandMethod("IMP",CommandFlags.UsePickSet|CommandFlags.Modal)]
        public void SELECM()
        {
            var ss = ed.GetSelection();
            if (ss.Status != PromptStatus.OK) return;
            ObjectId[] myID = ss.Value.GetObjectIds().ToArray();
            ed.SetImpliedSelection(myID);
            string cmd = "._pedit\n_m\n_p\n\n_Y\n_Join\n\n\n";
            doc.SendStringToExecute(cmd, true, false, false);
            ed.Regen();
            var ss1 = ed.SelectImplied();
            if (ss1.Status != PromptStatus.OK) return;
           
            using (var tr = db.TransactionManager.StartTransaction())
            {
                foreach (SelectedObject s in ss1.Value)
                {
                    var ob = tr.GetObject(s.ObjectId, OpenMode.ForRead) as DBObject;
                   //[b]this result object is still line[/b]
                    //[b]how to make update selection result selection is object after has to pedit where is object polyline after send command pedit[/b]
                    ed.WriteMessage("\nobject type " + ob.GetType().Name.ToString());
                }
                tr.Commit();
            }
     
        }

gile

  • Water Moccasin
  • Posts: 2392
  • Marseille, France
Re: how to get update selection after run sendcommand pedit
« Reply #1 on: June 28, 2022, 07:07:19 AM »
Hi,

SendStringToExecute works asynchronously (i.e. the string command is executed at the end of the code).
You can use Editor.Command() which works synchronously and accept typed arguments such as numbers, ObjectId or SelectSet (the same way as the command LISP function).
Code - C#: [Select]
  1.         [CommandMethod("IMP", CommandFlags.UsePickSet | CommandFlags.Modal)]
  2.         public static void SELECM()
  3.         {
  4.             var doc = Application.DocumentManager.MdiActiveDocument;
  5.             var db = doc.Database;
  6.             var ed = doc.Editor;
  7.             var ss = ed.GetSelection();
  8.             if (ss.Status != PromptStatus.OK) return;
  9.             ed.Command("_.pedit", "_m", ss.Value, "", "_y", "_join", "", "");
  10.             var ss1 = ed.SelectLast();
  11.             if (ss1.Status != PromptStatus.OK) return;
  12.  
  13.             using (var tr = db.TransactionManager.StartTransaction())
  14.             {
  15.                 foreach (ObjectId id in ss1.Value.GetObjectIds())
  16.                 {
  17.                     ed.WriteMessage("\nObject type: " + id.ObjectClass.DxfName);
  18.                 }
  19.                 tr.Commit();
  20.             }
  21.         }
Speaking English as a French Frog

daboho

  • Newt
  • Posts: 35
Re: how to get update selection after run sendcommand pedit
« Reply #2 on: June 28, 2022, 11:41:04 AM »
thank gile i was test but only one object is selected not all
ed.WriteMessage("\ncount object : " + ss1.Value.Count.ToString()); result only 1
in first selection is 3 line

gile

  • Water Moccasin
  • Posts: 2392
  • Marseille, France
Re: how to get update selection after run sendcommand pedit
« Reply #3 on: June 28, 2022, 02:55:49 PM »
The 3 lines do not exist anymore, the command PEDIT created a new polyline and deleted the 3 lines.
Speaking English as a French Frog

daboho

  • Newt
  • Posts: 35
Re: how to get update selection after run sendcommand pedit
« Reply #4 on: June 29, 2022, 12:01:40 AM »
My mean var ss1=ed.SelecLast()
Only select single last one object
In ss1.count only one of object (only can save single last object or can not save multiple object)