Table object

Table object

ProfWolfMan
Advocate Advocate
1,414 Views
5 Replies
Message 1 of 6

Table object

ProfWolfMan
Advocate
Advocate

Hi,

 

Good Day!

 

I am trying to create a table with 2rows & 2columns with a title.

 

I do some search here and google and i can not find perfect instruction about table.

Because now i can not use noofroes & noofcolumns methods.

and also i can not use mytable.cells(row,column).value="xxx".

those are absolute.

 

Anyone have piece of code to create a simple table using latest api?

It helps more for me.

 

 

 

 

 

Thanks & Regards,
G
0 Likes
1,415 Views
5 Replies
Replies (5)
Message 2 of 6

Hallex
Advisor
Advisor

Try this function

        public static void SetCell(Table oTable, int row, int column, string value,
           double height, CellAlignment cellalign)
        {
            //oTable.SetTextString(row, column, value);//<A2010
            oTable.Cells[row, column].TextString = value;//A2010

            // oTable.SetTextHeight(row, column, height);//<A2010
            oTable.Cells[row, column].TextHeight = height;//A2010

            //oTable.SetAlignment(row, column, cellalign);//<A2010
            oTable.Cells[row, column].Alignment = cellalign;//A2010

        }

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
0 Likes
Message 3 of 6

ProfWolfMan
Advocate
Advocate

Hi Hallex,

 

Thanks for your reply.

When i try to attempt table.cells() method following error occurs.

(image attached)

 

Method not found: 'Autodesk.AutoCAD.DatabaseServices.CellRange

Autodesk.AutoCAD.DatabaseServices.Table.get_Cells()'

 

I am using AutoCAD2008 & VS2005. Below is a snippet.

-------------------------------------------------------------------

'create table

Dim PJtbl As New Table

PJtbl.InsertRows(0, 10, 1)

PJtbl.InsertRowsAndInherit(1, 0, 5)

PJtbl.InsertColumns(0, 25, 1)

'assign value

PJtbl.Cells(0, 0).TextString = rowvalues(0)

-------------------------------------------------------------------

 

Thanks & Regards,
G
0 Likes
Message 4 of 6

Hallex
Advisor
Advisor

I haven't have this version on my machine sorry

Try other function from my old project

perhaps it will do your work

     public void FillCell(Table oTable, string value, int row, int column,
           ObjectId id, double height, CellAlignment cellalign, double topmargin, double bottommargin,
            double leftmargin, double rightmargin)
        {
            oTable.SetTextString(row, column, value);

            oTable.SetTextHeight(row, column, height);

            oTable.SetTextStyle(row, column, id);

            oTable.SetAlignment(row, column, cellalign);

            oTable.SetMargin(row, column, CellMargins.Bottom, bottommargin);

            oTable.SetMargin(row, column, CellMargins.Top, topmargin);

            oTable.SetMargin(row, column, CellMargins.Left, leftmargin);

            oTable.SetMargin(row, column, CellMargins.Right, rightmargin);
        }

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
0 Likes
Message 5 of 6

ProfWolfMan
Advocate
Advocate

Sorry!!!

 

I am out of luck.

API says table.setstring() is obsolute.

I am keep trying to solve it.

Thanks for your valuable time.

 

Meanwhile, anyone knows to create a simple table & assign values in AutoCAD2011?

Table API changed lot from its previous. 

Please share.

 

Thanks & Regards,
G
0 Likes
Message 6 of 6

Anonymous
Not applicable

From here http://www.theswamp.org/index.php?topic=37061.msg420539#msg420539

 

Took out tuples and blocks in link works for 2011 and 2012

 

            [CommandMethod("CreateTable")]
            public void CreateTable()
            {

                Document doc = Application.DocumentManager.MdiActiveDocument;
                Database db = doc.Database;
                Editor ed = doc.Editor;

                using (Transaction trx = db.TransactionManager.StartTransaction())
                {
                    BlockTable bt = db.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;

                    BlockTableRecord btrMs = (BlockTableRecord)bt[BlockTableRecord.ModelSpace].GetObject(OpenMode.ForRead);



                    Table tbl = new Table();
                    tbl.TableStyle = db.Tablestyle;
                    tbl.Position = Point3d.Origin;

                    TableStyle ts = (TableStyle)trx.GetObject(tbl.TableStyle, OpenMode.ForRead);
                    double txtheight = ts.TextHeight(RowType.DataRow);

                    tbl.Cells[0, 0].TextString = "Title";
                    tbl.InsertRows(1, 1, 1);
                    tbl.Rows[1].Style = "Data";
                    tbl.InsertRowsAndInherit(1, 1, 3);
                    tbl.InsertColumnsAndInherit(1, 0, 1);




                    for (int i = 1; i <= 3; i++)
                    {
                        tbl.Cells[i, 0].Contents.Add();
                        tbl.Cells[i, 0].Contents[0].TextString = "dfdrdrrerd";
                        tbl.Cells[i, 1].Value = "hgjhgjjg";
                    }

                    tbl.GenerateLayout();

                    btrMs.UpgradeOpen();
                    btrMs.AppendEntity(tbl);
                    trx.AddNewlyCreatedDBObject(tbl, true);

                    trx.Commit();
                }
            }

 

0 Likes