Bottom Middle and Top Middle DBText Object not aligning correctly

Bottom Middle and Top Middle DBText Object not aligning correctly

Anonymous
Not applicable
1,429 Views
4 Replies
Message 1 of 5

Bottom Middle and Top Middle DBText Object not aligning correctly

Anonymous
Not applicable

Hi Guys,


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?

 

 

 

 

Tr = CurDb.TransactionManager.StartTransaction()
            Try
                Using Tr
                    Dim BlkTable As BlockTable = Tr.GetObject(CurDb.BlockTableId, OpenMode.ForRead)
                    Dim BlkRableRec As BlockTableRecord = Tr.GetObject(BlkTable(BlockTableRecord.PaperSpace), OpenMode.ForWrite)
 
                    Dim NewText As DBText = New DBText
                    NewText.SetDatabaseDefaults()
                    NewText.Position = New Point3d(InsertPoint.asArray)
                    NewText.Height = Data.TextHeight
                    NewText.TextString = Data.LabelPrefix + RetData + Data.LabelSuffix
                    NewText.Rotation = Data.ActualAngle
 
                    Dim AlignmentFlagSet As Boolean = False
 
                    Select Case Data.TextAlignment
                        Case "Top_Left"
                            NewText.HorizontalMode = TextHorizontalMode.TextLeft
                            NewText.VerticalMode = TextVerticalMode.TextTop
                            AlignmentFlagSet = True
                        Case "Top_Middle"
                            NewText.HorizontalMode = TextHorizontalMode.TextMid
                            NewText.VerticalMode = TextVerticalMode.TextTop
                            AlignmentFlagSet = True
                        Case "Top_Right"
                            NewText.HorizontalMode = TextHorizontalMode.TextRight
                            NewText.VerticalMode = TextVerticalMode.TextTop
                            AlignmentFlagSet = True
                        Case "Middle_Left"
                            NewText.HorizontalMode = TextHorizontalMode.TextLeft
                            NewText.VerticalMode = TextVerticalMode.TextVerticalMid
                            AlignmentFlagSet = True
                        Case "Middle_Middle"
                            NewText.HorizontalMode = TextHorizontalMode.TextMid
                            NewText.VerticalMode = TextVerticalMode.TextVerticalMid
                            AlignmentFlagSet = True
                        Case "Middle_Right"
                            NewText.HorizontalMode = TextHorizontalMode.TextRight
                            NewText.VerticalMode = TextVerticalMode.TextVerticalMid
                            AlignmentFlagSet = True
                        Case "Bottom_Left"
                            NewText.HorizontalMode = TextHorizontalMode.TextLeft
                            NewText.VerticalMode = TextVerticalMode.TextBottom
                            AlignmentFlagSet = True
                        Case "Bottom_Middle"
                            NewText.HorizontalMode = TextHorizontalMode.TextMid
                            NewText.VerticalMode = TextVerticalMode.TextBottom
                            AlignmentFlagSet = True
                        Case "Bottom_Right"
                            NewText.HorizontalMode = TextHorizontalMode.TextRight
                            NewText.VerticalMode = TextVerticalMode.TextBottom
                            AlignmentFlagSet = True
                    End Select
 
                    If AlignmentFlagSet = True Then
                        NewText.AlignmentPoint = New Point3d(AlignPoint.asArray)
                    Else
                        Ed.WriteMessage("Alignment Point Skipped!" + vbCrLf)
                    End If
 
                    'added to fix alignment issue
                    'Dim WDB As Database = HostApplicationServices.WorkingDatabase
                    'HostApplicationServices.WorkingDatabase = CurDb
                    'NewText.AdjustAlignment(CurDb)
                    'HostApplicationServices.WorkingDatabase = WDB
 
                    NewText.TextStyleId = GetTextStyleID(Data.TextStyle)
                    NewText.LayerId = GetLayerID(Data.LabelLayer)
 
                    BlkRableRec.AppendEntity(NewText)
 
                    Tr.AddNewlyCreatedDBObject(NewText, True)
                    Tr.Commit()
 
                End Using
            Catch ex As System.Exception
                'Something
                Ed.WriteMessage(ex.Message)
            Finally
 
            End Try

 

0 Likes
Accepted solutions (1)
1,430 Views
4 Replies
Replies (4)
Message 2 of 5

hgasty1001
Advisor
Advisor

Hi,

 

Not sure, but i think that if the text is aligned you have to set only the AlignmentPoint, in other words, delete the line with NewText.Position=..., and set its position only if the text has NOT  an aligment flag.

 

Gaston Nunez

0 Likes
Message 3 of 5

absStructural
Enthusiast
Enthusiast
I have noticed the same thing - and typically write something like:

if(DBText.IsDefaultAlignment)
DBText.Position = pt;
else
DBText.AlignmentPoint = pt;
0 Likes
Message 4 of 5

Anonymous
Not applicable

Thanks guys Ill give it a go and get back to you.

 

Stephan

0 Likes
Message 5 of 5

Anonymous
Not applicable
Accepted solution

OK Chaps,

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

When placing Text TOP MIDDLE or BOTTOM MIDDLE

You can use the a

 
TextHorizontalMode.TextCenter

 But  the rest use (When refering to the middle of the text

TextHorizontalMode.TextMid

 

when refering to the middle... GRRRRR

Stephan

0 Likes