.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Setting the text styles in a table
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
I've found nearly everything I need to draw my tables, but cannot find how to set the text styles for the Title, Header and Data cells.
There must be a way, but it is hidden under an obscure method or property title which I can't identify or find on the internet or in the Object Browser.
Can some one point me in the right direction?
Laurie Comerford
Solved! Go to Solution.
Re: Setting the text styles in a table
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Re: Setting the text styles in a table
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Re: Setting the text styles in a table
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi Jeff,
Thanks for that, but I'm still unable to get going.
The SetTextStyle method requires I pass it an ObjectID, but gives no indication as to which Object the ObjectID applies.
Do you know of some sample code I could look at?
Laurie Comerford
Re: Setting the text styles in a table
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
ID of the the textstyle
This function sets the table object to use the TextStyleTableRecord specified by ID for the specified row types. Different row types can be OR'ed.
Re: Setting the text styles in a table
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Here is a example if you have the 3 textstyles in code named
<CommandMethod("SetTextStyleInTable")> _
Public Sub SetTextStyleInTable()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Using trx As Transaction = db.TransactionManager.StartTransaction()
Dim txtTbl As TextStyleTable = trx.GetObject(db.TextStyleTableId, OpenMode.ForRead)
Dim tbl As New Table()
tbl.TableStyle = db.Tablestyle
Dim tblStyle As TableStyle = trx.GetObject(tbl.TableStyle, OpenMode.ForWrite)
tblStyle.SetTextStyle(txtTbl("TitleText"), RowType.TitleRow)
tblStyle.SetTextStyle(txtTbl("HeaderText"), RowType.HeaderRow)
tblStyle.SetTextStyle(txtTbl("DataText"), RowType.DataRow)
tbl.Position = Point3d.Origin
tbl.Cells(0, 0).TextString = "TITLE"
tbl.InsertColumns(0, 5, 1)
tbl.InsertRows(1, 2, 1)
tbl.Rows(1).Style = "Header"
tbl.Cells(1, 0).TextString = "Header"
tbl.InsertRows(2, 1, 1)
tbl.Rows(2).Style = "Data"
tbl.Cells(2, 0).TextString = "Data"
tbl.InsertRowsAndInherit(3, 2, 10)
Dim bt As BlockTable = trx.GetObject(db.BlockTableId, OpenMode.ForRead)
Dim modelBtr As BlockTableRecord = trx.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
modelBtr.AppendEntity(tbl)
trx.AddNewlyCreatedDBObject(tbl, True)
trx.Commit()
End Using
End Sub
Re: Setting the text styles in a table
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi Jeff,
Thanks as always. I'm up and running now.
For any one else using this code, they need to be aware that the TextStyles "TitleText", "HeaderText" and "DataText" need to be available in a complete solution.
Laurie Comerford
Re: Setting the text styles in a table
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi Jeff. I have looked all over for information regarding creating tables in AutoCad 2010, but have not found much. The stuff I found is all obsolete. So when I found your post I had to use some of it, but I have some questions. Here is your code, changed a bit for my circumstance:
Public Sub AddTable(ByVal dwg_scale As Double, ByVal dwgTextHeight As Double)
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Using tableTrans As Transaction = db.TransactionManager.StartTransaction()
Dim txtTbl As TextStyleTable = tableTrans.GetObject(db.TextStyleTableId, OpenMode.ForRead)
Dim smdTable As New Table()
smdTable.TableStyle = db.Tablestyle
Dim tblStyle As TableStyle = tableTrans.GetObject(smdTable.TableStyle, OpenMode.ForWrite)
Dim cellHgt As Double, smdCol0Width As Double, smdCol1Width As Double
Dim smdCol2Width As Double, smdCol3Width As Double, smdCol4Width As Double, tableLocX As Double, tableLoc As Point3d
cellHgt = dwgTextHeight * 2
smdCol0Width = 9.0 * dwg_scale
smdCol1Width = 13.5 * dwg_scale
smdCol2Width = 13.5 * dwg_scale
smdCol3Width = 16.2 * dwg_scale
smdCol4Width = 21.3 * dwg_scale
tableLocX = (((smdCol0Width + smdCol1Width + smdCol2Width + smdCol3Width + smdCol4Width) / 2.0) * -1)
tableLoc = New Point3d(tableLocX, 0, 0)
tblStyle.SetTextStyle(txtTbl("Romans"), RowType.TitleRow)
tblStyle.SetTextStyle(txtTbl("Romans"), RowType.HeaderRow)
tblStyle.SetTextStyle(txtTbl("Romans"), RowType.DataRow)
smdTable.Position = tableLoc
smdTable.Cells(0, 0).TextString = "DISCRETE COMPONENTS"
smdTable.InsertRows(1, cellHgt, 2)
smdTable.InsertColumns(0, smdCol0Width, 1)
smdTable.InsertColumns(1, smdCol1Width, 1)
smdTable.InsertColumns(2, smdCol2Width, 1)
smdTable.InsertColumns(3, smdCol3Width, 1)
smdTable.InsertColumns(4, smdCol4Width, 1)
smdTable.DeleteColumns(5, 1)
smdTable.Rows(1).Style = "Header"
smdTable.Rows(2).Style = "Data"
smdTable.Cells.Alignment = CellAlignment.MiddleCenter
smdTable.Cells.TextHeight = dwgTextHeight
smdTable.Cells(1, 0).TextString = "ITEM NO."
smdTable.Cells(1, 1).TextString = "X"
smdTable.Cells(1, 2).TextString = "Y"
smdTable.Cells(1, 3).TextString = "Z (HEIGHT)"
smdTable.Cells(1, 4).TextString = "COMPONENT TYPE"
Dim bt As BlockTable = tableTrans.GetObject(db.BlockTableId, OpenMode.ForRead)
Dim smdTableBtr As BlockTableRecord = tableTrans.GetObject(bt(BlockTableRecord.ModelSpac e), OpenMode.ForWrite)
smdTableBtr.AppendEntity(smdTable)
tableTrans.AddNewlyCreatedDBObject(smdTable, True)
tableTrans.Commit()
End Using
End SubI just want to create a table that has the title = "DISCRETE COMPONENTS". The headers to be "ITEM NO.", "X", "Y", ... and then a blank row below the header row.
I also want the all the cells to have the same text height (dwgTextHeight) and be middle center justified. I believe I have it all in that code, but for some reason the title is the only text that is coming in with the correct text height. I have the text style ROMANS set to the value in "dwgTextHeight". The text height for the header and data rows is coming in at the default 0.18.
The header row is middle center justified which is good, but the data row is not justified.
Can you help me out with this? I've been trying all sorts of combinations of stuff and now my eyes are bleeding.
Thanks,
Mark
Re: Setting the text styles in a table
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Your code is working good enough not ideal though sorry
Here is just quickly edited attempt of mine
Here is nap time for me so I can't to rewrite it completely
Try this out:
{code}
Public Sub AddTable(ByVal dwg_scale As Double, ByVal dwgTextHeight As Double) Dim doc As Document = Application.DocumentManager.MdiActiveDocument Dim db As Database = doc.Database Dim ed As Editor = doc.Editor
Using tableTrans As Transaction = db.TransactionManager.StartTransaction() Dim txtTbl As TextStyleTable = tableTrans.GetObject(db.TextStyleTableId, OpenMode.ForRead) Dim smdTable As New Table() smdTable.TableStyle = db.Tablestyle Dim tblStyle As TableStyle = tableTrans.GetObject(smdTable.TableStyle, OpenMode.ForWrite) Dim cellHgt As Double, smdCol0Width As Double, smdCol1Width As Double Dim smdCol2Width As Double, smdCol3Width As Double, smdCol4Width As Double, tableLocX As Double, tableLoc As Point3d
cellHgt = dwgTextHeight * 2 smdCol0Width = 9.0 * dwg_scale smdCol1Width = 13.5 * dwg_scale smdCol2Width = 13.5 * dwg_scale smdCol3Width = 16.2 * dwg_scale smdCol4Width = 21.3 * dwg_scale tableLocX = (((smdCol0Width + smdCol1Width + smdCol2Width + smdCol3Width + smdCol4Width) / 2.0) * -1) tableLoc = New Point3d(tableLocX, 0, 0)
tblStyle.SetTextStyle(txtTbl("Romans"), RowType.TitleRow) tblStyle.SetTextStyle(txtTbl("Romans"), RowType.HeaderRow) tblStyle.SetTextStyle(txtTbl("Romans"), RowType.DataRow) smdTable.Rows(0).Style = "Title" smdTable.Position = tableLoc smdTable.Cells(0, 0).TextString = "DISCRETE COMPONENTS" smdTable.InsertRows(1, cellHgt, 2) smdTable.InsertColumns(0, smdCol0Width, 1) smdTable.InsertColumns(1, smdCol1Width, 1) smdTable.InsertColumns(2, smdCol2Width, 1) smdTable.InsertColumns(3, smdCol3Width, 1) smdTable.InsertColumns(4, smdCol4Width, 1) smdTable.DeleteColumns(5, 1) smdTable.Rows(1).Style = "Header" smdTable.Rows(1).TextHeight = dwgTextHeight smdTable.Rows(2).Style = "Data" smdTable.Rows(2).TextHeight = dwgTextHeight smdTable.Rows(1).Alignment = CellAlignment.MiddleCenter smdTable.Rows(2).Alignment = CellAlignment.MiddleCenter smdTable.Cells.Alignment = CellAlignment.MiddleCenter smdTable.Cells.TextHeight = dwgTextHeight smdTable.Cells(1, 0).TextString = "ITEM NO." smdTable.Cells(1, 1).TextString = "X" smdTable.Cells(1, 2).TextString = "Y" smdTable.Cells(1, 3).TextString = "Z (HEIGHT)" smdTable.Cells(1, 4).TextString = "COMPONENT TYPE" smdTable.Cells(2, 0).TextString = 1 smdTable.Cells(2, 1).TextString = 1.2345 smdTable.Cells(2, 2).TextString = 2.3456 smdTable.Cells(2, 3).TextString = 0.0 smdTable.Cells(2, 4).TextString = "SOME TYPE" Dim bt As BlockTable = tableTrans.GetObject(db.BlockTableId, OpenMode.ForRead) Dim smdTableBtr As BlockTableRecord = tableTrans.GetObject(bt(BlockTableRecord.ModelSpac
smdTableBtr.AppendEntity(smdTable) tableTrans.AddNewlyCreatedDBObject(smdTable, True) tableTrans.Commit()
End Using
End Sub
{code}
~'J'~
C6309D9E0751D165D0934D0621DFF27919
Re: Setting the text styles in a table
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi Hallex,
Thank you very much. That did the trick and my eyes have stopped bleeding.
Have a great day.
Mark


