.NET

Reply
Active Contributor
laurie.comerford
Posts: 48
Registered: ‎09-08-2006
Message 1 of 11 (549 Views)
Accepted Solution

Setting the text styles in a table

549 Views, 10 Replies
10-30-2011 04:44 AM

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?

 

Regards

Laurie Comerford
Valued Mentor
jeff
Posts: 321
Registered: ‎05-12-2009
Message 2 of 11 (545 Views)

Re: Setting the text styles in a table

10-30-2011 05:22 AM in reply to: laurie.comerford

TableStyle.SetTextStyle()

 

Link

You can also find your answers @ TheSwamp
Valued Mentor
jeff
Posts: 321
Registered: ‎05-12-2009
Message 3 of 11 (542 Views)

Re: Setting the text styles in a table

10-30-2011 05:28 AM in reply to: jeff

Also can  try

 

Table.Cells[row,column].TextStyleId = id;

You can also find your answers @ TheSwamp
Active Contributor
laurie.comerford
Posts: 48
Registered: ‎09-08-2006
Message 4 of 11 (527 Views)

Re: Setting the text styles in a table

10-30-2011 01:51 PM in reply to: jeff

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?

 

Regards

Laurie Comerford
Valued Mentor
jeff
Posts: 321
Registered: ‎05-12-2009
Message 5 of 11 (503 Views)

Re: Setting the text styles in a table

10-31-2011 07:39 AM in reply to: laurie.comerford

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.

 

You can also find your answers @ TheSwamp
Valued Mentor
jeff
Posts: 321
Registered: ‎05-12-2009
Message 6 of 11 (497 Views)

Re: Setting the text styles in a table

10-31-2011 09:12 AM in reply to: jeff

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

 

 

 

You can also find your answers @ TheSwamp
Active Contributor
laurie.comerford
Posts: 48
Registered: ‎09-08-2006
Message 7 of 11 (484 Views)

Re: Setting the text styles in a table

10-31-2011 01:02 PM in reply to: jeff

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.

 

 

Regards

Laurie Comerford
Mentor
mgorecki
Posts: 399
Registered: ‎09-23-2004
Message 8 of 11 (406 Views)

Re: Setting the text styles in a table

03-07-2012 01:18 PM in reply to: jeff

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.ModelSpace), OpenMode.ForWrite)

            smdTableBtr.AppendEntity(smdTable)
            tableTrans.AddNewlyCreatedDBObject(smdTable, True)
            tableTrans.Commit()

        End Using

    End Sub

 I 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

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 9 of 11 (399 Views)

Re: Setting the text styles in a table

03-07-2012 01:52 PM in reply to: mgorecki

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.ModelSpace), OpenMode.ForWrite)

            smdTableBtr.AppendEntity(smdTable)             tableTrans.AddNewlyCreatedDBObject(smdTable, True)             tableTrans.Commit()

        End Using

    End Sub

{code}

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Mentor
mgorecki
Posts: 399
Registered: ‎09-23-2004
Message 10 of 11 (396 Views)

Re: Setting the text styles in a table

03-07-2012 02:11 PM in reply to: Hallex

Hi Hallex,

Thank you very much.  That did the trick and my eyes have stopped bleeding.

Have a great day.

Mark

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community