fbcadcam logo 1

Fbcadcam Programmer's Guide

Home
Download
Install notes
User's Guide Forum
History Credits

The FbCadCam programmer's guide is about learning how to write scripts for use in fbcadcam's macro system.
However, since the script language is similar to FreeBasic, I first present the concept of coding in FreeBasic. If you already know how to code in FreeBasic then skip to the script section below.

Learning how to code in Freebasic.
To me the process of learning begins with creativity. It's like painting a picture.
I start off with a blank screen and ponder the idea "what shall I make today?"

So, what shall we make today?

How about:
Creating a cad program.
The original user interface for FBCAD had six sections:

'FbCadCam version 0.0.1
ScreenRes 800, 600 'create a blank screen (window) 800 pixels wide by 600 pixels high
Line(0,0)-(179,529),1,bf 'command button area
Line(200,30)-(699,529),2,bf 'drawing area
Line(200,0)-(699,29),3,bf 'menu area
Line(180,0)-(199,529),4,bf 'layer area
Line(700,0)-(799,599),5,bf 'entity properties area
Line(0,530)-(699,599),6,bf 'info area
Sleep
End

Next, create an array of command buttons.
I propose we make the buttons 18 pixels square
A grid, ten columns by 20 rows

'FbCadCam version 0.0.2
ScreenRes 800, 600 'create a blank screen (window)
Line(0,0)-(179,529),1,bf 'command button area
Line(200,30)-(699,529),2,bf 'drawing area
Line(200,0)-(699,29),3,bf 'menu area
Line(180,0)-(199,529),4,bf 'layer area
Line(700,0)-(799,599),5,bf 'entity properties area
Line(0,530)-(699,599),6,bf 'info area
'grid of command buttons
'10 vertical lines
Line(0,0)-(0,529),15
Line(18,0)-(18,529),15
Line(36,0)-(36,529),15
Line(54,0)-(54,529),15
Line(72,0)-(72,529),15
Line(90,0)-(90,529),15
Line(108,0)-(108,529),15
Line(126,0)-(126,529),15
Line(144,0)-(144,529),15
Line(162,0)-(162,529),15
'20 horizontal lines
Line(0,0)-(179,0),15
Line(0,18)-(179,18),15
Line(0,36)-(179,36),15
Line(0,54)-(179,54),15
Line(0,72)-(179,72),15
Line(0,90)-(179,90),15
Line(0,108)-(179,108),15
Line(0,126)-(179,126),15
Line(0,144)-(179,144),15
Line(0,162)-(179,162),15
Line(0,180)-(179,180),15
Line(0,198)-(179,198),15
Line(0,216)-(179,216),15
Line(0,234)-(179,234),15
Line(0,252)-(179,252),15
Line(0,270)-(179,270),15
Line(0,288)-(179,288),15
Line(0,306)-(179,306),15
Line(0,324)-(179,324),15
Line(0,342)-(179,342),15
Sleep
End

As you can see, adding code to the program (apx. 40 lines so far) makes it harder to digest but by reading through it line by line you can generalize what it's supposed to be doing.
By copying and pasting the above code into FBedit, saving, compiling and running it, you begin to understand what it means to make a program.

As it is, this program doesn't do anything other than paint a picture (ie. the general layout of fbcadcam's user interface).
My goal is to paint a picture of what programming is about which leads me to introduce the idea of using VARIABLES.
To those who are new to programming, the concept of the variable may be difficult to understand.
Below, I introduce you to the concept by showing you the keen advantage of using them.

The variable X
Take for example:
'grid of command buttons
'10 vertical lines
Line(0,0)-(0,529),15
Line(18,0)-(18,529),15
Line(36,0)-(36,529),15
Line(54,0)-(54,529),15
Line(72,0)-(72,529),15
Line(90,0)-(90,529),15
Line(108,0)-(108,529),15
Line(126,0)-(126,529),15
Line(144,0)-(144,529),15
Line(162,0)-(162,529),15

Can be rewrote as:
Line(X,0)-(X,529),15
Line(X,0)-(X,529),15
Line(X,0)-(X,529),15
Line(X,0)-(X,529),15
Line(X,0)-(X,529),15
Line(X,0)-(X,529),15
Line(X,0)-(X,529),15
Line(X,0)-(X,529),15
Line(X,0)-(X,529),15
Line(X,0)-(X,529),15

And all we would need to do is define what the value of X is:
X=0
Line(X,0)-(X,529),15
X=18
Line(X,0)-(X,529),15
X=36
Line(X,0)-(X,529),15
X=54
Line(X,0)-(X,529),15
X=72
Line(X,0)-(X,529),15
X=90
Line(X,0)-(X,529),15
X=108
Line(X,0)-(X,529),15
X=126
Line(X,0)-(X,529),15
X=144
Line(X,0)-(X,529),15
X=162
Line(X,0)-(X,529),15

