Author Topic: Bottom Middle and Top Middle DBText Object not aligning correctly  (Read 2196 times)

0 Members and 1 Guest are viewing this topic.

GumbyCAD

  • Newt
  • Posts: 84
Hi Team,

I have a routine that draws a piece of text.
It works very well except if I use the "Bottom Middle or Top Middle" Alignment.

It draws it but appears as "Middle Middle" alignment.

After placement I change the Justification with AutoCAD Properties Dialog and set it back again to Bottom Middle and every appears correctly.

Anyone Got any Ideas?  :embarrassed:

Code - vb.net: [Select]
  1.             Tr = CurDb.TransactionManager.StartTransaction()
  2.             Try
  3.                 Using Tr
  4.                     Dim BlkTable As BlockTable = Tr.GetObject(CurDb.BlockTableId, OpenMode.ForRead)
  5.                     Dim BlkRableRec As BlockTableRecord = Tr.GetObject(BlkTable(BlockTableRecord.PaperSpace), OpenMode.ForWrite)
  6.  
  7.                     Dim NewText As DBText = New DBText
  8.                     NewText.SetDatabaseDefaults()
  9.                     NewText.Position = New Point3d(InsertPoint.asArray)
  10.                     NewText.Height = Data.TextHeight
  11.                     NewText.TextString = Data.LabelPrefix + RetData + Data.LabelSuffix
  12.                     NewText.Rotation = Data.ActualAngle
  13.  
  14.                     Dim AlignmentFlagSet As Boolean = False
  15.  
  16.                     Select Case Data.TextAlignment
  17.                         Case "Top_Left"
  18.                             NewText.HorizontalMode = TextHorizontalMode.TextLeft
  19.                             NewText.VerticalMode = TextVerticalMode.TextTop
  20.                             AlignmentFlagSet = True
  21.                         Case "Top_Middle"
  22.                             NewText.HorizontalMode = TextHorizontalMode.TextMid
  23.                             NewText.VerticalMode = TextVerticalMode.TextTop
  24.                             AlignmentFlagSet = True
  25.                         Case "Top_Right"
  26.                             NewText.HorizontalMode = TextHorizontalMode.TextRight
  27.                             NewText.VerticalMode = TextVerticalMode.TextTop
  28.                             AlignmentFlagSet = True
  29.                         Case "Middle_Left"
  30.                             NewText.HorizontalMode = TextHorizontalMode.TextLeft
  31.                             NewText.VerticalMode = TextVerticalMode.TextVerticalMid
  32.                             AlignmentFlagSet = True
  33.                         Case "Middle_Middle"
  34.                             NewText.HorizontalMode = TextHorizontalMode.TextMid
  35.                             NewText.VerticalMode = TextVerticalMode.TextVerticalMid
  36.                             AlignmentFlagSet = True
  37.                         Case "Middle_Right"
  38.                             NewText.HorizontalMode = TextHorizontalMode.TextRight
  39.                             NewText.VerticalMode = TextVerticalMode.TextVerticalMid
  40.                             AlignmentFlagSet = True
  41.                         Case "Bottom_Left"
  42.                             NewText.HorizontalMode = TextHorizontalMode.TextLeft
  43.                             NewText.VerticalMode = TextVerticalMode.TextBottom
  44.                             AlignmentFlagSet = True
  45.                         Case "Bottom_Middle"
  46.                             NewText.HorizontalMode = TextHorizontalMode.TextMid
  47.                             NewText.VerticalMode = TextVerticalMode.TextBottom
  48.                             AlignmentFlagSet = True
  49.                         Case "Bottom_Right"
  50.                             NewText.HorizontalMode = TextHorizontalMode.TextRight
  51.                             NewText.VerticalMode = TextVerticalMode.TextBottom
  52.                             AlignmentFlagSet = True
  53.                     End Select
  54.  
  55.                     If AlignmentFlagSet = True Then
  56.                         NewText.AlignmentPoint = New Point3d(AlignPoint.asArray)
  57.                     Else
  58.                         Ed.WriteMessage("Alignment Point Skipped!" + vbCrLf)
  59.                     End If
  60.  
  61.                     'added to fix alignment issue
  62.                     'Dim WDB As Database = HostApplicationServices.WorkingDatabase
  63.                     'HostApplicationServices.WorkingDatabase = CurDb
  64.                     'NewText.AdjustAlignment(CurDb)
  65.                     'HostApplicationServices.WorkingDatabase = WDB
  66.  
  67.                     NewText.TextStyleId = GetTextStyleID(Data.TextStyle)
  68.                     NewText.LayerId = GetLayerID(Data.LabelLayer)
  69.  
  70.                     BlkRableRec.AppendEntity(NewText)
  71.  
  72.                     Tr.AddNewlyCreatedDBObject(NewText, True)
  73.                     Tr.Commit()
  74.  
  75.                 End Using
  76.             Catch ex As System.Exception
  77.                 'Something
  78.                 Ed.WriteMessage(ex.Message)
  79.             Finally
  80.  
  81.             End Try
  82.  


edit:kdub -> FORMATTING code=vbnet
« Last Edit: January 30, 2014, 01:03:19 AM by Kerry »

bargool

  • Guest
Re: Bottom Middle and Top Middle DBText Object not aligning correctly
« Reply #1 on: January 30, 2014, 12:33:59 AM »
Try to delete
Code: [Select]
NewText.Position = New Point3d(InsertPoint.asArray)If you need alignment, you have not use DBText.Position

GumbyCAD

  • Newt
  • Posts: 84
Re: Bottom Middle and Top Middle DBText Object not aligning correctly
« Reply #2 on: January 30, 2014, 02:18:42 AM »
Unfortunately Not...

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Bottom Middle and Top Middle DBText Object not aligning correctly
« Reply #3 on: January 30, 2014, 08:48:31 AM »
Try using DbText.AlignmentPoint instead of DbText.Position after you set the alignment types.
Revit 2019, AMEP 2019 64bit Win 10

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Bottom Middle and Top Middle DBText Object not aligning correctly
« Reply #4 on: January 30, 2014, 05:18:32 PM »
Yep, something like :

Code - C#: [Select]
  1.  
  2.           acText.HorizontalMode = WhateverModeYouWantToUseInThisInstance;
  3.  
  4.           if (acText.HorizontalMode != TextHorizontalMode.TextLeft)
  5.           {
  6.               acText.AlignmentPoint = acPtAlign;
  7.           }
  8.  
  9.  



Code - vb.net: [Select]
  1.  
  2.           '' Set the alignment for the text
  3.           acText.HorizontalMode = WhateverModeYouWantToUseInThisInstance
  4.  
  5.           If acText.HorizontalMode <> TextHorizontalMode.TextLeft Then
  6.               acText.AlignmentPoint = acPtAlign
  7.           End If
  8.  
  9.  
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

GumbyCAD

  • Newt
  • Posts: 84
Re: Bottom Middle and Top Middle DBText Object not aligning correctly
« Reply #5 on: February 10, 2014, 10:44:51 PM »
OK Chaps,

Solution found....  And what a crappy solution.  :realmad:

When placing Text TOP MIDDLE or BOTTOM MIDDLE

You can use the a
Code: [Select]
TextHorizontalMode.TextMid
You have to use
Code: [Select]
TextHorizontalMode.TextCenter
But  the rest use
Code: [Select]
TextHorizontalMode.TextMid when refering to the middle... GRRRRR

Stephan