By the will of fate, it turned out that for one of my hobbies, I needed to
poke around in the API for the domestic CAD
system Nanocad , while not having any practical skills in developing for CAD.
And if a couple of years ago in a similar situation, when I decided to look at the API for Revit purely for the sake of curiosity, there were no problems at all, then everything was not so simple with Nanocad.
In memory, and with all due respect to Mikhail Nikolayevich, one can say: “Breathe air into the chest ...” these Americans posted on their website in the public domain ...
instructions for getting started ! What are they all there ... well, in general, you understand, this is not “store in onions in pantyhose”.
')
But we, as decent people, will not scold people who gave us a completely sane product for free and access to development tools, just try to help them a little, especially since the latest publication on MultiCad. NET API was
in the Nanosoft blog on Habré, almost two years ago and it is necessary to fill a little vacuum.
Unfortunately, as a complete newcomer to this issue, I will not be able to give you the material of really decent quality, but at least we will consider those issues on which I immediately had a “plug”. It turns out, as in the last
cycle on Data Science article from a beginner - beginners.
The plan is something like this: a few words about Nanocad, a bit of general programming about Nanocad, and at the end writing a primitive command using MultiCAD .NET API 7 (for Nanocad 8.X).
So, we hide the drawings in the tube, remove the drawpieces, push the patterns on the mezzanine, and you are welcome under the cat.

Dear reader, if you see these lines, know that you are in GREAT danger! Those who have read
my past articles know that lately I have been supplementing headlines with something stylized for greater artistic expression, now I play on films, now proverbs.
I don’t know why, but when I started writing this article, I realized that I simply had to fill it with references to excerpts from the monologues of the Golden Age of the “Anshlag” and “Smehopanorama” programs. So, this article is only for people with strong spirit.
Content:
Part I: “I do not get paid for it! (Introduction).Part II: Import SubstitutionPart III: Access to the API, documentation, where to start.Part IV: Set up the development environment and write a simple command.Part V: It's a shame! (Conclusion)1. I do not pay for it! (Introduction)

To begin with, it would be appropriate to say that I am in no way connected with Nanosoft, they don’t pay me any money, so all that will be in the article is my personal opinion.
By the way, this opinion will be quite positive. My full acquaintance with Nanocad began many years ago, when my colleague
Drzugrik was still young trainees and fate brought us to a good company, for which the use of pirated software was unacceptable. Naturally, for two “students” there was no AutoCAD license, and it was then that Nanocad us out.
True, it should be noted that all the free versions of the 3.X family cost me a lot of pulled out hair and foul language, but then version 5.1 (
Nanocad Free ) came out, which is quite a convenient “electronic drawing board”. I still use it when I need to jot down some simple "scheme", for example, this one:

As you can see, the interface is similar to the old-fashioned AutoCAD “dolentochny”, and the functionality is similar to AutoCAD LT of the “end of zero”. True, in contrast to the LT version of Avtokad, in the free Nanocade there is some possibility to work with 3D, there is not much benefit from it unless students do tasks on descriptive geometry (I drew myself views and isometry, I looked, and then I copied).
And in terms of two-dimensional design for the construction industry, the functionality of the free version may well be enough for freelancers or small design offices and construction and assembly organizations.
There is certainly a paid version, at the moment Nanocad 8.5, I honestly do not like all the charms of automation, which it gives. But if you believe the book “Path to Nanocad” (about it later), then it seems to be really convenient to work, but I myself didn’t come across in practice, I can only imagine how much time automating some fields in the drawing and automated control with NormaCS could save.
Unlike the free version in the paid version, 3D seems to be better, but 2D parametrization and 3D modeling will have to be paid separately (in addition to the license for Nanocad Plus), for foreigners, this version is simply dubbed
NanoCAD PROThe whole trouble is that, as I understand, in our country of companies where the design process is put on the "mind" is probably still less than offices where everything "should be done yesterday" and "on the knee", but on people implementers of automation are looked upon as holy fools. This is true my personal opinion and at the same time, it is far behind the reality, it may already be a bright future, a “garden city” and all that, then I will be very happy for my homeland =)
But back to the Nanocad, in the light of the current world conjuncture he has for Russian companies (including state-owned companies) one chip, namely ...
2. Import substitution

Life somehow does not become calmer, extends sanctions, and you see that it comes to the point that we will crush the sanctions distributions on DVDs with a bulldozer, what then do?
It should be noted that historically, we have an overwhelming advantage in products of Autodesk and its twin brothers in the field of building design, products of the company Ascon (Compass), somehow did not take root, although sometimes the projects carried out in Compass, are also found. It should be noted that this is again my personal opinion, I hope it will not provoke a “holivar”.
Well, going back to “AutoCAD and Company” what do we have? Autodesk products are quality but expensive and the office is central in the USA. There are BricsCAD and ZWCAD, they are of course cheaper, and for example the same BricsCAD will tell a bunch of advantages about itself
in comparison with others , but still, despite the presence of domestic offices, they can also be considered foreign. These programs have their fans, but I can’t say anything about them - I didn’t use it.
There is also DRAFTSIGHT, which has a free version for private use that runs under Linux, neither say anything bad nor good about it, I used it for about 30 minutes, probably, and that for a long time.
Well, there certainly is ArchiCAD, but it seems to me there is a slightly different concept and we will not compare them now.
There are other CAD systems, including domestic ones, I know very little or nothing about them.
The main thing is that, apart from the dependence on the Open Design Alliance, Nanocad is probably the first candidate for the "import substitution" of some Autodesk products in the field of building design.
Note that the platform has a vertical of solutions and you can meet various specializations from mechanics to modern BIM, I honestly have not encountered them in practice and I can not say whether, for example, Nanocad “Engineering BIM” can replace the solutions based on Revit.
By the way, it would be appropriate to say thanks to Autodesk, because if you believe the forum, then the update of the free version of Nanocad was tied exactly to the update of the DWG format to the version of DWG 2018. The exact
timing of the update of the free version is still unknown .
Well, besides paid products, let us recall that there is of course an opensource solution: FreeCad, LibreCAD, QCAD - I sincerely wish them success, but I think few people dare to build a project business based on them, at least for now.
Well, in order to move smoothly to API issues, I’ll say that the MultiCAD .NET API theoretically allows you to write universal applications that will run
in Nanocad, AutoCAD, ZWCAD . In the case of a non-native platform, the libraries are launched through the software layer. True, in practice, I failed to verify this now, and why? And because I only have AutoCAD 2017 installed on my PC, and there is an accessible “layer” on the developer portal, it does not support it (the edge is AutoCAD 2016). So that we leave the evidence on the conscience of the developers.
Now we finally began to smoothly approach the problems that the novice developer will face, determined to master the Nanocad API.
3. Access to API, documentation, where to start.

Perhaps the most rational way will be to register in the
"Club of Developers" Nanocad. Fill in a simple questionnaire, wait for approval (I think if it is adequately filled out, then there should be no problems), after which you get access to resources for development.
What are these resources:
- Access to licenses and distributions of released versions of Nanocad, including some beta versions, as well as directly to the API itself (SDK package).
- Access to a private forum for developers (not to be confused with a regular forum )
- Communication with developers, the ability to point to a "bug" or request a "feature."
Well, in words everything looks very good, in practice, of course, it is also good, but still with a fly in the ointment.
I think, since this direction is non-core and not monetized, they are doing it on a residual basis, so, for example, only beta version 8.5 is available on the developer portal, although the company’s portal has already posted a full version. The problem is that the full version with of. site, in my opinion, goes without the SDK, so sit down think strongly the SDK from the beta is different from the final or not.
Well, as I mentioned above, the MultiCAD_AC_ZC_Enabler_2209_RU package (a set of “layers” for API work in other CAD) has probably already been updated too, but there is no newer version (for AutoCAD 2017).
But once again, and for that -
thanks! These are trifles, the main thing is that you can get licenses for new and old versions of the program, and start sawing your application (licenses are given only for development).
The second problem is the API documentation, it should be noted that there are APIs for many languages: pure .NET API (not Multikad), C ++, Lisp, but we will talk today only about the MultiCAD API .NET. So, if you are accustomed to a detailed description of classes, methods, properties in native libraries from Microsoft, you will certainly be disappointed. Most of the descriptions in the help seem to be automatically generated, but sometimes there are still classes for which there is an explanation. It turns out that if you are “not any programmer” (as I am) and you are not a brilliant detective at the same time, in order to immediately solve the logic of the API, then you cannot do without outside help.
Where can we get help? And almost nowhere except the developers forum. But about the forum a little later, but to begin with about literature.
With educational literature, everything is simple - it is almost there! In the API documentation itself there is a small explanation of how to create a project (more on this in the next chapter), a couple of short notes and a few examples.
There is a book
“The Way to nanoCAD” , since I was “very secured”, I even bought it (by the way, I found it cheaper than on the official website). The book itself is good, you can scroll through the day, and thus find out what you can (and cannot) do in Nanocad 8.X and how quickly you can transfer to it from AutoCAD. The book has the 13th chapter, which summarizes the basic concepts of programming for Nanocad. But there is not much information and porridge from it can not be cooked, in fact, this statement of reference from the SDK + is a few good techniques and explanations.
What else is there? There are articles in the company's blog on Habré or, which is more convenient in my opinion, the same articles in the
English version of the blog via API (there they are not mixed with articles that are not related to the development). The articles are good, but they are frankly small and they rarely come out, as I mentioned at the beginning, the latter came out almost 2 years ago.
The community at Nanocad is small, so it seems that all that remains is a forum for developers. On the one hand, it is clearly impossible to say that the forum is living a stormy life, that there is a boom and so on. On the other hand, the specialists of the company try to answer normal questions during the day, for which they are thankful. But with “abnormal” (stupid) questions, things are worse, there is no one to answer them (so I sometimes communicate with myself there).
I think the main problem is that there are few enthusiasts on the forum. And in order to fix this, I am writing now, and you are reading this article.
Another important point is licensing.
Firstly, by joining the developers club you sign a contract (well, in the sense of clicking the "I agree" button), in which it is written in a difficult legal language that it is possible and impossible.
The question of the interpretation of this contract in terms of the rights to your applications (libraries) to the developers was asked by various people, including
me . The meaning of the answers is something like this: Nanosoft does not limit the free use and distribution of your work on the basis of the Nanocad development tools.
And in order to find out it is not necessary to join the club, simply read the license agreement for any version of the program (at least since version 5). For example, the SDK for the free version 5.1 is available inside the distribution (at least it used to be), that is, in principle, it looks like a club and you don’t have to join, but if you want to use the latest API versions (and we want, because in NC5 .1 it is scanty), you still have to enter.
But enough to say, it's time to do something useful, let's move on to the part for which the whole article was conceived.
4. Set up the development environment and write a simple command.
Before we begin, I will say that we chose the MultiCAD .NET API not only for its “cross-platform” nature, but also for the ability to create
custom primitives (but in this example we will not create them).

So, we are going to write a team that draws a face, the one on the left, but then you will draw your own on the right (just kidding). We will focus on Nanocad 8.1, but the code is simple and I think it will go in any version of the 8.X. family.
We will write and collect the code in MS Visual Studio. Ok, and which version to choose? It all depends on our goals. So the examples included in the SDK for NC 8 were collected in MS Visual studio 2012. And when you try to open them in later versions, a solution update wizard may appear.
Unfortunately, since I haven’t collected the whole package from the SDK, I can’t say whether the conversion to a newer version of the project influences its performance. But I can say for sure that if you download the free VS Express Desktop 2012, then the projects in the SDK will not be cursed and, in principle, they can be collected calmly.
By the way, if you want to download VS Express Desktop 2012
from the Microsoft website , it’s not a fact that you will succeed, in my case, MS apparently thinks that I am crazy and if you persistently try to download it, it blocks me, but fortunately this version can also be found on the web , but again, the registration service seems to have died, so I’ll also have to look for the code.
Anyway, that example that we will write with you now can be collected in a later version of Visual Studio. For example, I use VS 2015 Community edition, but I think in 2013 and in 2017, I also have to go.
The first thing to start is to create a project (this information is also in the SDK).

Attention choose .NET Framework 4.0 This version is used in the API for NC8 (for NC 5.1, for example, .NET Framework 3.5). Next, select the class library, the name you can choose what you want.
Next you need to connect the libraries from the MultiCAD .NET API (mapimgd.dll and mapibasetypes.dll), as in the picture:

Be sure to remove the item locally in the properties:

Configure the debugger so that our assembly opens immediately in Nanocad. To begin with, in the properties of the project, we specify nCad.exe as the application being launched (as in the picture).

Let's connect our library to the list of startup files (so as not to call the netload command every time). To do this, in our case (for NC 8.1), go to C: \ ProgramData \ Nanosoft \ nanoCAD x64 Plus 8.1 \ DataRW and find or create the load.config file with the following content.
<root> <list> <module path="C:\Users\...\bin\Debug\nanoforhabr1.dll"/> </list> </root>
Instead of three points, naturally, the full address to your project folder. It is not necessary to be limited to one record in the future, you can add another 1 section if you have your own libraries.
Now, when you press F5, our project will be immediately loaded into Nanocad and you will only have to type the command that we will write.
As usual, we are going to sort it out into pieces now, and the full text is available on
GitHub (only. * Cs file is located at this address, if necessary, create a project yourself)
So, for the beginning we will write the necessary namespaces:
using System; using System.Collections.Generic; using Multicad.AplicationServices; using Multicad.Runtime; using Multicad.DatabaseServices; using Multicad.Geometry; using Multicad.DatabaseServices.StandardObjects; using System.Windows.Forms;
Next, create a team.
namespace nanoforhabr1 { public class startfor81 { [CommandMethod("Dface", CommandFlags.NoCheck | CommandFlags.NoPrefix )] public void DrawFace() {
Attribute [CommandMethod ("Dface", CommandFlags.NoCheck | CommandFlags.NoPrefix)]
It defines the name of the command that we will enter in the NC command line (in our case, Dface), and then the flags go; I’m not ready to say about the flag values ​​yet. Then immediately comes the name of the class in which we implement our "business logic", the name of the class is any - at your discretion, I have public void DrawFace ()
In the next section, we will draw the left half of the face.
So, let's understand. In the MultiCAD .NET API there are classes that are responsible for defining geometric objects and displaying them in a drawing, create an eye: DbCircle eye = new DbCircle (); - creates a circle object (similar to the CIRCLE command in the command line or clicking on the circle in the toolbar) then we adjust the radius of the circle and the coordinates of the center, I think it’s so clear. eye.DbEntity.AddToCurrentDocument (); - adds an object to the drawing.
With a simple line, I think everything is so clear (this will be our nose).
Then draw a mouth. Define a polyline DbPolyline mouth = new DbPolyline (); We form points on which it will be built (inclined and straight line).
List<Point3d> mouthPoints = new List<Point3d>() { new Point3d(100, 150, 0), new Point3d(200, 100, 0), new Point3d(350, 100, 0) };
mouth.Polyline = new Polyline3d (mouthPoints); - create in the database object the geometry according to our points.
mouth.Polyline.SetClosed (false); if you want the line to close - change the value.
mouth.DbEntity.Transform(McDocumentsManager.GetActiveDoc().UCS);
- I borrowed this line on the developers forum, I don’t know whether it is necessary to precisely change the system of user coordinates to the world or not =)
Draw the second part of the face
We simply create the second eye by analogy. But the second half of the mouth mirrored for the sake of diversity. In fact, we make an analogue of the MIRROR team (mirror)
mouth2.Polyline= mouth.Polyline.Mirror(new Plane3d(new Point3d(350, 100, 0), new Vector3d(200, 0, 0))) as Polyline3d;
This command creates for us a new mirror copy of the line reflected from the base point and the plane (it’s as if you poke a mouse at the screen and draw a line along which the object will be reflected).
Add a little interactive.
The first section simply sends the text to the console (the window where you enter commands). The second section creates an object for entering data into the console and gets the value entered by the user. In this case, we ask the user to introduce himself and save his name.
Create a text object, this is a small share of humor in our team.
We draw the user's attention to the created record, and at the same time we demonstrate that a design, such as windows.forms, for example, can be built into your application, that is, you could make your own form call and then process the data. We will simply display the username obtained earlier.
It seems that our face is dissatisfied with its being, let's remove it.
In the last section, we do two things: we show the user a pop-up hint that the “delete” command was automatically turned on and we run another command from our team.
We press F5 and if everything is OK, we can check our team in action, do not forget to enter the name of the team as in the screenshot.

And to intercept some debug information, you can use a special
monitoring utility .
If suddenly you don’t want to join the developers club, and you really want to see the result of your work, you can download the demo version of NC 8.5. It looks like it comes without an SDK bundle, but we will not be upset, naturally the mapimgd.dll and mapibasetypes.dll libraries should be in the package of the program itself, so that they can be found in the bin folder.
I do not know whether this is possible from the point of view of the law, but I think that there should be no problems.
So, I shared with you almost everything I knew at the moment, it remains only to draw a conclusion.
5. It's a shame (Conclusion)

Well, what did Viktor Koklyushkin say: “It's a shame”, why is it insulting? For the fact that a promising project - a product of a completely acceptable quality did not unfold, as it could unfold. Strangely, of course, it seems that even some state support measures were there, it seems that in the free version you can really draw something simple, without wanting to throw a brick at the monitor, but still somehow the environment created around the product is worse than it could be. I’m thinking that if more people get involved in the development for Nanocad, even if it’s just “just for fun”, as we are now, then Nanosoft will feel its relevance, maybe the forum will heal, the APIs will start to be better documented and the files are more often laid out. In principle, if we consider that it may still be worthwhile to wait for the update of the free version, then maybe it will be so in the future.
In the meantime, I’ll say thank you and wish good luck to the developers of the Nanocad and to everyone who has mastered this article to the end, despite the jokes from the Anshlag.
Have a good start of work week!