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.
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.
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'~
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
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.
Can't find what you're looking for? Ask the community or share your knowledge.