Author Archives: DevClub

Porting an ObjectARX application to nanoCAD

In this post we describe how to migrate an existing ObjectARX application to nanoCAD.

This post is part of nanoCAD SDK Documentation that can be downloaded from the nanoCAD Developers’ Club.

To migrate an existing ObjectARX project to NRX:

  1. ObjectARX projects typically contain two project configurations: Debug and Release. Open the project in Visual Studio and create additional configurations that will be used for compiling the application  for nanoCAD. For example, Debug NCAD:

  2. In the General section of the project Configuration Properties set the property Character Set to the value Use Unicode Character Set and the property Use of MFC to the value Use MFC in a Shared DLL:

  3. Go the C/C++ > General section and specify nanoCAD SDK header files directories in the following order:
    [nanoCAD SDK path]\include
    [nanoCAD SDK path]\include\TD
    [nanoCAD SDK path]\include\MAPI
    [nanoCAD SDK path]\include\arxgate

    Note, the directories must be added in the right order to avoid compiling errors.

  4. In the C/C++ > Code Generation section choose the Multi-threaded DLL option for the Runtime Library property.

  5. In the Linker > General section add paths to the nanoCAD SDK libraries:
    [nanoCAD SDK path]\lib
    [nanoCAD SDK path]\lib\TD


Now it is possible to build the project, load the generated application DLL into nanoCAD with APPLOAD command and launch the application by running one of its commands.

For a complete sample project please look at the samples\NRX\CrossCircle SDK folder. This sample contains a custom entity, its managed wrapper, and commands written with both C++ and .NET.

The nanoCAD SDK is available in the nanoCAD Developers’ Club.

Creating a new project for NRX application

In this post we describe how to create a new project for NRX (nanoCAD runtime extension) applications.  NRX is a classical C++ API, compatible with ObjectARX, that allows the user to extend nanoCAD functionality.

This post is part of nanoCAD SDK Documentation that can be downloaded from the nanoCAD Developers’ Club.

To create a new NRX project:

  1. Create a new C++ project in Microsoft Visual Studio 2008 (Win32 Project):Start_NrxG_NewPrj_1
  2. Set the project name and its location:

  3. Choose DLL as an application type and add common header files for MFC:Start_NrxG_NewPrj_21
  4. In the General section of the project Configuration Properties set the property Character Set to the value Use Unicode Character Set and the property Use of MFC to the value Use MFC in a Shared DLL:

  5. Go to the C/C++ > General section and specify nanoCAD SDK header file directories in the following order:
    [nanoCAD SDK path]\include
    [nanoCAD SDK path]\include\TD
    [nanoCAD SDK path]\include\MAPI
    [nanoCAD SDK path]\include\nrxgate

    Start_NrxG_NewPrj_4Note, the directories must be added in the right order to avoid compiling errors.

  6. In the C/C++ > Codegeneration section choose the Multi-threaded DLL option for the Runtime Library property.

  7. In the Linker > General section add paths to the nanoCAD SDK libraries:
    [nanoCAD SDK path]\lib
    [nanoCAD SDK path]\lib\TD


  8. Add the following line to include the essential NRX header files:
  9. Add the following code to define an entry point:
  10. Implement the initApp() function that register all commands for the application:
  11. Implement the uninitApp() function that unloads application commands. In practice, a whole command group is unloaded, not only a separate command:

Tables in MultiCAD.NET. Part 3: Saving and loading table from an external file


The previous post about tables in MultiCAD.NET described how to create, modify and format tables with different data types and mentioned using table templates. In this post we will talk about templates and look more closely at the API that allows you to save a table to an external file as a template and then load it to the drawing to create type tables. Also the post will describe the table data exchange process between a MultiCAD.NET application and Microsoft Excel.

Example table

Let’s assume that the example table describes different types of mounting profiles (C-studs, U-channels etc.) and contains the following data: name, code, thickness, function.


Example table

We showed how to create and format tables in the previous post. Here, we’ll discuss how to save this table to an external file so that we can use it later as a template.

Saving table as a template

