Table Text Style

Anonymous

Table Text Style

Anonymous
Not applicable

How do you set the text style for cells in a table?  I used to be able to set the title row, head row and data row text style in vba. In vb.net I tried using <tablestyle>.SetTextStyle but it is asking me for an ID.

0 Likes
Reply
2,253 Views
6 Replies
Replies (6)

Anonymous
Not applicable

Have you taken the time to become familiar with the managed API using

the materials available through Autodesk's web site?

 

In the managed world, objects in drawings are repesented by ObjectIds,

rather than by their user-friendly names. Hence, you have to find the

ObjectId of the table style you want to apply, by looking it up in the table

style dictionary.

 

Sorry, if I sound like I think you're asking for a loaded question, but

understading the basics of the managed API, such as what ObjectIds

are and how they're used, is a prerequisite.

 

0 Likes

Hallex
Advisor
Advisor

Try this code snippet

 

              TextStyleTable tt = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForRead, false);

                        if (!(tt.Has(txstylename))) return;

                        ObjectId txtid = tt[txstylename];

                        

 then apply this txtid to your code

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
0 Likes

Anonymous
Not applicable

This is a piece of code I have in my program. I just wasn't sure if this is what it was asking for.

 

'Check if text style exists
Dim acTextStyleTable As TextStyleTable = acLayerTextTrans.GetObject(MyDrawingDb.TextStyleTableId, _
                                                                                                    OpenMode.ForRead)


For Each acTextStyleObjId As ObjectId In acTextStyleTable
      Dim acTextStyleTableRec As TextStyleTableRecord
      acTextStyleTableRec = acLayerTextTrans.GetObject(acTextStyleObjId, OpenMode.ForRead)

       If acTextStyleTableRec.Name = strTableTextStyle Then
            TableTextStyleFound = True
       End If

next

Anonymous
Not applicable

You don't have to search the text style table manually, because the Has()

method tells you if an entry exists, and the indexer or Item() method will get

it if it does, so most of that code is pointless and wasteful.

 

The other thing is a basic programming mistake, which is that you

continue looking at items in the table even after you've found the

one you're after. Are you familiar with the Exit For statement?

 

See hallex's reply - that's all you need.

0 Likes

Anonymous
Not applicable

Thanks for you help. It is greatly appreciated.

0 Likes

brianchapmandesign
Collaborator
Collaborator

Life saver once again!


"Very funny, Scotty. Now beam down my clothes.
0 Likes