.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

format table style

1 REPLY 1
Reply
Message 1 of 2
Ahmmed-saber
314 Views, 1 Reply

format table style

the folwing code to create a table in AutoCAD  for points positions P#,E,N,Z

I need to format the table throw code because the result is the same picture attach

public void CreateTableFormula()
          {
               Document doc = Application.DocumentManager.MdiActiveDocument;
               Database db = doc.Database;
               Editor ed = doc.Editor;


               using (Transaction Tx = db.TransactionManager.StartTransaction())
               {
                    ObjectId ModelSpaceId =
                               SymbolUtilityServices.GetBlockModelSpaceId(db);
                    BlockTable bt = Tx.GetObject(db.BlockTableId,
                                                OpenMode.ForRead) as BlockTable;
                    BlockTableRecord btr = Tx.GetObject(ModelSpaceId,
                                          OpenMode.ForWrite) as BlockTableRecord;
                    TypedValue[] tv = new TypedValue[1];
                    List<Point3d> lspl = new List<Point3d>();
                    int number = 1;
                    tv.SetValue(new TypedValue((int)DxfCode.Start, "point"), 0);
                    SelectionFilter filter = new SelectionFilter(tv);
                    PromptSelectionResult ssPrompt;
                    ssPrompt = ed.GetSelection(filter);
                    if (ssPrompt.Status == PromptStatus.OK)
                    {
                         SelectionSet ss = ssPrompt.Value;

                         foreach (SelectedObject sObj in ss)
                         {
                              DBPoint spoint = Tx.GetObject(sObj.ObjectId, OpenMode.ForWrite) as DBPoint;
                              lspl.Add(spoint.Position);
                         }
                    }
                    PromptPointOptions ppo = new
                                PromptPointOptions("\nSpecify insertion point: ");

                    PromptPointResult ppr = ed.GetPoint(ppo);

                    if (ppr.Status != PromptStatus.OK)
                         return;
                    double rowHeight = 5, colWidth = 7;
                    Table table = new Table();
                    table.Position = ppr.Value;
                    table.Cells[0, 0].Value = "saber Title";
                    table.Cells[0, 0].Alignment = CellAlignment.MiddleCenter;
                    table.Cells[0, 0].GetMergeRange();
                    table.Cells[0, 0].TextHeight = 2;
                    
                    table.InsertColumns(0, colWidth, 3);
                    table.InsertRows(0, rowHeight, 1);
                    //table.Alignment = CellAlignment.MiddleCenter;
                    table.Cells.Alignment = CellAlignment.MiddleCenter;
                    table.Cells[1, 0].Value = "P#";
                    table.Cells[1, 1].Value = "E";
                    table.Cells[1, 2].Value = "N";
                    table.Cells[1, 3].Value = "Z";
                    //table.Cells[1, 4].Value = "D";
                    int InsertRow = 2;
                    foreach (Point3d pt3 in lspl)
                    {
                         DBText txt = new DBText();
                         txt.SetDatabaseDefaults();
                         txt.TextString = number.ToString();
                         txt.Position = pt3;
                         txt.Rotation = 0;
                         txt.Height = 1.8;
                         btr.AppendEntity(txt);
                         Tx.AddNewlyCreatedDBObject(txt, true);
                         table.InsertRows(InsertRow, rowHeight, 1);
                         table.Cells[InsertRow, 0].TextString = number.ToString();
                         table.Cells[InsertRow, 1].TextString = $@"{txt.Position.X: 0.0000}";
                         table.Cells[InsertRow, 2].TextString = $@"{txt.Position.Y: 0.0000}";
                         table.Cells[InsertRow, 3].TextString = $@"{txt.Position.Z: 0.0000}";                 
                         number++;
                         InsertRow++;
                    }

                    btr.AppendEntity(table);
                    Tx.AddNewlyCreatedDBObject(table, true);
                    Tx.Commit();
               }
          }
     

 

table.png

 

Labels (2)
1 REPLY 1
Message 2 of 2
_gile
in reply to: Ahmmed-saber

Hi,

What about changing these values:

double rowHeight = 5, colWidth = 7;

so that colWidth is much more greater than rowHeight (try about 8 times greater).



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report