The script integration in nanoCAD consists of three steps: registration of new commands, download these commands in the software environment and bind commands to the interface elements. You can ignore the last step - in this case you can invoke commands from the command line. Let’s consider each step in more detail.
A new command registration in nanoCAD is performed through a dedicated nsf-file, which is essentially a xml-file. Briefly, the command is described in the tags: ‹command›‹/command›, and has four attributes: name, weight, cmdtype and capsdisable. The understanding of “name” and “weight” attributes is quite clear (“name” is the command name, which is typed in the command line; “weight” is the command weight, also this parameter is optional and equal to 30 by default). It is necessary to understand two other parameters better.
‹command name="save" weight="30" cmdtype="1" capsdisable="0"›
overrides the save document file command.
One nsf-file can define several commands. It is structured in the following way:
‹?xml version="1.0" encoding="utf-8"?›
‹command name="cmd1" weight="30" cmdtype="1" capsdisable="0"›
‹command name="cmd2" weight="30" cmdtype="1" capsdisable="0"›
‹command name="cmd3" weight="30" cmdtype="1" capsdisable="0"›
Here, as you’ve probably already understood, three commands: cmd1, cmd2 and cmd3 are defined.
Within the ‹command›‹/command› tags it is possible to place two more tags: ‹description›‹/description› and ‹script›‹/script›. The first tag defines the command description. The second tag specifies the language of the script writing – VBScript or JScript. For example:
structure. It prescribes a script code.
Due to this knowledge you can create your first nsf-file, which transforms your script into the command and register it in nanoCAD without any problems:
The described “hello” command displays the classical greeting in the command line. Save this xml-file with the «userdata.nsf» name. The first step is finished.
Step 2. The command file download when nanoCAD is run
To download the nsf-file, enter nsf in the command line of nanoCAD, specify a path of the created «userdata.nsf» file. Now it is possible to invoke commands described in the file, for example, the command created in the previous step – hello:
Fig. 1. The simplest hello command.
It is not expedient to repeat these steps each time when we need to invoke our command. So let’s automate this process.
A command creation of the nsf-file download
We should create a command which will run the created nsf-file. To this effect let’s create the «userdata.cfg» text file and describe «load_userdata_nsf» command:
weight=i30 |cmdtype=i0 | intername=sload_userdata_nsf
The script written above describes the new load_userdata_nsf command, which runs nsf command (RealCommandName=snsf) with the options specified in the Keyword line. I draw your attention to the “s” character, which follows after the equal sign («=»). This symbol is necessary for the nanoCAD’s interpreter to work with the cfg-file.
Let’s consider more interesting and useful options in detail. For example, I draw your attention to the following structure:
This means that when you run the command (in this case - “nsf”), the «userdata.nsf» and Enter commands will be placed in the command line (i.e. the «userdata.nsf» file will be loaded), and after the CloseDocument+Enter command (i.e. the current drawing will be closed), and finally the NewDocument+Enter command (i.e. a new document will be created). I think you’ve guessed that the «^M» symbol means Enter.
Automatic loading of the nsf-file
The next action allows loading the load_userdata_nsf command automatically when we start nanoCAD. To achieve this, we should create the «userdata.ini» text file with the following lines:
; Registration of the file containing commands at nanoCAD’s startup
To finish step 2 we should put three created files: userdata.nsf, userdata.ini and userdata.cfg into the nanoCAD’s installation folder and start the program. If you’ve done everything correctly, the userdata.nsf file will be loaded into nanoCAD automatically and the hello command will be registered. If the nsf-file describes more commands, all of them will be available from the command line.
Step 3. Integration of the script commands to the nanoCAD interface
The «userdata.cfg» file is responsible for command integration with the nanoCAD interface. This file has a specific structure where all elements of the nanoCAD interface are written with the same extension. This article doesn’t allow us to list the numerous possibilities and options of this file, but baseline set is following (all commands need to be registered in the «userdata.cfg» file):
Registration of the nanoCAD menu
This is carried out in the following way:
[\menu\mycommans] |name=sMy commands
[\menu\mycommans\hello] |name=sNew command HELLO |intername=shello
You will find the My commands menu item with New command HELLO item, which runs the hello command. You can extend your menu item by adding new lines.
Registration of the nanoCAD’s toolbar
This is carried out in the following way:
[\toolbars\mycommans] |InitialVisible=f1 |name=sMY commands
You will find the My commands toolbar and one new command located on it. The InitialVisible option is responsible for the toolbar visibility when you start nanoCAD (f1 – visible, f0 – invisible).
Appropriation of the specific icon to the command
To appropriate a specific icon to the command, you should override the command by specifying dll with the image resource. In particular, you can use the newbtns.dll file, which is installed with nanoCAD.
weight=i30 |cmdtype=i0 |CapsDisable = W0xFF
BitmapDll=snewbtns.dll | icon=sPENCIL
It is also possible to run the command using the hotkeys by registering them in the following way:
Now you can invoke the hello command by pressing Ctrl+Shift+1.
Final steps: Features of the interface registration
At the moment any changes in the nanoCAD interface are applied only after a single reset of the program and registry cleaning. Therefore, we should add the following lines in userdata.ini:
Starting the program via the ncad.exe (important!), we get the new HELLO command, menu item, toolbar and hotkeys. Start the software and stop the setting reset by adding the «ClearRegistry=f1» line in the userdata.ini file:
Why is it important to run the software directly from ncad.exe? The fact is that when you run the application using standard desktop icon or Startup menu item, it checks the integrity of installation and if you make any changes in the interface, the application will try to restore files and nanoCAD registry record, running the Windows Installer. It will ruin everything what you have done. When you are writing and debugging your scrips proceed with ncad.exe.
But when your have finished and your application is checked and registered in the system, you can run the software using the standard desktop icon or Startup menu item. Once checked the integrity of the key files, the software will be run correctly.
We have learnt to extend the features of nanoCAD (through three setup files: userdata.nsf, userdata.cfg and userdata.ini). In this case new commands are added into the nsf-file and interface settings are added into the cfg-file. All together, they are linked by the ini-file.
Fig. 2. The adjusted on new commands nanoCAD interface
The commands which you can use in nanoCAD are described in the ActiveX API document. The installation folder is located in the following path:
The ActiveX API provides the users with great opportunity. Small automation tools save you from routine and speed up your work.
It is possible to download demo files: userdata.nsf, userdata.cfg and userdata.ini
. In this case you don’t have to create these files, you can use and edit the downloaded files.