TheSwamp

Code Red => .NET => Topic started by: WILL HATCH on February 14, 2013, 03:28:30 PM

Title: KISS
Post by: WILL HATCH on February 14, 2013, 03:28:30 PM
Had a request from the drafting department here today, they're pissed off that MText attributes are such a pain to work with.  Decided to keep it simple stupid:

Code - C#: [Select]
  1.         //[CommandMethod("Drafting", "qAtt", 0)]
  2.         [CommandMethod("qAtt"]
  3.         public void QuickAttributeEditor()
  4.         {
  5.             Document doc = Application.DocumentManager.MdiActiveDocument;
  6.             Editor ed = doc.Editor;
  7.             Database db = doc.Database;
  8.             try
  9.             {
  10.  
  11.                 using (Transaction tr = doc.TransactionManager.StartTransaction())
  12.                 {
  13.                     doc.TransactionManager.EnableGraphicsFlush(true);
  14.                     PromptNestedEntityOptions pneo = new PromptNestedEntityOptions("\nSelect attribute to edit");
  15.                     AttributeReference ar = null;
  16.                     while (true)
  17.                     {
  18.                         PromptNestedEntityResult pner = ed.GetNestedEntity(pneo);
  19.                         if (pner.Status != PromptStatus.OK) return;
  20.                         ar = pner.ObjectId.GetObject(OpenMode.ForRead) as AttributeReference;
  21.                         if (ar != null) break;
  22.                         ed.WriteMessage("\nNot an attribute reference!");
  23.                     }
  24.                     ar.UpgradeOpen();
  25.                     if (ar.IsMTextAttribute)
  26.                     {
  27.                         try
  28.                         {
  29.                             MText tempText = ar.MTextAttribute;
  30.                             ar.Visible = false;
  31.                             doc.TransactionManager.QueueForGraphicsFlush();
  32.                             doc.TransactionManager.FlushGraphics();
  33.                             InplaceTextEditor.Invoke(tempText, new InplaceTextEditorSettings());
  34.                             ar.MTextAttribute = tempText;
  35.                             ar.Visible = true;
  36.                         }
  37.                         catch (System.Exception e)
  38.                         {
  39.                             Application.ShowAlertDialog(String.Format("Error: {0}", e));
  40.                             return;
  41.                         }
  42.                     }
  43.                     else
  44.                     {
  45.                         ObjectId[] ids = new ObjectId[1] { ar.ObjectId };
  46.                         InplaceTextEditor.Invoke(ar, ref ids);
  47.                     }
  48.                     tr.Commit();
  49.                     ed.Regen();
  50.                 }
  51.             }
  52.             catch
  53.             { throw; }
  54.         }

**EDIT: was needlessly opening objects for write before they were validated as AttributeReference
Title: Re: KISS
Post by: Hugo on February 15, 2013, 09:55:11 AM
As the command to start   (Drafting)    :-(


Wie lautet der Befehl zum Starten 

Danke
Title: Re: KISS
Post by: fixo on February 15, 2013, 11:20:36 AM
Try second one : qAtt
Title: Re: KISS
Post by: Hugo on February 15, 2013, 11:38:12 AM
Super Danke  :-) :-) :-)
Title: Re: KISS
Post by: WILL HATCH on February 15, 2013, 11:42:15 AM
Sorry, in hindsight I should have taken the CommandGroup out of the code when I posted on here.  It's for a palette which organizes all of my commands on different tabs by their CommandGroup attribute
Title: Re: KISS
Post by: WILL HATCH on February 15, 2013, 12:33:36 PM
 :lmao: Ctrl + double click does the same thing
Title: Re: KISS
Post by: CADbloke on February 16, 2013, 07:47:22 PM
MText attributes are such a pain to work with. 

I'm assuming they know about Ctrl-click & Ctrl-double-click the last one to edit them in place, in the order you clicked them in. I didn't run the code (yet - I like it) but I assume it opens the full MText editor instead of the cut-down one you get with Ctrl-double click.

edit - apparently 2 inches above this text is too far for me to look. Derp!
Title: Re: KISS
Post by: WILL HATCH on February 16, 2013, 08:18:22 PM
I learned that trick after posting this... Don't know if it's different, don't actually do any drafting.  I'll look into it next week

 
MText attributes are such a pain to work with. 

I'm assuming they know about Ctrl-click & Ctrl-double-click the last one to edit them in place, in the order you clicked them in. I didn't run the code (yet - I like it) but I assume it opens the full MText editor instead of the cut-down one you get with Ctrl-double click.

edit - apparently 2 inches above this text is too far for me to look. Derp!