Author Topic: Annotative Mtext  (Read 2148 times)

0 Members and 1 Guest are viewing this topic.

Jeff H

  • Needs a day job
  • Posts: 6144
Annotative Mtext
« on: October 29, 2012, 12:59:25 PM »
If you are adding MText from an Annotative style is this the way you have to calculate text height?
Code - C#: [Select]
  1. mtxt.TextHeight = (1.0 / Db.Cannoscale.Scale) * txtStyleTblRecord.TextSize;
  2.  
Testing code
Code - C#: [Select]
  1.  
  2.          [CommandMethod("MTL")]
  3.         public void MTL()
  4.         {
  5.             MtxtCommand(AttachmentPoint.TopLeft);
  6.         }
  7.         [CommandMethod("MTC")]
  8.         public void MTC()
  9.         {
  10.             MtxtCommand(AttachmentPoint.TopCenter);
  11.         }
  12.         [CommandMethod("MTR")]
  13.         public void MTR()
  14.         {
  15.             MtxtCommand(AttachmentPoint.TopRight);
  16.         }
  17.         [CommandMethod("MML")]
  18.         public void MML()
  19.         {
  20.             MtxtCommand(AttachmentPoint.MiddleLeft);
  21.         }
  22.         [CommandMethod("MMC")]
  23.         public void MMC()
  24.         {
  25.             MtxtCommand(AttachmentPoint.MiddleCenter);
  26.         }
  27.         [CommandMethod("MMR")]
  28.         public void MMR()
  29.         {
  30.             MtxtCommand(AttachmentPoint.MiddleRight);
  31.         }
  32.         [CommandMethod("MBL")]
  33.         public void MBL()
  34.         {
  35.             MtxtCommand(AttachmentPoint.BottomLeft);
  36.         }
  37.         [CommandMethod("MBC")]
  38.         public void MBC()
  39.         {
  40.             MtxtCommand(AttachmentPoint.BottomCenter);
  41.         }
  42.         [CommandMethod("MBR")]
  43.         public void MBR()
  44.         {
  45.             MtxtCommand(AttachmentPoint.BottomRight);
  46.         }
  47.         private void MtxtCommand(AttachmentPoint attachPnt)
  48.         {
  49.             PromptPointOptions ppo = new PromptPointOptions("\nSelect Mtext's " + Enum.GetName(typeof(AttachmentPoint), attachPnt) + " attachment point: ");
  50.  
  51.             PromptPointResult ppr = Ed.GetPoint(ppo);
  52.             if (ppr.Status != PromptStatus.OK)
  53.             {
  54.                 return;
  55.             }
  56.             using (Transaction trx = Db.TransactionManager.StartTransaction())
  57.             {
  58.                 using (MText mtxt = new MText())
  59.                 {
  60.                     mtxt.SetDatabaseDefaults();
  61.                     mtxt.Contents = "";
  62.                     mtxt.Location = ppr.Value;
  63.                     mtxt.SetAttachmentMovingLocation(attachPnt);
  64.                     mtxt.TextStyleId = Db.Textstyle;
  65.                     TextStyleTableRecord txtStyleTblRecord = Db.Textstyle.GetDBObject<TextStyleTableRecord>();
  66.                     if (txtStyleTblRecord.Annotative == AnnotativeStates.True)
  67.                     {
  68.                         mtxt.Annotative = AnnotativeStates.True;
  69.                         ObjectContextManager ocm =Db.ObjectContextManager;
  70.                         ObjectContextCollection occ =ocm.GetContextCollection("ACDB_ANNOTATIONSCALES");
  71.                         ObjectContexts.AddContext(mtxt, occ.CurrentContext);
  72.                         mtxt.TextHeight = (1.0 / Db.Cannoscale.Scale) * txtStyleTblRecord.TextSize;
  73.                     }
  74.                     else
  75.                     {
  76.                         mtxt.TextHeight = Db.Textsize;
  77.                     }
  78.                     InplaceTextEditorSettings ipts = new InplaceTextEditorSettings();
  79.                     InplaceTextEditor.Invoke(mtxt, ipts);
  80.                     if (!String.IsNullOrWhiteSpace(mtxt.Contents))
  81.                     {
  82.                         BlockTableRecord btr = Db.CurrentSpace(OpenMode.ForWrite);
  83.                         btr.AppendEntity(mtxt);
  84.                         trx.AddNewlyCreatedDBObject(mtxt, true);
  85.                     }
  86.  
  87.                 }
  88.                 trx.Commit();
  89.             }
  90.         }
  91.  

Uses these Extension method
Code - C#: [Select]
  1.  
  2.          /// <summary>
  3.         /// Author: Tony Tanzillo
  4.         /// Source: http://www.theswamp.org/index.php?topic=41720.msg468319#msg468319
  5.         /// </summary>
  6.         /// <typeparam name="T"></typeparam>
  7.         /// <param name="id"></param>
  8.         /// <returns></returns>
  9.         public static T GetDBObject<T>(this ObjectId id, OpenMode mode = OpenMode.ForRead) where T : DBObject
  10.         {
  11.             if (id.IsNull)
  12.             {
  13.                 throw new ArgumentNullException("id is null");
  14.             }
  15.             return (T)id.Database.TransactionManager.GetObject(id, mode, id.IsErased, false);
  16.         }
  17.  
  18.  
  19.         /// <summary>
  20.         /// Author: Tony Tanzillo
  21.         /// Source: http://www.theswamp.org/index.php?topic=41311.msg464457#msg464457
  22.         /// Open and return the BlockTableRecord for the current space in the given database:
  23.         /// </summary>
  24.         /// <param name="db"></param>
  25.         /// <param name="mode"></param>
  26.         /// <returns></returns>
  27.         public static BlockTableRecord CurrentSpace(this Database db, OpenMode mode = OpenMode.ForRead)
  28.         {
  29.             return (BlockTableRecord)db.CurrentSpaceId.GetObject(mode, false, false);
  30.         }
  31.  
« Last Edit: October 29, 2012, 01:04:47 PM by Jeff H »

Jeff H

  • Needs a day job
  • Posts: 6144
Re: Annotative Mtext
« Reply #1 on: November 13, 2012, 01:20:41 AM »
Looks like SetFromStyle() will make annotative and add annotation scale