
In the
previous article, we wrote about how to import points from an external text file into a .dwg drawing using the classic .NET API. In this article, we will look at the features of solving the same problem on the cross-CAD system platform MultiCAD .NET API and demonstrate how a built application can be run in nanoCAD and AutoCAD without changing the project settings and recompiling.
Creating and setting up a working draft
The project is created in the same way as for the previous example:
')
- Project type: Visual C #
- Template: Class Library
All that needs to be done is just to connect the mapimgd.dll library included in the nanoCAD SDK package starting from version 4.0. The configuration of the project remains unchanged for developing applications running both on the nanoCAD platform and on other systems, in particular, AutoCAD. If the previous project had two configurations - Debug NCAD and Debug ACAD, then there will be one - Debug MultiCAD.
Importing coordinates and adding primitives to the drawing database
The structure of the application and the general code (application form, organization of a preview, import of coordinates from a file) remain the same, the classes
Importer
and
Creator
, the code of which depends on a specific platform, will be changed.
So, the
Creator.createPoints()
method, which is responsible for the direct creation of points for the input coordinate array, now looks like this:
public static void CreatePoints(List coords) { for(int i = 0; i<coords.Count-2; i += 3) {
Recall what the procedure for creating points looked like earlier when using the classic .NET API:
public static void CreatePoints(List coords) { DocumentCollection dm = Platform.ApplicationServices.Application.DocumentManager; Database db = dm.MdiActiveDocument.Database; using (db) {
Obviously, the amount of code required to implement this method has been significantly reduced: to create an object, set coordinates, and add to the database it took only three lines of code! And this is another distinctive feature of MultiCAD.NET: in addition to solving its main task - ensuring cross-platform applications - the MultiCAD.NET API allows you to make application code much more compact. This is achieved due to the fact that many auxiliary operations are already “embedded” in the main functionality.
Literally briefly dwell on the procedure for adding points to the drawing. Without going into details (this is the topic of a separate article), we note that the MultiCAD API implements three geometry levels for graphic objects: pure “mathematical” geometry, geometry with the addition of basic properties of primitives: color, thickness and style of lines, etc., and level database objects. In our case, we created a standard
DbPoint
geometry, set its geometrical parameters, and used the
DbEntity
property to go to the database level and add an object to the drawing. There is no need to determine the current drawing space: the
AddToCurrentDocument()
method
AddToCurrentDocument()
automatically determine which document is current and which workspace is currently being used.
Application loading in nanoCAD and AutoCAD
Now that the code has been compiled and the .NET assembly for the application is built, it's time to talk about the options for running the application under different systems.
- Applications for the nanoCAD environment are loaded using the standard NETLOAD or APPLOAD commands,
- To run applications on systems other than nanoCAD, the use of a special adapter application (Object Enabler) is required. For example, for AutoCAD, you must first download the MultiCAD Enabler for AutoCAD application (available after registering with the nanoCAD Developer Club ), and then the compiled application - with the NETLOAD command.
The source code of the project is available
here .
Discussion of the article is also available on our forum:
forum.nanocad.ru/index.php?showtopic=6509 .
Translation of the article into English:
Importing coordinates using the MultiCAD.NET API .