Is it possible to insert DXFBlock/DxfModel/Entities in DXFTableCell object?

1
Sachin Tripathi
1/9/2020 10:54 AM

Hi,

I'm able to insert string/date/number values in dxfTable cell content and it is working fine. But I need to insert DXFBlock/DxfModel/Entities in DXFTableCell content. I've been searching but I haven't found anything about it. Can you tell me how can I do it?

Thank you!

Sachin

Wout
1/9/2020 3:50 PM

Hi,

Yes it's possible to add a block to a table cell:

C# Code:
        public void TestTableWithBlocks() {
            DxfModel model = new DxfModel(DxfVersion.Dxf21);

            DxfTableStyle tableStyle = new DxfTableStyle("Double bordered");
            tableStyle.DataCellStyle.SetAllBordersBorderType(BorderType.Double);
            tableStyle.DataCellStyle.SetAllBordersColor(Colors.Green);
            tableStyle.TitleCellStyle.SetAllBordersBorderType(BorderType.Double);
            tableStyle.HeaderCellStyle.SetAllBordersBorderType(BorderType.Double);
            model.TableStyles.Add(tableStyle);

            DxfBlock block = new DxfBlock("TESTBLOCK");
            model.Blocks.Add(block);
            block.Entities.Add(
                new DxfLwPolyline(
                    new Point2D(2d, 1d),
                    new Point2D(2d, 3d),
                    new Point2D(5d, 3d),
                    new Point2D(6d, 2d),
                    new Point2D(5d, 1d)
                )
            );
            block.Entities.Add(new DxfCircle(new Point3D(5d, 3d, 0d), 2d));

            {
                DxfTable table = new DxfTable(model.DefaultTableStyle);
                table.InsertionPoint = new Point3D(0d, 10d, 0d);
                table.TableStyle = tableStyle;

                table.RowCount = 4;
                table.ColumnCount = 1;

                foreach (DxfTableColumn column in table.Columns) {
                    column.Width = 8d;
                }

                table.Rows[0].Cells[0].Contents.Add(new DxfValueFormat.String(), "Text");

                table.Rows[1].Cells[0].Contents.Add(new DxfTableCellContent(block));

                table.Rows[2].Cells[0].Contents.Add(new DxfTableCellContent(block));
                table.Rows[2].Cells[0].Contents[0].Format.AutoScale = true;
                table.Rows[2].Cells[0].CellStyleOverrides.CellAlignment = CellAlignment.MiddleCenter;

                table.Rows[3].Cells[0].Contents.Add(new DxfTableCellContent(block));
                table.Rows[3].Cells[0].Contents[0].Format.BlockScale = 0.5d;
                table.Rows[3].Cells[0].CellStyleOverrides.CellAlignment = CellAlignment.BottomRight;

                model.Entities.Add(table);
            }

            DxfWriter.Write("TableWriteTest.TestTableWithBlocks.dxf", model);
            DwgWriter.Write("TableWriteTest.TestTableWithBlocks.dwg", model);
        }

- Wout

Sachin Tripathi
1/14/2020 1:43 PM

Thank you for sharing sample code. Yes, now I can add dxfblock in table entity. Thanks a lot :)

Regards,
Sachin

1