To save a table to a separate file, the McTable.SaveToFile() method is used. The table can be saved to a file of one of the following formats:

  • .dat files,
  • tabbed text (.txt),
  • comma-separated text,
  • XML,
  • Microsoft Excel (.xls),
  • (.ods).

The table to be saved can be picked from the drawing. The following command allows user to pick a table and save it to a file of the available formats:

Loading table from a file

To load a table from an external file, use the McTable.LoadFromFile() method. As well as for SaveToFile(), the file name can be specified explicitly or chosen from the dialog. The following file formats are supported for loading:

  • table .tbl, .dat files,
  • text (.txt, .csv, .xml),
  • Microsoft Access(.mdb, .accdb),
  • Microsoft Excel (.xls, .xlsx),
  • (.ods),
  • StarOffice (.sxc)

The following command adds a table from the user selected file to the drawing:

Now the saved table can be used as a template for adding type tables to the drawing:


Type tables based on the template table

Exchanging data with Excel

In addition to saving tables to files, MultiCAD.NET has the ability to quickly exchange data with Microsoft Excel sheets.

When the ExportToExcel() method is called, the table data is copied to a newly created and opened Excel book, keeping the cells format the same.
The following command lets the user select a table in the drawing and export it to an Excel sheet:

Also MultiCAD.NET supports importing table data from Excel. To import a selected cell range from the opened Excel sheet, use the ImportFromExcel() method:

This post concludes our review of the basic features of the tables API in MultiCAD.NET. This was definitely not the entire list of the abilities provided by the API, so if you have any questions or suggestions regarding this functionality please feel free to write comments. The tables feature list is currently being enhanced and we’ll be happy to get suggestions for more subjects to discuss in future posts.

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.

Tables in MultiCAD.NET. Part 1: Generating reports based on table templates


With this post, we’re beginning a series of articles about features and details of the MultiCAD.NET API for creating and modifying table entities.

For many drawings, tables are indispensable: they’re used to present descriptions, specifications, and instructions for creating construction elements represented in a drawing. It’s common to create tables based on properties extracted from drawing objects. Automating this process can save time and reduce errors.

As an example, let’s consider generating a report that contains a list of socket properties extracted from an electric map (a drawing that illustrates socket placement for a number of rooms.) Each socket is marked by a note that contains the following text data:

  • socket type,
  • code number/manufacturer,
  • room number.


The algorithm to create the table can be divided into three steps:

  • creating the custom report template,
  • loading the template and filling the table with data,
  • breaking the entire table into a number of pages and inserting the pages.

Creating the table template

Usually table reports are based on standard templates that are created with the tables UI. For demonstration purposes we are going to create a custom template using the MultiCAD.NET API, so that the whole table will look as follows:


Each cell value represents the number of sockets of a specific code in a specific room. Also, the table contains a page header that could be added for each page and a header for the first page with the table’s title.

Here is an example of the method that creates the template and saves it to a file with a specified name:

Users will be able to change the suggested table’s structure and cell formatting in the table editor.

This implementation of the table contains cells with special string identificators: #code and #room. These strings help to find the correct place for the data when the table is being filled. This ensures the table will be filled properly even if the numbers of rows or columns are changed.

Constructing a report

An algorithm for report building can be divided into the following steps:

  1. adding the command for creating the report
  2. selecting all the notes for multilayered constructions that contain description for sockets,
  3. loading the template and open the table editor to provide the ability to make changes in the template manually,
  4. structuring the data from the selected objects,
  5. filling in the table headers (the table’s title and column names),
  6. filling in the rows.

Here is the entire code for the example, with a discussion of key points:

Adding the command for creating the report

We will add the key method that is the handler for the smpl_CreateTableReport command and implements the algorithm:

Selecting objects

Selecting all notes for multilayered constructions can be performed using object filter:

As a result we will get an array of Ids for all notes in the drawing. Using these Ids we can obtain a text string of each note:

To simplify filling up the table, all text data should be arranged in an single structure that supports searching and sorting operations. Here the following structure of nested dictionaries is used: <product_code<room_number, count=”">>.

Loading the template

Let’s assume that the template is already created and saved to an external file (for example, C:\template.dat file) using the CreateTemplate() method. Now the saved table can be loaded using the McTable.LoadFromFile() method. Let’s create a table object, read the saved table into it and launch the table editor. It’s important to note that the table must be saved in a format that can keep the table’s structure and formatting, as well as its contents.


After that we can switch to filling up the table. The process includes sorting data received from the notes strings and adding them in appropriate cells. There is a quite wide list of possible implementations, one of which you can find in the example’s source code.

Page division

MultiCAD.NET contains an effective ability to divide a table into multiple fragments without losing its integrity. It’s used to split a large table in order to place it on a smaller sheet of paper, while still being able to edit it as a whole. To insert a page breaks by maximum page height the McTable.PagesTable.SetPageHeight() is used.

The following code fragment divides the table into separable pages so that the total height of the filled rows of each page should be less than 50 mm:


Another option is to insert a page break by a row index using the McTable.PagesTable.SetPageBreak() method. For example, to insert a page break after the row with index 7:

The result table will contain two pages:


After the table is divided, insertion points for each page need to be set. The points are set relative to the table’s insertion point using the McTable.PagesTable.SetOriginPage() method. The first parameter of the method is a page index, and the second parameter is the page insertion point. For example, to insert pages with the interval of 5:

Loading the example application to AutoCAD

Like any MultiCAD application, the example can simply run in nanoCAD after loading the example’s assembly and calling the registered smpl_CreateTableReport command. To run the MultiCAD application in AutoCAD, it’s required to use the special Object Enabler application. It’s important to note that the standard MultiCAD Enabler for AutoCAD (which is available in the nanoCAD Developers’ Club) doesn’t support objects from the Multicad.Symbols namespace. For running applications that deal with such objects, SPDS GraphiCS or MechaniCS (that contain full set of primitives including table and note entities) should be launched first.

Selecting and editing custom entities in MultiCAD.NET


In the previous post we discussed the process for creating custom entities in the MultiCAD.NET API, and described the CustomObjects example from the SDK. In this post we’re going to focus on the issue of selecting custom entities of the same type in the drawing.

The CustomObjects example creates custom entities that display as framed text strings:

TextInBox entities

TextInBox entities with initial text strings

We’ll extend the code for the CustomObjects example by adding functionality to searching for one or more of these entities and changing the text for each of them.

In MultiCAD.NET, when selecting a single object in the drawing, the object manager’s method SelectObject() is used. The method has the following signatures:

Both methods allow the user to select an object based on a prompt shown in the command line. The second method adds an additional parameter for the coordinates of the selection point.

For selecting multiple objects, the following methods are used:

The first method selects drawing objects using a specific filter, the second one shows a prompt in the command line and allows the user to pick objects by themself.

The filter is represented by an ObjectFilter object and defines the selection criteria: object type, documents, layers, sheets or area for searching objects. In the following example, the SelectCircles command gets a list of circle objects that are on the current sheet and intersect a specified rectangular area:

To find all circle entities from the entire drawing (not only on the current sheet), the drawing’s document should be set as a search area:

The second method allows the user to select entities manually instead of using filters, but we need to make sure the user has selected only entities of desired type.

Here we create a new command called TextInBoxEdit that allows user to select a set of any entities, then filters out only TextInBox entities from the set and changes text for all of them:

Let’s see how it works.

The command prompts the user to select entities on the drawing:


User-selected objects

After the command’s execution, the text strings have been changed in all selected TextInBox entities:


TextInBox entities with changed text strings

Creating custom entities in CAD with MultiCAD .NET API

One of the key disadvantages of classical .NET APIs in .dwg-compatible CAD programs is that it is impossible to create custom entities in .NET. Custom entities must be created in C++ with managed C++/CLI wrappers to be usable in .NET .

Our MultiCAD .NET technology provides the ability to create custom entities within the bounds of managed code. In addition to not requiring intermediate C++ objects, MultiCAD .NET uses standard .NET mechanisms, so there is no need to manually serialize objects, create COM objects, or perform other overhead chores that are typical with CAD programming.

The CustomObjects sample application, delivered with the SDK, provides a good example of how  MultiCAD .NET works. This application creates a custom entity, TextInBox, that draws a framed text string:

