Tables in MultiCAD.NET. Part 2: Creating and modifying


In the previous post we saw an example of using the MultiCAD.NET API for creating an automatic report with extracted properties from select drawing objects. We’ve purposely disturbed the chronological order. In today’s post we will create and modify a simple table. Then we’ll fill the table with text and numeric data, using expressions. Finally, we’ll switch over to adding blocks and subtables as cell content and conclude by attaching objects to the table to practice using their properties as the table’s dynamic contents.

Creating and formatting tables

In the MultiCAD.NET API, table entities are represented by the McTable class from the Multicad.Symbols.Tables namespace. The following code creates an empty table and  adds two rows and three columns starting at 0 index:

With the same method, you can add row and column ranges at specific positions.

Let’s add the content for the newly created table and define cell formating. The table will contain a property list of construction elements: index, name, part number, material and count. For the count column we will use a numeric cell format and the other cells will contain text data.


One of the advantages of the MultiCAD.NET table API is an ability to use different fit modes for oversized text. With the HorzFits property you can choose the following horizontal fitting options if text width exceeds cell bounds:

  • HorizontalFitsEnum.None — leave as is,
  • HorizontalFitsEnum.Shrink — adjust width factor (default mode),
  • HorizontalFitsEnum.Wrap — word wrap.

The VertFits property defines the text fitting if text height exceeds cell bounds:

  • VerticalFitsEnum.None — leave as is,
  • VerticalFitsEnum.Shrink — shrink text height (default mode),
  • VerticalFitsEnum.Expand — expand row height,
  • VerticalFitsEnum.AddRows — occupy extra rows.

After the table is created, you can modify its structure: add, delete, move or copy rows and columns. For example, let’s add one extra record for a “Bolt” component, then move the “Count” column to the last position and delete the “Index” column:

Then add a row for a total number of components. For counting, the embedded “Summ” expression can be used:


For summing up the numeric data from the cell region to the result cell, the string representation of the expression has been used. In the table editor the cell will appear as follows:


The editor can be launched programmatically using the OnEdit() method from the McTable object.

Note, that we set the numeric format for the “Count” column’s cells instead of the default Auto format, which  identifies data type automatically.

Adding tables to the drawing

The table can be added to the drawing just as other entities, using one of the following methods:

  • Table.DbEntity.AddToCurrentDocument(); — adds the table entity to the drawing. The upper left corner of the table is placed at the drawing origin.
  • Table.PlaceObject(); — inserts the table interactively, the insertion point is specified by user. Calling the method without arguments or with McEntity.PlaceFlags.Normal as a parameter value launches the table editor before inserting.

The following allows the table to be added into the drawing in the interactive mode without using the table editor:

Using blocks and subtables in cells contents

In addition to text and numeric data you can insert blocks and other tables into a table’s cells. Let’s look at how this works with a sample table that describes a metal structural profile. The first column contains the shape type, the second column: its specification, and the third column: its graphical representation:


The specification for the profile is represented by the following table:


Images of different shape types are represented by separate blocks stored in an external .dwg file:


Let’s discuss how we can add a profile’s specification and image to the main table.

Inserting subtables

To insert subtables, the following method is used:

McTable.InsertSubtable(ref McTable inTable, int row, int col, InsertionModeEnum mode);

  • inTable — the table to insert,
  • row, col — row and column indexes of the cell to which the subtable will be inserted,
  • mode — the insertion mode.

The subtable can be inserted in the following modes:

  • InSingleCell — the table will be inserted into the specified cell. The structure of the resulting table will be adjusted in order to fit the inserted table.
  • CellByCell — the table will be inserted cell-by-cell starting from the upper left cell. The resulting table will contain only overlapping cells from both tables.
  • Over — the table will be inserted over the main table. Neither of the  tables’ structure will be changed.

The following code inserts the specification table to a separate cell of the main table:


Using blocks as cell content

For inserting blocks into table cells, the EmbedBlock() method of a Cell object is used. This method enables embedding of a block in a separate cell using block ID, block name, or block name and name of an external file that contains the block:

bool EmbedBlock(int row, int col, McObjectId Id);
bool EmbedBlock(int row, int col, ref String name);
bool EmbedBlock(int row, int col, ref String name, ref String fileName);

The following code inserts the block of the shape’s image from the external file:


Extracting properties from entities to a table

Another useful feature of the MultiCAD.NET API is attaching entities to the table. Since the object is attached, you are able to extract its properties to a cell using special expressions. The following example demonstrates how to attach a closed polyline to the table and use its area property as a value of the cell (0,0):

Attaching objects allows you to track changes dynamically. Changing properties of the attached object changes the contents of corresponding table cells.

One thought on “Tables in MultiCAD.NET. Part 2: Creating and modifying

  1. Pingback: Tables in MultiCAD.NET. Part 3: Saving and loading table from an external file | nanoCAD API Blog

Leave a Reply