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

Trouble getting TextSize of a known textstyle

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
bowa
557 Views, 3 Replies

Trouble getting TextSize of a known textstyle

I'm trying to determine the textheight (textsize) of a textstyle that exists within my drawing. If anyone can point out my errors I'd greatly appreciate it.

 

Dim txsd As TextStyleTable = CType(trTbl1.GetObject(db.TextStyleTableId, OpenMode.ForRead), TextStyleTable)
Dim txtHt As Double = txsd.Item(strTextStyle).Database.Textsize
Dim txtStyle As String = txsd.Item(strTextStyle).Database.Textstyle.ToString

 

with the code above in my application, I always seem to be returning the same textstyleid and the height/size of the current text style (STANDARD) no matter what value I put in for strTextStyle. The styles I am querying exist in the drawing.

 

3 REPLIES 3
Message 2 of 4
SENL1362
in reply to: bowa

For a new ISO based drawing:

Default textSize==2.5

TextSize (standard)==0, but if you execute STYLE and change the height it will return that new value.

 

You're txtHt will always return the Database default, ie. Default textSize.

        [CommandMethod("TestTextStyle")]
        static public void TestTextStyle()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            string textStyleName = "Standard";
            try
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    ed.WriteMessage("\n Default Textsize=={0}", db.Textsize);
                    TextStyleTable textStyleTable = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForRead);
                    if (!textStyleTable.Has(textStyleName))
                        throw new System.Exception(string.Format("Error: TextStyle not found: {0}", textStyleName));

                    ObjectId textStyleId = textStyleTable[textStyleName];
                    TextStyleTableRecord textStyle = (TextStyleTableRecord)tr.GetObject(textStyleId, OpenMode.ForRead);
                    ed.WriteMessage("\n {0} Size=={1}", textStyleName, textStyle.TextSize);

                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage(ex.Message);
            }
        }

 

Message 3 of 4
bowa
in reply to: SENL1362

SENL,

Thank you. This is excellent. Does exactly what I need. For an explanation, I particularly appreciate that you've shown the difference between the database default as opposed to the height of the specified style.

 

Since I'm working in VB, I've posted your code converted for anyone else who might stumble upon this.

 

<CommandMethod("TestTextStyle")> _
    Public Shared Sub TestTextStyle()
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
        Dim ed As Editor = doc.Editor

        Dim textStyleName As String = "Standard"
        Try
            Using tr As Transaction = db.TransactionManager.StartTransaction()
                ed.WriteMessage(vbLf & " Default Textsize=={0}", db.Textsize)
                Dim textStyleTable As TextStyleTable = DirectCast(tr.GetObject(db.TextStyleTableId, OpenMode.ForRead), TextStyleTable)
                If Not textStyleTable.Has(textStyleName) Then
                    Throw New System.Exception(String.Format("Error: TextStyle not found: {0}", textStyleName))
                End If

                Dim textStyleId As ObjectId = textStyleTable(textStyleName)
                Dim textStyle As TextStyleTableRecord = DirectCast(tr.GetObject(textStyleId, OpenMode.ForRead), TextStyleTableRecord)
                ed.WriteMessage(vbLf & " {0} Size=={1}", textStyleName, textStyle.TextSize)

                tr.Commit()
            End Using
        Catch ex As System.Exception
            ed.WriteMessage(ex.Message)
        End Try
    End Sub

 

 

Much appreciated!

Message 4 of 4
SENL1362
in reply to: bowa

I'm glad i can return something to you or the forum.

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