TextInBox sample entity

TextInBox sample entity

A drawing containing this custom entity can be opened by any .dwg-compatible CAD program. The entity can be modified by loading an assembly, containing the entity’s code. The same assembly can be correctly loaded to all supported CAD platforms without recompiling.

MultiCAD .NET technology runs natively in nanoCAD, and works in AutoCAD (and other compatible CAD programs) through an Object Enabler extension module, which can be downloaded in the nanoCAD Developers’ Club.

Defining a custom entity class

To create a new custom entity type, it’s necessary to define a new class, derived from McCustomBase (the base class for all custom entities.) Two attributes are required for the defined class:

  1. [CustomEntity] attribute with specified class type, its GUID, the name that will be used for all such entities in the drawing’s database and the local name,
  2. [Serializable] attribute allows for using the standard serialization mechanism from .NET Framework.

The following code defines the TextInBox custom entity class:

The methods from the base McCustomBase class for drawing entity geometry, adding into the database, selecting, and modifying the object are overridden by the TextInBox class.

Drawing geometry

The OnDraw() method is used for drawing the object. This method uses the GeometryBuilder class as a parameter.

Adding an entity into a drawing, with interactive coordinate input

The PlaceObject() method is used for adding custom entities into the drawing. Apart from its primary purpose, this method is also used for interactive coordinate input. In the MultiCAD API, interactive input is implemented in the InputJig class, which contains all essential functionality:

  • public InputResult GetPoint(string prompt) — gets a point on the drawing from user input. The prompt parameter is used to show a prompt.
  • public void ExcludeObject(McObjectId ObjectId) — excludes a specified object from snap. (This can be used to prevent an object from snapping itself.)
  • public EventHandler MouseMove — the mouse movement event handler, used for monitoring mouse motion and interactive object redrawing.

This code implements the PlaceObject method:

Editing and Modifying Object

To add object-modifying and text-editing features to the TextInBox class, the following methods from the base class are overridden:

  • public virtual List OnGetGripPoints() — get the list of object’s grip points (the marked points on the object that are used for transforming the object.)
  • public virtual void OnMoveGripPoints(List indexes, Vector3d offset, bool isStretch) — the grip points moving event handler.
  • public virtual void OnTransform(Matrix3d tfm) — defines object transformations.
  • public virtual hresult OnEdit(Point3d pnt, EditFlags lInsertType) — the object editing event handler.

This code sets the grip points to the box corner points input by the user:

When the custom entity is selected, the grip points are shown:


This event handler code allows the grip points to be moved by dragging:

The indexes parameter is a list of grip points indexes, and offset is a grip points displacement vector.

The OnTransform() method calculates the new positions of both corner points after transformations:

And finally, a text string editing method is required. Editing can be initiated by double-clicking on the entity, or by choosing the proper item from the context menu. Once the edit command is called, the form with text field appears to enable setting a new value for the text string:


TextInBox edit form

Adding Object Properties to the Property Inspector

The MultiCAD .NET API provides the ability to add the properties of a custom entity to a property inspector regardless of the platform used for opening the .dwg file, be it AutoCAD or nanoCAD. This can be done by adding the following attributes to the appropriate public property:

  • DisplayNameAttribute — defines the property name for displaying in the inspector;
  • DescriptionAttribute — property description;
  • CategoryAttribute — defines the name of the category for the property.

Use this feature to add the Text property to the properties palette:

This will display the contents of the entity’s text component in the property inspector:


Text property shown in the inspector

In this example, we have created a custom entity that can be added to the .dwg drawing and standard modifications for CAD users. This set of entities’ features can be extended as well. In later articles we’ll talk about creating entity versions by adding new fields and by renaming (removing) existing fields, and discuss the specifics of entity versioning in MultiCAD.NET API.


Welcome to nanoCAD API blog. The blog is dedicated to nanoCAD programming and customization and intended for sharing information about using different kinds of our APIs for CAD application development. Here you will be able to find up-to-date information about our products, technical details, how-to solutions and of course sample code.

If you have any suggestions or ideas for blog topics, please feel free to put them forward in comments or at