TheSwamp

Code Red => .NET => Topic started by: latour_g on January 25, 2016, 12:17:08 PM

Title: CUI to .NET
Post by: latour_g on January 25, 2016, 12:17:08 PM
Hi,

I'm converting a cui into .net.  I would like to put this command in .net :
^C^C^P_ai_draworder _Back ^P

I have try this but it ain't working :

Code: [Select]
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
...
Document doc = AcadApp.DocumentManager.MdiActiveDocument;
doc.SendStringToExecute("\x03\x03\x10" + "_ai_draworder" + "\n" + "_Back" + "\n", true, false, true);

Is there a way to make it work ?

Thank you
Title: Re: CUI to .NET
Post by: gile on January 25, 2016, 12:47:27 PM
Hi,

Did you simply try:

Code - C#: [Select]
  1. doc.SendStringToExecute("_ai_draworder _back ", false, false, false);
Title: Re: CUI to .NET
Post by: gile on January 25, 2016, 01:03:51 PM
Since AutoCAD 2015, you can also use the Editor.Command() which supports selections sets as arguments.

Code - C#: [Select]
  1. var ed = AcAp.DocumentManager.MdiActiveDocument.Editor;
  2. var sel = ed.GetSelection();
  3. if (sel.Status == PromptStatus.OK)
  4.     ed.Command("_draworder", sel.Value, "", "_back");
Title: Re: CUI to .NET
Post by: latour_g on January 25, 2016, 01:18:51 PM
That's what I would have needed, I'm programming for Autocad 2014 unfortunately.

Title: Re: CUI to .NET
Post by: gile on January 25, 2016, 02:20:07 PM
Why not using the API which is sometimes simpler than calling commands.

Code - C#: [Select]
  1.         [CommandMethod("MOVEBACK", CommandFlags.UsePickSet)]
  2.         public void MoveToBack()
  3.         {
  4.             var doc = Application.DocumentManager.MdiActiveDocument;
  5.             var db = doc.Database;
  6.             var ed = doc.Editor;
  7.  
  8.             var selection = ed.GetSelection();
  9.             if (selection.Status != PromptStatus.OK)
  10.                 return;
  11.  
  12.             using (Transaction tr = db.TransactionManager.StartTransaction())
  13.             {
  14.                 var btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead);
  15.                 var order = (DrawOrderTable)tr.GetObject(btr.DrawOrderTableId, OpenMode.ForWrite);
  16.                 order.MoveToBottom(new ObjectIdCollection(selection.Value.GetObjectIds()));
  17.                 tr.Commit();
  18.             }
  19.         }
Title: Re: CUI to .NET
Post by: latour_g on January 25, 2016, 03:11:24 PM
You are right, it's working fine with the API.
Thank you !
Title: Re: CUI to .NET
Post by: 57gmc on January 25, 2016, 06:40:02 PM
Here's a small note: You may want to change the command name to "MoveToBack" so as not to be confused with the "Movebak" command.