Command Scripts and Extensions
Command Scripts (SCR)
Command scripts are convenient for often performance of certain sequence of actions. Command script is a text file with .scr extension, which contains a set of instructions intended to be executed in nanoCAD command line. Each line of the file contains a command or reference to another script.
There are following commands to work with scripts:
- SCRIPT loads the script file and consistently performs instructions described in this file. If any script is active at the moment the SCRIPT command is invoked, the script is stopped;
- SCRIPTCALL a service command launched from a script file, which launches another (nested) script; An example of using SCRIPTCALL commands in the text of a scr script loaded by the PACKAGE command:
FILEDIA 0
SDI 1
OPEN _Y "C:\tests\t1.dwg"
SCRIPTCALL "C:\tests\Close.scr"
SCRIPTCALL "C:\tests\23885_circles_5000.scr"
SDI 0
FILEDIA 1- RESUME continues an interrupted script;
- RSCRIPT repeats the last script.
Script files can be created outside the program with help of any text editor. The launched command is written with a new line of the file with parameters values requested by it, positioned through space. Each space in a script is significant, it is similar to pressing ENTER or SPACE.
In case it is necessary to work with command which, when being performed, displays dialog box, use its version without dialog with a hyphen before the command name. For example, you can use -DIMSTYLE instead of DIMSTYLE command.
Scripts can contain comments. Any line that begins with a semicolon (;) is considered a comment, it is ignored while the script is being processed.
The last line of the script must be blank.
Names of files and named objects (layers, styles) that contain spaces must be enclosed in double quotes.
You can run a script at nanoCAD startup from the operating system’s command line using –s switch.
Software Extensions
nanoCAD allows you to use different software to extend its functionality: add new commands, entities, tools for editing and document management, database.
nanoCAD supports the following programming interfaces:
- NrxGate C++ API, is designed to create and transfer applications on C++, allowing you to create new entities;
- .NET API is designed to create .NET applications;
- MultiCAD API C++ API, is designed to write cross-platform CAD applications, allowing you to create new entities;
- MultiCAD .NET API .NET API, designed for developing cross-platform CAD-applications, creating new primitives
- COM API is designed to write automation scripts and create commands in JScript, VBScript, manage external nanoCAD applications via ActiveX®;
- LISP API is the dialect of LISP, designed to automate work in nanoCAD.
The documentation of nanoCAD’s API, examples of applications and scripts are available for members of nanoCAD Develope rs’ Club.
NRX and LISP File Loading

Menu: Tools – Application > Load application…
Command line: APPLOAD
The command allows you to load NSF, MultiCAD API, LISP, .NET and NRX-applications to nanoCAD.
After starting the command the Load/Upload Applications dialog box appears:

To load a file, select it in the top of the dialog box and click the Load button. All files loaded in this nanoCAD session display in the list of the Loaded applications tab.

Note
Unlike AutoCAD, where a LISP-application is loaded only into the current document, the commands of LISP-applications loaded in nanoCAD are available during whole working session from any documents.
Commands of loaded applications become available for calling from nanoCAD command line.
To record the history of the loading, select the Add to history checkbox. The list of previously loaded files can be viewed on the History list tab.
It is possible to automatically load the applications when you start nanoCAD. To do this, click the Contents button in the opened dialog box and add the files that should be automatically loaded for each new nanoCAD session.
After loading of the NSF, NRX, MultiCAD, .NET or LISP application, its commands, that can be started from the nanoCAD’s command line, are available.
.NET Application Loading
Ribbon: Manage – Applications - Applications > Load .NET application
Menu: Tools – Application > Load .NET application
Command line: NETLOAD
To load a NET-application, start the command and in the opened dialog box select the necessary dll-file.
The command of loaded NET-application are available from the any documents during whole nanoCAD working session.
JScript Loading
Ribbon: Manage – Applications - Scripts > JScript
Menu: Tools – Scripts > JScript…
Command line: JS, -JS
After starting the command, select the necessary file with js extension in the opened dialog window. Script execution begins immediately after loading.
VBScript Loading
Ribbon: Manage – Applications - Scripts > VBScript
Menu: Tools – Scripts > VBScript…
Command line: VBS, -VBS
After starting the command, select the necessary file with vbs-extension in the opened dialog window. Script execution begins immediately after loading.
Loading Python-Script
Ribbon: Manage – Applications – Scripts > Python
Menu: Tools – Scripts > Python
Command line: PY, -PY
After calling the command, in the dialog box that opens, select the desired file with the py extension. The script execution starts immediately after the file is loaded.
To work with the PY command, Python 3 should be installed in Windows operating system and Active Scripting support (win32com.axscript) should be enabled. You can install Python Win32 extensions (pywin32) and Python Active Scripting support will be registered automatically.
NSF Files Loading

