We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 7
sn32018 Fist stops into nanoCAD's programming world
Menu
Products
nanoCAD Plus
nanoCAD Pro
nanoCAD Mechanica
nanoCAD Construction
nanoCAD Constructionsite
nanoCAD 30Scan
nanoCAD.
nanoCAD
Why nanocao?
Key features
Virtual tour
Comparison
News
Support
Tech support
Installation
FAQ.
Forum
Developers
Welcome, Developer!
Join the club
Beta software
Developers blog
Company
Nanosoft
About us
Our vision
Contacts
Buy nanoCAD
First steps into nanoCAD’s programming world
» Why nanocAD
» Support
» Developers
» Buy
» Company
» My Account
First steps into nanoCAD's programming world
hitpssnanocad.com/page/Programmingt wansro%8 Fest stops into nanoCA0's programming world
nanoCAD provides several types of API for CAD application development. In order to build utilities and small application
you can use scripts based on ActiveX Automation (Script and VBScript), Below we will show how it works by creating a
small application, which interacts with the user through the command line and draws lines in predefined order on
nanoCAD’s drawing space automatically. Based on this example you can create your own application,
The result of the demonstration example should be similar to the image below:
To get the same result we should have the following
* nanoCAD 3:5 (its possible to download the software on the nanocac.com site or from one of the torrents, for
example thepiratebay.or9}
# any text editor (l use Notepad++)
Tasking
There is no significant difference between programming languages you use: nanoCAD supports Java-script as well as
Visual Basic Script. In this article the Visual Basic Script was used.
To demonstrate the work of VB-Script we will transform the LISP-Script to the VB-Script, The shape shown in fig.1 was
drawn by using the recursive functions. Let's create the same shape in VB-Script.
hitpssnanocad.com/page/Programmingtansn0%8 Fest steps into nanoCA0's programming world
Fig, 1. The universal Sierpinski curve
Structure of the program
VB-Script in nanoCAD doesn't have any input function. The script starts running from the first lines and works to the end.
The main program module is quite simple ~ a single iteration, Let's start with it
Code in LISP Code in VBScript
Line 7h}
sete i tay) ine 7, 8
). There is
From the code we can see that the Sierpinski curve is drawn by four recursive functions: AQ), BO. CO,
ction, Size) function which draws a line on the necessary scale and at the required
also the special Line (0
angle. Definitions of these functions are realized by VBS tools, far example, the A) -function will be described in LISP and
VBS as
hitpssnanocad.com/page/Programmingt9372018 Fest stops into nanoCA0's programming world
Code in LISP Code in VaScript
defun A (kD aCe)
(cond ( (> 0) kf k > 0 then
(ag-ki) (kL)
(Line 1h) yh
(BU-kI)D
(Dine 0 (* 2nd) Line 0, 2 *h
(Co ¢-kr) ket)
(tine Th) Line 7,
(agi) A(k-1)
yo Bnd If
End Sub
Place these additional five functions at the end of the main script. The following steps will introduce you to output graphic
in nanoCAD and interact with the user.
The first steps
First of al, VB-Scrpt is a text editor with the bs file extension, which can be run in nanoCAD by using VBS (see fig2). tis
easy, you should only speciy the script path and if it was written correctly, the script works. I the script has any erors, the
message about it appears in the command line.
mold Seite ph
——— -
Ucseoncn tee]
Qrgence~ —Nowfoler
“te Favorites
Desktop
B Downloads
\3
scence | (J trate
Me
é=
a
(i Ubrares
[Documents
a) Music
El Petes
Bi videor
PM Computer ea] — Fie |
Sack) (oe)
Compute
Network
[ssp [enue Tostvs Jorancx rou [orm [sw [54]
Fig.2. Java and Visual Basic scripts are run by JS and VBS commands correspondingly
\VB-syntax is completely standard, so we can use DIM, SET, FOR-NEXT, IF-THEN-ELSE, declaration of variables,
() or wsqBox ()), function declarations and/or integer division operations.
arrays and standard features (such as. cst
To get access to the current drawing use Thi ebrawing, If you are going to draw in the model space (the Model tab), the
hitpssnanocad.com/page/Programmingtsn32018 Fist stops into nanoCAD's programming world
Mode1space collection will be defined through the following structure:
jode1Space
The access to the command line is carried out through the Utility object. The script, which is written below, outputs the
classical greeting in the command line:
Dim ut
Drawing til
"Hello, worla!")
With cetrateger(), GetPoint (), Gets
ng(), GetReal(), GetBntity(), GetDistance(),
.ngle () functions and also with some others itis possible to request data from the command line, For example:
= Thisbrawing.util
tinteger
pecify a positive number (>=
Loop While count <= 0
= ThisDrawing.Utility.Get?oint ("0,0,0", “Specify a point Wm” & i}
Hf you know where the data is entered and how to interact with the user, you can start to write more complicated
Programs.
Most crucial functions
What other functions can be used in nanoCAD? In general, you can use al functions that are defined by DWG file
structure: draw a line, arc, circle, hatch, define a point, polar coordinates, open/close a file, work with layers, variables, etc.
‘These functions are described in the SDK documentation to DWG: Autodesk (Developer Center section), or Open Design
Alliance,
We will use the Addiiine (startpoint, endpoint) function to create a 2D line. Also you can use the following
functions:
AddCirele (center, radius) ~ circle;
Addarc (center,
startangle, endangle) —arc
AddSllipse(center, majoraxis, radiusratio) — ellipse;
AddPoly1ine (verticeslist) — polyline;
AddText (textstring, insertionpoint, height) ~single-line text
AddiYext (insertionpoint, width, text) ~multi-line text.
‘The coordinates which are transferred into nanoCAD can be three-dimensional. In this case, it has been three-dimensional
array, but itis more comfortable t
like this:
nsfer the «x,y, 2» line, where x, y, 2 are three-dimensional coordinates. That is
Dim ms
hitpssnanocad.com/page/Programmingtansro%8 Fest stops into nanoCA0's programming world
Also the lines in this script are located in the different layers. To get this you should create two new layers at the beginning
and then change the current layer:
olyrLinel = ThisDrawing.Layers.A s")
Set olyrLine2 = ThisDrawing.Layers.Add ("Rectangles")
Set olyr inel
cline.Layer = olyr.Name
The result
At the end you should have the result as shown in fig.3. Of course, ths result doesn't have any particular usefulness (other
than an aesthetic pleasure), but it gives some food for thought and self-improvement
(uA el en I) Si Pi EAI hla) Tel srdirs
Br Sit tee EBRD Os Telfoeytae
netpe Sek
ne Wat
Theiss
Sica Or
UES per vonpen
cS ane
Bpletter an option [270%
Eyenter an option (1
#
IB cownsna
Fig.3. Result of VBScript command
The demonstration script you can download here: demoscrpt zip, Download, unzip, open using any text editor, lear and
hitpssnanocad.com/page/Programmingt9372018 Fist steps into nanoCAD's programming world
run it in nanoCAD. And a litte tip: don’t set the order of curves above 4 or you will get stuck -)
NANOCAD
SMART DESIGN AND DRAFTING
. Tech support . Welcome, Developer! . Nanosoft
. Installation . Join the club . About us
. FAQ . Beta software . ur vision
. Forum . Developers blog . Contacts
. Products . nanoCAD Applications . Partners
, +7 (495) 645-86-26
, [email protected]
. Old version site
Copyright 2018 Nanosoft. All Rights Reserved. Privacy policy. Terms of Use.
hitpssnanocad.com/page/Programmingt