Author Topic: KISS  (Read 3735 times)

0 Members and 1 Guest are viewing this topic.

WILL HATCH

  • Bull Frog
  • Posts: 450
KISS
« 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
« Last Edit: February 15, 2013, 11:43:13 AM by WILL HATCH »

Hugo

  • Bull Frog
  • Posts: 422
Re: KISS
« Reply #1 on: February 15, 2013, 09:55:11 AM »
As the command to start   (Drafting)    :-(


Wie lautet der Befehl zum Starten 

Danke

fixo

  • Guest
Re: KISS
« Reply #2 on: February 15, 2013, 11:20:36 AM »
Try second one : qAtt

Hugo

  • Bull Frog
  • Posts: 422
Re: KISS
« Reply #3 on: February 15, 2013, 11:38:12 AM »
Super Danke  :-) :-) :-)

WILL HATCH

  • Bull Frog
  • Posts: 450
Re: KISS
« Reply #4 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

WILL HATCH

  • Bull Frog
  • Posts: 450
Re: KISS
« Reply #5 on: February 15, 2013, 12:33:36 PM »
 :lmao: Ctrl + double click does the same thing

CADbloke

  • Bull Frog
  • Posts: 342
  • Crash Test Dummy
Re: KISS
« Reply #6 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!
« Last Edit: February 16, 2013, 08:15:42 PM by CADbloke »

WILL HATCH

  • Bull Frog
  • Posts: 450
Re: KISS
« Reply #7 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!