.NET

.NET

Reply
Active Member
Stephan.Guympert
Posts: 7
Registered: ‎10-15-2013
Message 1 of 5 (270 Views)
Accepted Solution

Bottom Middle and Top Middle DBText Object not aligning correctly

270 Views, 4 Replies
02-04-2014 10:40 PM

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

 

Valued Mentor
gasty1001
Posts: 471
Registered: ‎04-11-2010
Message 2 of 5 (252 Views)

Re: Bottom Middle and Top Middle DBText Object not aligning correctly

02-05-2014 05:31 AM in reply to: Stephan.Guympert

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

Active Contributor
absStructural
Posts: 36
Registered: ‎07-15-2010
Message 3 of 5 (228 Views)

Re: Bottom Middle and Top Middle DBText Object not aligning correctly

02-06-2014 05:33 AM in reply to: gasty1001
I have noticed the same thing - and typically write something like:

if(DBText.IsDefaultAlignment)
DBText.Position = pt;
else
DBText.AlignmentPoint = pt;
Active Member
Stephan.Guympert
Posts: 7
Registered: ‎10-15-2013
Message 4 of 5 (212 Views)

Re: Bottom Middle and Top Middle DBText Object not aligning correctly

02-06-2014 05:52 PM in reply to: absStructural

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

 

Stephan

Active Member
Stephan.Guympert
Posts: 7
Registered: ‎10-15-2013
Message 5 of 5 (178 Views)

Re: Bottom Middle and Top Middle DBText Object not aligning correctly

02-10-2014 07:57 PM in reply to: Stephan.Guympert

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

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.