Better yet, let the computer do the math:
X=0
Line(X,0)-(X,529),15
X=X+18 'here X=0+18 or X=18
Line(X,0)-(X,529),15
X=X+18 'and here X=18+18 or X=36
Line(X,0)-(X,529),15
X=X+18 'continuing on... X=36+18 or X=54
Line(X,0)-(X,529),15
X=X+18 'you're getting the picture now (X will be equal to 72)
Line(X,0)-(X,529),15
X=X+18
Line(X,0)-(X,529),15
X=X+18
Line(X,0)-(X,529),15
X=X+18
Line(X,0)-(X,529),15
X=X+18
Line(X,0)-(X,529),15
X=X+18
Line(X,0)-(X,529),15

Even better:
For X=0 to 162 step 18
Line(X,0)-(X,529),15
Next

Using a variable and the For Next commands condenses 10 lines of code to 3 lines of code.
And we can do the same for the horizontal lines in the grid by using a variable called Y.
'20 horizontal lines
Line(0,0)-(179,0),15
Line(0,18)-(179,18),15
Line(0,36)-(179,36),15
Line(0,54)-(179,54),15
Line(0,72)-(179,72),15
Line(0,90)-(179,90),15
Line(0,108)-(179,108),15
Line(0,126)-(179,126),15
Line(0,144)-(179,144),15
Line(0,162)-(179,162),15
Line(0,180)-(179,180),15
Line(0,198)-(179,198),15
Line(0,216)-(179,216),15
Line(0,234)-(179,234),15
Line(0,252)-(179,252),15
Line(0,270)-(179,270),15
Line(0,288)-(179,288),15
Line(0,306)-(179,306),15
Line(0,324)-(179,324),15
Line(0,342)-(179,342),15

Condenses to:
For Y=0 to 342 step 18
Line(0,Y)-(179,Y),15
Next

Now the program looks like this:
'FbCadCam version 0.0.3
Dim As Integer X,Y
ScreenRes 800, 600 'create a blank screen (window)
Line(0,0)-(179,529),1,bf 'command button area
Line(200,30)-(699,529),2,bf 'drawing area
Line(200,0)-(699,29),3,bf 'menu area
Line(180,0)-(199,529),4,bf 'layer area
Line(700,0)-(799,599),5,bf 'entity properties area
Line(0,530)-(699,599),6,bf 'info area
'grid of command buttons
'10 vertical lines
For X=0 to 162 step 18
Line(X,0)-(X,529),15
Next
'20 horizontal lines
For Y=0 to 342 step 18
Line(0,Y)-(179,Y),15
Next
Sleep
End

RECAP
How many FreeBASIC commands did I just throw at you?
These commands along with all the other commands availible with Freebasic are documented in the offline (chm) help file whick can be downloaded along with the FreeBasic compiler from FreeBasic.net. There is an online FBWiki as well. The commands are listed in alphabetical order in the FreeBasic Manual.

You can find out what each FreeBasic command does and how to use it.

For example the DIM command  is here.

The Dim command declares a variable by name and reserves memory to accommodate it.
The wiki page shows you the syntax (how the command can be used) followed up with examples.
The Dim command applies to ARRAYS as well. If you are new to programming, you might be wondering what the heck and ARRAY is. Continue reading the Dim command wiki page and you can find a link to Arrays Overview.

The people who helped put FreeBasic's documentation together did a very good job. The documentation along with the forum and community are excelent resources. And of course, you are alway welcome to call and talk to me with any freebasic questions.



scripts for use in fbcadcam's macro system is about doing things programmatically (automatically rather then manually)

Drawing Programmatically. A simple example: Copy and paste the code below and run the macro

'----------------------------------------------------------

'Draw a LINE
Line(0,0)-(400,300)

'Draw Circles, Arcs, Ellipses and Elliptical Arcs
'circle (x,y),major_radius,minor_radius,arc_start_degrees,arc_end_degrees,rotation_degrees

'Draw a CIRCLE
circle(250,250),50

'Draw an ARC
circle(250,250),70,,15,185

'Draw an ELLIPSE
circle(250,250),120,80,,,35

'Draw an ELLIPTICAL ARC
circle(250,250),200,140,30,300,55

'----------------------------------------------------------



Drawing Programmatically. Using variables example: Copy and paste the code below and run the macro

'----------------------------------------------------------

Dim As Integer i,j,k,c,x,y
Dim As Double center_x,center_y,radius,angle,rot
Dim As Double pi

pi = 4 * Atn(1)
center_x=200
center_y=200
radius=100
Circle (center_x,center_y),radius
c=10
angle=360/c
For i=0 To c-1
    rot=i*angle
    x=center_x+cos(rot*pi/180)*radius
    y=center_y+sin(rot*pi/180)*radius
    Circle(x,y),20
Next

'----------------------------------------------------------