Author Topic: CUI to .NET  (Read 1594 times)

0 Members and 1 Guest are viewing this topic.

latour_g

  • Newt
  • Posts: 184
CUI to .NET
« 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

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: CUI to .NET
« Reply #1 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);
Speaking English as a French Frog

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: CUI to .NET
« Reply #2 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");
Speaking English as a French Frog

latour_g

  • Newt
  • Posts: 184
Re: CUI to .NET
« Reply #3 on: January 25, 2016, 01:18:51 PM »
That's what I would have needed, I'm programming for Autocad 2014 unfortunately.


gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: CUI to .NET
« Reply #4 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.         }
Speaking English as a French Frog

latour_g

  • Newt
  • Posts: 184
Re: CUI to .NET
« Reply #5 on: January 25, 2016, 03:11:24 PM »
You are right, it's working fine with the API.
Thank you !

57gmc

  • Bull Frog
  • Posts: 358
Re: CUI to .NET
« Reply #6 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.