.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Bottom Middle and Top Middle DBText Object not aligning correctly

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Stephan.Guympert
1090 Views, 4 Replies

Bottom Middle and Top Middle DBText Object not aligning correctly

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

 

4 REPLIES 4
Message 2 of 5

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

Message 3 of 5
absStructural
in reply to: hgasty1001

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

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

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

 

Stephan

Message 5 of 5

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost