var btr = new BlockTableRecord();
btr.Name = "我的块定义";
//添加一个表子实体到块定义中
Table table = new Table();
table.SetSize(2, 2);
table.SetRowHeight(100);
table.SetColumnWidth(100);
table.Cells[0, 0].TextString = "1";
table.Cells[0, 1].TextString = "2";
table.Cells[1, 0].TextString = "3";
table.Cells[1, 1].TextString = "4";
table.Position = new Point3d(0, 0, 0);
btr.AppendEntity(table);
bt.Add(btr);
tans.AddNewlyCreatedDBObject(table);
tans.AddNewlyCreatedDBObject(btr);
发现块虽然创建成功了,但是insert进图形空间后这个表不显示。经过调试后,发现需要调用Table的API:GenerateLayout()才能显示。
正确的代码为:
var btr = new BlockTableRecord();
btr.Name = "我的块定义";
//添加一个表子实体到块定义中
Table table = new Table();
table.SetSize(2, 2);
table.SetRowHeight(100);
table.SetColumnWidth(100);
table.Cells[0, 0].TextString = "1";
table.Cells[0, 1].TextString = "2";
table.Cells[1, 0].TextString = "3";
table.Cells[1, 1].TextString = "4";
table.Position = new Point3d(0, 0, 0);
//在表的设置完成后,调用GenerateLayout API
table.GenerateLayout();
btr.AppendEntity(table);
bt.Add(btr);
tans.AddNewlyCreatedDBObject(table);
tans.AddNewlyCreatedDBObject(btr);