Command line: NSF
It is possible to register the scripts as nanoCAD commands. To register js or vbs-scripts (both one and whole packet), a programmer create NSF-file (the defined structure XML-file), which subsequently is loaded to nanoCAD with NSF command by user.
When the NSF-file is loaded, its command makes available.
Work with LISP-Applications

Ribbon: Manage – Applications - Scripts > Lisp

Menu: Tools – Scripts > Lisp

Command line: LSP
After starting the command, select the necessary option in the command line.
Options:
COmmands Function s Variable s
Outputs the commands, LISP variables and loaded LISP-applications to the command line.
Load Allows to load LISP-file with lsp or mnl extension by entering whole path of the file and its extension.
Execute Allows to execute one of the functions lsp or mnl file, that was loaded by using the Load option.
Console Converts nanoCAD command line to the LISP console mode. In this case, the command prompt changes to _>:
In the nanoCAD, entered function can be performed in the Console mode.
To exit the LISP-console mode, enter (quit) or (exit).
The ncad.lsp file
The root nanoCAD folder contains important ncad.lsp file that is being automatically loaded on nanoCAD session start. The ncad.lsp is a text file that should have a correct LISP application structure. It can include function definitions, command definitions (they are to be created as functions with the C: prefix) as well as executable LISP expressions and comments.
After loading ncad.lsp a message in command line is generated. It displays names of the commands defined inside the file, e.g.:
nCad.lsp loaded. Commands: RESETVAR, DWGCLEARIt is possible to include executable expressions in ncad.lsp file to load additional applications, set values for LISP variables and etc.:
(setq @@PATH "D:\\MyPlugins\\")
;Loading applications
(load (strcat @@PATH "lspplugin.lsp"))
(arxload (strcat @@PATH "nrxplugin.nrx"))
(appload (strcat @@PATH "nsfplugin.nsf"))Script Editor (JS, VBS, LSP, DCL, SCR)

Menu: Tools – Scripts > Script Editor…
Command line: SCRIPTED
The built-in script editor allows you to create, edit and run batch files of various formats: ActiveX (.JS, .VBS), LISP (.LSP), DCL, SCR.
The script editor window is a functional bar, the title of which contains the name of the file being edited.
By default, the editor opens with an empty text field. When saving to a file later, specify a particular script format from the list of available ones.
You can make it so that when you call the script editor, the last script edited in it automatically opens. To do this, set the option to automatically open the last script in the ScriptEd options dialog of the script editor, described below.

Buttons
New File. Select the type of script in the drop-down menu.
Open Script. When you click on the button while holding down CTRL key, a menu will appear with the list of the most recently opened scripts and folders.

Save Script.
Save As.
Undo.
Redo.
Find Text. Opens the collapsed Search and Replace bar.
Replace Text. Opens the expanded Search and Replace bar.
Run Script.
Options.
Help.
Options
The button opens the scrip editor dialog box. The options dialog can also be opened by combination of CTRL+T buttons in the process of editing the script code. In this case, the cursor should be in the text field of the script editor.
The Font tab of the Options dialog allows you to configure font settings for each category of a specific programming language.

The Options tab allows you to configure general options for displaying the code in the edit window.

Options:
Tab size Tab Size in spaces: the number of spaces to be inserted into a line when the
TAB button is pressed on the keyboard.
Autoident Enables/disables automatic indentation of a new code line identically to the
indentation of the previous line.
Brace highlight Highlighting the opening and corresponding to it closing brackets when the cursor is on one of them.
Restore last script
Automatic loading of the latest script when opening the editor.
Folding Enables/disables the text-block folding node. Text blocks are detected automatically.
Style Folding Node Style: Arrows, Plus/Minus, Circles, Squares.
White space marker size
The size of the white space marker in pixels. To enable the display of the space character, press CTRL+W on the keyboard.
Preserve encoding
Preserves the original encoding of the script file.
By default, the script editor uses UTF-8 encoding. All new scripts created in the script editor will have this encoding.
When opening a script file in the script editor, the encoding is determined automatically. If the Preserve encoding box is checked, then the script will be saved after editing in the same encoding it was in before opening in the script editor. If the checkbox is cleared, then the script will be saved in ANSI encoding (the current user encoding) after editing.
Find and Replace in Scripts
The script editor has several tools to quickly find the right part of the code:
- Find and replace bar;
- Bookmarks;
- Panel for jumping to a line by its number.
Find and Replace Bar
To search for text in scripts, you can open the search bar in one of the following ways:
- By clicking the Find text button in the script editor;
- By the CTRL+F keys combination on the keyboard. In this case, the cursor must be in the text field of the script editor.
The search bar will appear at the bottom of the script editor below the script text edit field:

Find/replace mode switch button. When you click on the button, additional fields are opened for setting up the replacement of the found text. Clicking again hides additional fields. Search pattern input field. You can enter single text characters, character sets, and regular expressions in the field. When you click on the button located in the right part of the field, this opens a list of the latest requests entered. Find next. Pressing the button moves the cursor to the next match of the script text with those entered in the search pattern input field. Use regular expressions. Regular expressions will be used to search for text in the script. Match case. The search will take into account the case of the characters entered in the pattern field. Match whole word. The search results will only display exact matches with the text entered in the search pattern field. Close the bar.
To automatically replace text in a script, open the replacement bar in one of the following ways:
- By clicking the Replace text button in the script editor;
- By the find/replace mode switching button on the search bar;
- By the CTRL+H key combination on the keyboard.

Elements of replacement bar to set the text replacement:
Replacement pattern input field. The field is intended for the text with which you want to replace the found text according to the pattern from the text search field. Clicking on the button on the right side of the field opens a list of the most recently entered replacement patterns. Replace. Clicking the button replaces the found text in the current fragment of the text file. Replace all. Clicking the button replaces all matches found in the text file that match the text search pattern with the text specified in the text replacement pattern.
Regular Expressions
A regular expression is a text search pattern that uses special characters to search for multiple spellings of an expression in a single search query.
To search for text in scripts using regular expressions, click the Regular expressions button on the search bar. Repeated clicking the button disables regular expression search.
The following special regular expression characters are allowed:
- . Replaces any character.
- For example, the expression Layout.. will find all entries of the format Layout01,Layout02, Layoutaa, etc. in the script.
- ** Escapes the character following it from being read as a special character. For example, the expression Layout… will find in the script all entries of the format Layout.01, Layout.02, Layout.aa, etc., that is, the dot character after Layout will not be recognized as a special replacement for any character.
- [ ] Inside square brackets, a set of options is specified, either as single characters or as ranges. It is not necessary to separate options with a space. When specifying a range, the start and end values are separated by a – sign.
- For example, the expression [1-9] will find in the script all the numbers from 1 to 9, the expression [a-z] will find in the script all the characters from a to z, and the expression [ab1] will find in the script individual characters either a, or b, or a number 1.
- * Applied to a character in the text and says that this character can either be absent or repeated from one to several times.
- For example, the expression Layout0*. will find entries of the form both Layout1 and Layout01, Layout001, etc.
- + Applied to a character in the text and says that this character can be repeated from one to several times.
- For example, the expression Layout0+. will find entries of the format Layout01, Layout001, etc.
- ? Applied to a character in the text and says that this character can either be absent or repeated only once.
- For example, the expression Layout0?. will find in the text records of the forms Layout1, Layout01.
- ^ Negative symbol. Applies to the character to be excluded from the search results. For example, the expression Layout.[^a-z] will find all entries in the script that contain the word Layout, followed by any character, and then any character other than the English letters from a to z.
- $ End of line character. Applied at the end of the regular expression so that nothing extra is included in the search results.
- For example, the expression Layout.[^a-z] will show Layout001 as a search result that matches the conditions, despite the fact that there is an extra character - 1 at the end. The expression Layout.[^a-z]$ will not include this entry in the search results.
More information about regular expression syntax can be found here.
Bookmarks
To move quickly between lines, you can use bookmarks. Bookmarks are displayed as red flags on the left vertical bar of the script editor window next to the corresponding lines of code:
You can bookmark a line in two ways:
- by clicking the left mouse button on the bookmarks bar opposite the required line;
- by placing the cursor on the required line and pressing the CTRL+F2 key combination on the keyboard.
You can delete a bookmark in the same ways:
- by clicking the left mouse button on the bookmark flag;
- by placing the cursor on the line with a bookmark and pressing the CTRL+F2 key combination on the keyboard.
You can delete all bookmarks at once by pressing CTRL+L.
To quickly jump between lines marked with bookmarks:
- to go to the next tab, press F2 on the keyboard
- to go to the previous bookmark, press SHIFT+F2.
Move to a Line by Number
To move to a script line by its number, open the corresponding bar in the script editor by pressing CTRL+G on the keyboard.
The bar will appear at the bottom of the script editor:
The bar elements:
| The field shows which line the cursor is on. |
|---|
| A field for entering the number of the line to move to. |
| The total number of lines in the script. |
| Button to move to the desired line. |
| Close the bar. |
Shortcuts
Many actions in the Script Editor are available through keyboard shortcuts. However, they work only during script editing, that is, when the cursor is in the script editing text field.
| Select All | CTRL+A |
|---|---|
| Copy | CTRL+C, CTRL+INS |
| Insert | CTRL+V, SHIFT+INS |
| Cut | CTRL+X, SHIFT+DEL |
| Undo | CTRL+Z, ALT+BACKSPACE |
| Redo | CTRL+Y |
| Go to String | CTRL+G |
| Find | CTRL+F |
| Find Next | F3 |
| Find Selected | CTRL+F3 |
|---|---|
| Replace | CTRL+H |
| Open | CTRL+O |
| Save | CTRL+S |
| Save As | CTRL+ALT+S |
| Properties | CTRL+P |
| Run | CTRL+R |
| Find the Matching Pair Bracket | CTRL+{ |
| Display/hide space characters | CTRL+W |
| Set/unset bookmark in the line | CTRL+F2 |
| Move to the next bookmark | F2 |
| Move to the previous bookmark | SHIFT+F2 |
| Delete all bookmarks | CTRL+L |

In the same dialog, you can also configure general options for displaying the code in the edit window.
Creating Commands from Downloadable Applications and Command Scripts
Commands of the third-party applications, scripts, scenarios, etc. discussed above can be integrated into nanoCAD as independent commands. They can be placed in the ribbon, on toolbars, in the menu.
To do this:
- Add the desired script/application in the autoload list using the Application Load (APPLOAD) or Load NET Application commands.
For example, add LispExample.lsp with the following LISP command:
//LispExample.lsp
(defun c:SetColor()
(command "_-Color" "230")
)- Create a new custom nanoCAD command in the Customize user interface dialog box based on SetColor command from the loaded script/application. In the same place, specify the icon file for it.

-
- If necessary, create a new toolbar in the Customize user interface dialog.
-
- In the same dialog, drag a newly created nanoCAD command to the required toolbar, menu or ribbon tab.

- Reload nanoCAD.
Run nanoCAD from Command Line with Program Module
There is a possibility to load a program module or extension script together with nanoCAD launch from the command line of the operating system or by using a shortcut.
Syntax of call from the command line:
File names and paths that contain spaces should be enclosed with double quotation marks. For example:
"C:\Program Files\Nanosoft AS\nanoCAD x64 Plus 10.5\nCad.exe"
"C:\Users\Alex\AppData\Roaming\Nanosoft AS\nanoCAD x64 Plus
10.5\Samples\nCAD Mechanica. Shift.dwg"Script file or file of loaded application should be the most recent parameter in the call line.

Note
Ways to launch nanoCAD from the command line of the operating system with the simultaneous opening of the desired document on the desired layout or with the required named view are discussed in the Opening document from the command line section.
Options:
| -invisible | nanoCAD launch in a stealth mode. It creates only nanoCAD process. Nether window, nor program message are displayed on the screen. It is convenient to use at simultaneous load of script of loaded module to fulfill operation in the background. |
|---|---|
| -g | Loading program module. |
| -s | Loading command script (*.scr). |
Example of loading a drawing file and LISP-scipt in the background:
"C:\Program Files\Nanosoft AS\nanoCAD x64 Plus 10.5\nCad.exe"
"C:\Users\Alex\AppData\Roaming\Nanosoft AS\nanoCAD x64 Plus
10.5\Samples\nCAD Mechanica. Shift.dwg" -invisible -g
"C:\modules\plot_pdf.lsp"Example of loading a command script:
nCad.exe -s "C:\modules\my settings 3.scr"