Results 1 to 4 of 4

Thread: .NET TextStyles collection

  1. #1
    100 Club amaser's Avatar
    Join Date
    2006-05
    Location
    Joliet, IL
    Posts
    105
    Login to Give a bone
    0

    Default .NET TextStyles collection

    how do i cycle through all the text styles in a drawing?

    i'm using VB.NET 2008, and have the following code:

    Code:
    PublicSub FixTxtHt()
    'define variables
    Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
    Dim acDocDb As Database = acDoc.Database
    
    Using acTrans As Transaction = acDocDb.TransactionManager.StartTransaction()
    Dim acTxtTbl As TextStyleTable
    acTxtTbl = 'NOT SURE WHAT GOES HERE
    Dim acTxtTblRec As TextStyleTableRecord
    ForEach acTxtTblRec In acTxtTbl
    If acTxtTblRec.Name = "L70"Then
    acTxtTblRec.TextSize = 0.07
    EndIf
    If acTxtTblRec.Name = "L80"Then
    acTxtTblRec.TextSize = 0.08
    EndIf
    If acTxtTblRec.Name = "L90"Then
    acTxtTblRec.TextSize = 0.09
    EndIf
    If acTxtTblRec.Name = "L100"Then
    acTxtTblRec.TextSize = 0.1
    EndIf
    If acTxtTblRec.Name = "L120"Then
    acTxtTblRec.TextSize = 0.12
    EndIf
    If acTxtTblRec.Name = "L140"Then
    acTxtTblRec.TextSize = 0.14
    EndIf
    If acTxtTblRec.Name = "L200"Then
    acTxtTblRec.TextSize = 0.2
    EndIf
    If acTxtTblRec.Name = "L240"Then
    acTxtTblRec.TextSize = 0.24
    EndIf
    Next
    acTrans.Commit()
    EndUsing
    EndSub
    I'm not sure how to reference the TextStyles collection object to use int he for each statement. I've got a comment on the line where i'm not sure what to enter
    Last edited by Ed Jobe; 2010-05-17 at 02:54 PM. Reason: Added code tags.

  2. #2
    Active Member
    Join Date
    2006-08
    Location
    Brisbane : GMT+10
    Posts
    87
    Login to Give a bone
    0

    Default Re: .NET TextStyles collection

    You need to reference the acCurDb.TextStyleTableId

    Perhaps something like this ...

    Code:
           /// <summary>
            /// 
            /// </summary>  
            [CommandMethod("FTH")]
            public static void FixTextHeight()
            {
                // Get the current document and database, and start a transaction 
                Document doc = AcadApp.DocumentManager.MdiActiveDocument;
                Database db = doc.Database;
                using(Transaction tr = db.TransactionManager.StartTransaction())
                {
                    // Return the TextStyle table for the current database                  
                    TextStyleTable tsTbl = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
    
                    // Step through the TextStyle table
                    foreach(ObjectId objId in tsTbl)
                    {
                        TextStyleTableRecord tsTblRec = tr.GetObject(objId, OpenMode.ForWrite) as TextStyleTableRecord;
                        string textStyleName = tsTblRec.Name;
                        // If the StyleNAme matches, change the TextSize.
                        switch(textStyleName)
                        {
                            case "L70" :
                                tsTblRec.TextSize = Convert.ToDouble(AcadApp.GetSystemVariable("DIMSCALE")) * 0.07;
                                break;
                            case "L80":
                                tsTblRec.TextSize = Convert.ToDouble(AcadApp.GetSystemVariable("DIMSCALE")) * 0.08;
                                break;
                            default:
                                break;
                        }                    
                    }
                    tr.Commit();
                    // Dispose of the transaction via the 'using' statement 
                }
            }
    Last edited by Kerry Brown; 2010-05-17 at 07:51 AM.

  3. #3
    Active Member
    Join Date
    2006-08
    Location
    Brisbane : GMT+10
    Posts
    87
    Login to Give a bone
    0

    Default Re: .NET TextStyles collection

    on a revisit :

    The TextStyleTable does not need to be opened ForWrite .. ForRead will work

    Code amended accordingly ...

  4. #4
    100 Club amaser's Avatar
    Join Date
    2006-05
    Location
    Joliet, IL
    Posts
    105
    Login to Give a bone
    0

    Default Re: .NET TextStyles collection

    that did the trick. i have no idea why it didn't work in vb.net, but your example worked.
    thanx
    '

    Quote Originally Posted by Kerry Brown View Post
    You need to reference the acCurDb.TextStyleTableId

    Perhaps something like this ...

    Code:
           /// <summary>
            /// 
            /// </summary>  
            [CommandMethod("FTH")]
            public static void FixTextHeight()
            {
                // Get the current document and database, and start a transaction 
                Document doc = AcadApp.DocumentManager.MdiActiveDocument;
                Database db = doc.Database;
                using(Transaction tr = db.TransactionManager.StartTransaction())
                {
                    // Return the TextStyle table for the current database                  
                    TextStyleTable tsTbl = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
     
                    // Step through the TextStyle table
                    foreach(ObjectId objId in tsTbl)
                    {
                        TextStyleTableRecord tsTblRec = tr.GetObject(objId, OpenMode.ForWrite) as TextStyleTableRecord;
                        string textStyleName = tsTblRec.Name;
                        // If the StyleNAme matches, change the TextSize.
                        switch(textStyleName)
                        {
                            case "L70" :
                                tsTblRec.TextSize = Convert.ToDouble(AcadApp.GetSystemVariable("DIMSCALE")) * 0.07;
                                break;
                            case "L80":
                                tsTblRec.TextSize = Convert.ToDouble(AcadApp.GetSystemVariable("DIMSCALE")) * 0.08;
                                break;
                            default:
                                break;
                        }                    
                    }
                    tr.Commit();
                    // Dispose of the transaction via the 'using' statement 
                }
            }

Similar Threads

  1. vb.net textstyles
    By breton_jean789423 in forum Dot Net API
    Replies: 4
    Last Post: 2012-02-23, 05:41 AM
  2. layers, linetypes, dimstyles, textstyles
    By jledgewood in forum AutoCAD General
    Replies: 19
    Last Post: 2010-05-27, 05:12 AM
  3. Purge textstyles in blocks
    By david.hellberg in forum ACA General
    Replies: 4
    Last Post: 2009-01-09, 11:49 PM
  4. Merge textstyles and linetypes
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 0
    Last Post: 2006-09-11, 03:03 PM
  5. Replies: 2
    Last Post: 2006-08-31, 06:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •