[go: up one dir, main page]

0% found this document useful (0 votes)
365 views85 pages

Introduction To API 2024.1

The document provides an introduction to the ALPHACAM 2024.1 API, detailing copyright information, system requirements, and resources for support. It explains the use of Visual Basic for Applications (VBA) for creating custom macros within ALPHACAM, including interface layout and coding structure. The guide aims to familiarize users with the API to enhance their design and manufacturing processes using ALPHACAM software.

Uploaded by

prog.r
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
365 views85 pages

Introduction To API 2024.1

The document provides an introduction to the ALPHACAM 2024.1 API, detailing copyright information, system requirements, and resources for support. It explains the use of Visual Basic for Applications (VBA) for creating custom macros within ALPHACAM, including interface layout and coding structure. The guide aims to familiarize users with the API to enhance their design and manufacturing processes using ALPHACAM software.

Uploaded by

prog.r
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 85

ALPHACAM 2024.

INTRODUCTION TO API
Copyright

Copyright © 2024 Hexagon AB and/or its subsidiaries and affiliates. All rights reserved.

Any copyright or other intellectual property right of whatever nature which subsists or may subsist in the
presentation and/or content of the programs (including without limitation its look, feel, visual or other non-literal
elements) remains the property of Hexagon AB and/or its subsidiaries and affiliates or its licensor(s) absolutely.

No part of this publication may be reproduced, transmitted, transcribed, stored in a retrieval system or translated
into any language, in any form or by any means, electronic, mechanical, optical, chemical, manual or otherwise,
without the express written permission of Hexagon AB and/or its subsidiaries and affiliates.

Unauthorised reproduction or distribution of these programs or any part thereof is unlawful and may result in
civil or criminal penalties.

Windows is a trademark of Microsoft Corporation.

All product names mentioned in this publication, and not listed above, are acknowledged as the trademarks of
the respective manufacturers and producers of such products.

Hexagon AB and/or its subsidiaries and affiliates makes no representations or warranties with respect to the
contents hereof and specifically disclaim any implied warranties of satisfactory quality or fitness for any
particular purpose. Further, Hexagon AB and/or its subsidiaries and affiliates reserves the right to revise this
publication and to make changes in the contents hereof without obligation to notify any person of such changes
or revisions.

The information contained within this document is subject to change without notice and does not represent a
commitment on the part of the vendor. The software described in this document is furnished under a licence
agreement and may be used or copied only in accordance with the terms of the agreement.
Contents
Copyright ..................................................................................................................................... i

Conventions used in this manual............................................................................................... v

Recommended Operating Systems and Hardware for ALPHACAM ..................................... vii


Supported Operating Systems ................................................................................................. vii
ALPHACAM Minimum Specifications ....................................................................................... vii

Hexagon Customer Portal ........................................................................................................ viii

ALPHACAM esupport ................................................................................................................. ix

ALPHACAM Wiki .......................................................................................................................... x

Introduction .................................................................................................................................. 1

VBA. What is it? ........................................................................................................................... 2


Event Driven ............................................................................................................................... 2
Object based .............................................................................................................................. 2

ALPHACAM API interface ........................................................................................................... 3


Interface layout ........................................................................................................................... 4
Project Layout............................................................................................................................. 5
Coding Layout ............................................................................................................................ 5
Sub .......................................................................................................................................... 5
Function .................................................................................................................................. 5
Public ...................................................................................................................................... 5
Private ..................................................................................................................................... 5
Data Type ................................................................................................................................... 6
Byte ......................................................................................................................................... 6
Boolean ................................................................................................................................... 6
Integer ..................................................................................................................................... 6
Long ........................................................................................................................................ 6
Single ...................................................................................................................................... 6
Double ..................................................................................................................................... 6
Currency.................................................................................................................................. 6
Decimal ................................................................................................................................... 6
Date......................................................................................................................................... 7

Introduction to API i
Object ...................................................................................................................................... 7
String ....................................................................................................................................... 7
String ....................................................................................................................................... 7
Variant ..................................................................................................................................... 7
Variant ..................................................................................................................................... 7
User Defined ........................................................................................................................... 7

Message Box Example ................................................................................................................ 8


Inserting a Module ...................................................................................................................... 9
Rename the Project .................................................................................................................. 10
Option Explicit........................................................................................................................... 11
Simple Message Code ............................................................................................................. 12

Tutored Door Example .............................................................................................................. 16


Create Main Module ................................................................................................................. 17
Create the code sub section ..................................................................................................... 18
Item Declarations...................................................................................................................... 18
Variable prefixes ................................................................................................................... 18
Using the Dim statement ....................................................................................................... 19
Creating the Outside rectangle ................................................................................................. 21
Run the code ............................................................................................................................ 22
Preventing multiple common rectangles .................................................................................. 24
Bring it all into view ................................................................................................................... 24
Creating a variable Outer rectangle ......................................................................................... 25
Adding the new variables ...................................................................................................... 25
Adding values for the variables ............................................................................................. 26
Creating the Inner form............................................................................................................. 27
Create the new variables ...................................................................................................... 28
Create a new 2D object ........................................................................................................ 29
Naming the inner form .......................................................................................................... 29
Drawing the Inner form ......................................................................................................... 29
Central Slat design detail.......................................................................................................... 32
Create the new variables ...................................................................................................... 32
Calculate the position of the Lines ........................................................................................ 34
Line coding ............................................................................................................................ 34

Introduction to API ii
For/Next Loop explained ....................................................................................................... 35
Draw the line ......................................................................................................................... 35
Manipulating the drawn items ................................................................................................... 36
Create the new variables ...................................................................................................... 37
Create Collections ................................................................................................................. 37
Break Using Cutting Geometries .......................................................................................... 38
Delete the unwanted lines ..................................................................................................... 39
Considerations for Manufacture ............................................................................................... 42
Reversing the directions of alternate slat lines ..................................................................... 43
Setting the correct Tool Side................................................................................................. 45
Setting Start Points for the Inside design .............................................................................. 45
New Variables for PointAtFractL and SetStartPoint ............................................................. 46
Setting Start Points for the Outer Rectangle ......................................................................... 46
Working with Z levels................................................................................................................ 48
Attributes ............................................................................................................................... 48
New Variables for Attributes ................................................................................................. 49
Assigning the new values ..................................................................................................... 49
Machining ................................................................................................................................. 51
Create the Sub ...................................................................................................................... 51
Declare the variables ............................................................................................................ 51
Select the items to machine .................................................................................................. 52
Apply the machining cycle .................................................................................................... 52
Call the Sub for the Slat lines................................................................................................ 53
Call the Sub for the Inside geometries .................................................................................. 54
Call the Sub for the Outside rectangle .................................................................................. 55
Adding a Material for Simulation ........................................................................................... 55
Alter the viewing perspective ................................................................................................ 56

Conclusion so far ....................................................................................................................... 57

User Forms ................................................................................................................................. 58


Import the required files ............................................................................................................ 58
Form Design Basics ................................................................................................................. 60
Initial Imported Form Design .................................................................................................... 62
Structure................................................................................................................................ 63

Introduction to API iii


Termination Code.................................................................................................................. 65
Initial Settings Code .............................................................................................................. 66
When you click OK code ....................................................................................................... 67
Tidy Up the Values code ....................................................................................................... 68
Make the Form visible .............................................................................................................. 69

Adding to the ALPHACAM Interface ........................................................................................ 70

Conclusion.................................................................................................................................. 71

Additional Examples .................................................................................................................. 71

Introduction to API iv
Conventions used in this manual
To enable you to use the information in this guide effectively, you need to understand the conventions used in
the guide to represent differing types of information.

• Buttons on the screen are represented as the button text in square brackets.
For example: Click on [OK].

• Keys on the keyboard are represented as bold lettering in between < > characters.
For example: Press <Enter>.

• Ribbon Tab options are represented as a path with the Ribbon Tab in UPPER case with sub menus Capitalised
and separated with an arrow
For example: Select FILE > Open.

• Field names are represented as bold text. And the value to be entered will be represented by Bold Text.
For example: Enter the value 50 in the Offset field. or when prompted for the X & Y values type 100,50 <Enter>

Denotes a <LClick> or Primary Mouse Button Click.

Denotes a <RClick> or Secondary Mouse Button Click.

This is a note. It contains useful or additional information.

This is a reference. It directs you to another part of the user guide.

This is a thought box. It is generally used in exercises and contains a question for
you to consider.

This is a highlighted note to emphasise information.

This is a warning; it contains information that you must not ignore.

This is a tip. It is generally used in exercises and offers further advice.

Introduction to API v
This is the first line of a number list item
This is the second item of the numbered instructions, which you must
Follow in sequence.

• This is a list

• of items, in which

• The order is not important.

Introduction to API vi
Recommended Operating Systems and
Hardware for ALPHACAM
Supported Operating Systems

• 64bit operating systems.

• Windows 10 and Windows 11 Professional and Enterprise.

• Nvidia or ATI Open GL Graphics Card with 1Gb dedicated memory

We recommend you keep up to date with the latest Software Updates for the
supported operating systems and drivers for your hardware base.

Any Windows Operating system (OS) prior to and including Windows 8.1, are not a
supported operating system.

ALPHACAM Minimum Specifications

The latest minimum specification can be found at:


hexagon.com/products/product-groups/computer-aided-manufacturing-cad-cam-
software/alphacam/system-requirements

This minimum specification is to run any ALPHACAM basic system.

You are advised to increase the specification if you are:

• Wishing to produce files using the Automation Manager system.


• Working with solid models.
• Producing the NC code for 3D machining and 3, 4, or 5 axis simultaneous machining strategies.

Your minimum specifications should be the fastest processor with the most memory and the highest
specification video card that your budget will allow.

If using Autodesk Inventor Files, please check the current Inventor Apprentice Server
requirements at Inventor Apprentice Server

Introduction to API vii


Hexagon Customer Portal
At Hexagon, we strive to provide you and your business with first class technical support and services. The
Hexagon Customer Support Portal (HCP) allows you the tools you need to receive the best from your
software. In addition to generating new and updating existing support cases, the portal allows you:

• Unlimited user logins for your company.

• Access to all your licenses for easy reference.

• Get the latest releases and software update at the touch of a button.

• View what is available on your support and maintenance schedule.

• Reference to the Customer Support Charter at any time.

• View the status of your Technical Support cases.

• View all purchased Professional Services like Training and Consultancy.

For the Hexagon Customer Portal visit customers.ps.hexagonmi.com

Introduction to API viii


ALPHACAM esupport
Another location to gain valuable information about using the software or asking other experienced users for
assistance are the esupport forums.

Asking a question of the community, using the knowledge base or other available information links could save
you time if you have a problem that someone else may already have supplied a solution for.

For the Nexus Community pages please visit Nexus Community Home

Introduction to API ix
ALPHACAM Wiki
Another location to gain valuable information about using the software or asking other experienced users for
assistance is the ALPHACAM Wiki

The ALPHACAM Wiki is an ever expanding knowledge base where you will find all manner of information
relating to many areas of the ALPHACAM software titles.

Including, but not limited to, specific information about the commands in ALPHACAM, tutorial videos to assist
in your day to day use of the software.

Introduction to API x
Introduction
With any design and manufacturing system such as ALPHACAM, there soon comes a time when you feel that
you need some form of customisation to perform the drawing functions or application of machining to speed up
the processes.

As with many software packages, ALPHACAM has an inbuilt interface which allows you to access the ability to
create macro functions using the VBA programming language.
This interface is the Application Programming Interface or API.

Using the API within ALPHACAM allows you to create code based drawing tools which, when presented in an
easy to use format, can allow you to enter a simple set of values based on your requirements which can then
perform complex drawing and toolpath application processes, saving you the time taken to draw and machine
a part.

The aim of this course is to introduce you to the VBA environment within ALPHACAM and to give you an
insight of the power available once you start to understand the fundamentals.
We are not going to turn you into API wizards but this course will allow you to practice on a simple example
that can be amended to suit your own needs, to then give you the confidence to progress to more complex
VBA creations.

To give you an understanding of how powerful this method of programming applications can be, in the design
sector software titles such as Solidworks and Inventor use API to allow ease of functionality. Probably the
biggest office application using API programming is Excel.
Even Excel pales into the background when compared to the largest user of API programming, the Windows
operating system which you are using at present to take this course.

This course is designed to suit the newcomer to the VBA but not a newcomer to ALPHACAM.
A comprehensive knowledge of how to use ALPHACAM and an understanding of what it is that you need to
achieve is required, this is so you can work with the various commands within the API interface and
understand what you are writing in the code and what it is supposed to create once the macro is in use.

Unlike normal drawing and toolpath creation in the normal ALPHACAM environment, where you can pick and
choose methods via the many differing command icons, when creating a process in VBA, you need to have a
specific goal in mind to allow you to structure the language commands correctly.

To use any of the VBA creation options, you must have the xAPI multiplier on your
installed ALPHACAM licence

Introduction to API 1
VBA. What is it?
Visual Basic for Applications or VBA is what is a programming language that can achieve many differing
results depending on the path you take.

It is known as either of the following types of language;

Event Driven
This is where something must happen, before something else happens.

For example, as you are reading this document, the page remains static until you press the Page Up or Page
Down keys or roll the mouse wheel to read on further.

Both of those are known as Events which trigger actions.

In some instances, you may have created a dialogue for entering data, at the bottom you would perhaps have
an OK and Cancel or Finish button, each of these could have coding assigned to them so the when they are
clicked and event takes place.

Click OK and the data is actioned, click Cancel and the dialogue closes without actioning, these are events.

Object based
Everything that is referenced within the API to create code can be thought of as an Object.

A circle is an object, so would a rectangle or line. Any of these objects can then have attributes linked to them
to allow them to be manipulated. Using the circle as an example, it would have its size as an attribute and its
position.

These attributes can then have things done to them such as Move, Copy Scale etc. which are referred to as
Methods.

Introduction to API 2
ALPHACAM API interface
To use the API interface in ALPHACAM, you must have the xAPI module licences of the software.

Using ADD-INS / Macros > VBA Editor will open the API interface and allow you to start to create
your new project.

Once you have written your first project, you may wish to edit them, note though, from the API interface, you
are not able to directly open a project.

You must instead us the command ADD-INS / Macros > Open VBA Project

Introduction to API 3
Interface layout

The interface is made up of five distinct sections.

The Project window listing all available projects within the ALPHACAM
Section 1 environment.

Section 2 The title of the current working Project.

The Properties window displaying the current selected Object held in the
Section 3 coding window.

The Coding window where all your main writing will take place to create
Section 4 your Project

The Immediate window which displays useful information about what the
Section 5 current value of a variable may be. A good place to work with when fault
finding.

Introduction to API 4
Project Layout

As with the layout of the main interface, Projects themselves can also be broken into separate section which
allows you to control what will happen within your Project much easier.

As you can see from the image above, this example project has two code sections contained within the Module
folder, these two sections contain various code elements that are called on as and when needed for the
modUtils section with the Post section being the primary running code structure of the Project.

You can break the coding down into various sections, but this is a much more advanced method of coding than
what we will be looking at within this course.

Though we will look at some simple methods of structure, namely UserForms, which can make working with
your coded sections easier from the final user’s perspective.

Coding Layout

When you work with VBA coding, there are certain aspects to consider when writing the code, what type of
code are you wanting to create, and which types of data are you trying to work with.

Coding types fall into a few different categories and are described below;

A section of the main coding that performs the task required. This may be as simple as
Sub creating a circle, or as complex as creating an entire drawing with added tool paths.

A section of code which supplies a specific value for use within a sub. This can be used to hold
coding which will be used over again to do calculations for positions of objects within the main
Function
coding.

A Public declaration of a Sub or Function will allow access to the section of code from
Public anywhere within the entire Project.

A Private declaration of Sub or Function will only allow access to that section of coding from
Private within the module where the Private section is written.

Introduction to API 5
Data Type

When creating your Project, you will need to create, manipulate and store different types of values or data. The
types of data you can use are listed below, the list may appear a little confusing, but the important items that
we will be working with have the  symbol set beside them.

Data Type Storage Size Range

1 Byte. 0 to 255
Byte

Boolean  2 Bytes. True or False

Integer  2 Bytes. -32,768 to 32,767

Long  4 Bytes. -2,147,438,648 to 2,147,483,647


(long integer)

Single -3.102823 e38 to -1.401298 e-45 for negative values.


4 Bytes.
1.401298 e-45 to 3.402823 e38 for positive values.
(single-precision
floating point)

-1.79769313486231 e308 to -4.94065645841247 e-324 for


Double
negative values.
(double-  8 Bytes.
4.94065645841247 e-324 to 1.79769313486232 e308 for
precision positive values.
floating point)

Currency 8 Bytes. -922,337,203,685,477.5808 to 922,337,203,685,477.5807


(scaled integer)

±79,228,162,514,264,337,593,543,950,335 with no decimal


point.

±7.9228162514264337593543950335 with 28 places to the


14 Bytes.
Decimal right of the decimal.

Smallest non-zero number is


±0.0000000000000000000000000001

Introduction to API 6
Data Type Storage Size Range

8 Bytes. January 1, 100 to December 31, 9999


Date

Object  4 Bytes. Any Object reference

String 10 Bytes + String Length. 0 to approximately 2 billion


(variable length)

String  Length of String. 1 to approximately 65,400


(fixed length)

Any numeric value up to the range of a


Variant 16 Bytes.
Double
(with numbers)

Variant 22 Bytes + String Length. Same range as for variable-length String


(with characters)

The range of each element is the same as


User Defined Number required by elements.
the range of its data type.
(using Type)

Introduction to API 7
Message Box Example
In ALPHACAM, using the ADD INS/MACROS > New VBA Project

This will open the VBA interface.

From the Project listing window, scroll down and locate the VBAProject## (the ## represents the number of
the project in the listing and will vary from session to session).

Introduction to API 8
Inserting a Module

To be able to write code for this project we must create the sections in which the code will reside.
This can be achieved in one of two ways;

Using the <RClick> context menu on the


VBA Project in question, then Inserting the
required coding section to Project.

Using the drop down menu bar and from the Insert options,
select the required coding section for the Project.

Using either of these methods, Insert a Module to the current Project.

Introduction to API 9
Rename the Project

Whilst you may wish to leave the name as generated for this training example, it will prove more beneficial in
the future, to rename your projects to suit the practical application.

There is no option on the right click context menu to rename a Project, this must be done via the naming
window on the interface.

In the section highlighted in the image above, alter the name to suit your project.

Once you <LClick> anywhere outside of this line, then new name will be registered to the Project, and
the actual project will move up or down the listing tree depending on the alphabet order of the name.

Note that the name of Projects cannot include spaces or special characters.

Introduction to API 10
Option Explicit
Option Explicit is a heading that will appear at the top of your first section of coding if you have it as an active
setting.

This specific command informs the processing behind the coding, or the compiler, that every variable or
constant that needs to be used during the processing of the code is stated at the very beginning. This makes
the process of typing in variable or constant names easier due to the predictive nature of the coding window,
but it also means that you must go all the way to the top of the coding to add new variables should you need
to.

If your module did not open with the Option Explicit statement, then you will need to turn it on.
Using the drop-down Tools menu, access the Options.

On the Editor tab, ensure that the  Require Variable Declaration option is active.

Introduction to API 11
Simple Message Code
This piece of code which needs to be entered in the coding window will create a sample message that would
appear during a request for information or if a warning needs to be displayed for an error or other piece of user
information.

In the coding window, enter the following without the quote marks below the Option Explicit entry;

“sub MyMessageBox”

You do not need to enter the word “sub” with a capital ‘S’ the system knows this command word and
automatically sets the case correctly.

You do not need to enter the “End Sub” command, again, the system knows to do this.

The brackets are automatically entered as well, these are used in more complex programming sub sections to
allow for specific information to be passed around the entire project.

What you must remember is the naming convention, in the same manner as the actual project name, spaces
are not permitted in sub section names.

During the whole process of coding, if you do enter incorrect information the system will highlight the error for
your attention.

Introduction to API 12
The next line of code will generate the actual message box we need to see.

Typing “msgbox” (again without the quotes) then pressing the space bar will display this in the coding
window.

When you enter lines of code, if there are options or specific formats that can be applied, the VBA system will
show you in an information line, this can help the new coder to understand where a mistake has happened, or
if you need to apply any additional information to assist the user.

The text within the brackets is what will be actioned for the dialogue, the text in the quote marks will be
displayed in the ALPHACAM environment once we have saved and run the code.

Save your project using the FILE > Save command

A project cannot be run until it is saved.

If you make changes to a project and then close the editor, those changes are live
and the project will be saved. Closing the editor without using Save still applies the save
status.

Introduction to API 13
Depending on the use of the project, there may be a need for it to be saved in a specific location, for this
example file we can save to the default “…. LICOMDIR / VBMacros” folder.

It is worth noting that the file extension for all created macros in ALPHACAM will be in the same format as the
actual module of ALPHACAM in use.

“MyFirstProject.a*b”, where the ‘*’ symbol is replaced by the letter representing the module in use, r for
Router, m for Mill, s for Stone etc.

Use the Run command to action the code you have written.

Initial message box viewed in ALPHACAM.

Introduction to API 14
To add a little more functionality and information, the code could have been entered slightly differently.

Perhaps there could be the need for a different button layout, maybe you could add a suitable title to the
message box for more information.

Edit the line of code so that it appears as this image.

In this line of code, we will achieve the following dialogue box.

The code line is now set up to a predetermined format for the msgbox command.

• The Prompt – “Hello World”

• Button options - vbOKCancel

• Message Box Title – “My First Message Box”

Each of the required sections are separated by a comma, and if a section is not added, it is ignored
completely.

For example, in the original line of code, omitting a specific title for this message box displayed ALPHACAM
as the title.

Introduction to API 15
Tutored Door Example
In this main example, we will examine in detail the options required to create the following drawing in
ALPHACAM.

The code we will need initially will be to create the outer rectangle of the door, the central arched pattern, and
the slat details for the design.

Initially the code will be written for a fixed size to ensure a complete understanding of the process, then the
saved coding will be altered to suit a variable method of geometry creation.

Sometimes it may prove more beneficial to create a simple drawing or function to prove out the concept, then
edit the code to suit sections which need to be more dynamic.

Adjusting single lines or sections of coding will also allow for any error correction rather than trying, at first, to
write the complete correct process, which may include errors in the coding that could be generated by earlier
coding errors.

Introduction to API 16
Create Main Module

In ALPHACAM, using the ADD INS/MACROS > New VBA Project

From the list of projects find the new VBAProject## entry and as in the previous example, use the Project
Title box to give this project a new name.

Locate the renamed project on your list of Projects, then use the Insert option, either <RClick> on the
Project or use the drop-down menu option, to Insert a new Module.

Finally, to create a basic structure, rename the module, using the same Title bar section, to “Code”.

Giving modules dedicated names allows you to easily navigate to the correct item should you need to edit, but
also it gives structure to the coding with names that suit specific areas of work.

Introduction to API 17
Create the code sub section
Underneath the Option Explicit statement, type in “sub Main” (without the quotes) to create the main sub
section which will contain all the required code to create the geometries for the door.

Item Declarations

Now we have an area in which to write the code, we need to inform the system of the types of variables we will
be using inside the code, so that the predictive elements of the text entry understand which options to make
available to you during the writing of the code.

Variable prefixes

To also allow for easier understanding of each variable in use, a prefix is used to identify each type of variable.

In the list below are some of the prefixes which will be used in this tutorial, though you are not limited to or
required to use them depending on your own programming style, it can prove beneficial when debugging the
code.

Data Type Prefix Example

Boolean bln blnIsValid


Date (and Time) dt dtStart
Double dbl dblScale
Integer int intCounter
Long lng lngHighCounter
Object o oCustomer
String str strAttribute1
Drawing drw drwTemp

Introduction to API 18
Using the Dim statement

All variables used in your code are identified using the Dim statement.
This command code declares the name of your variable and of what type it is to be used as.
A good naming convention to adopt is a meaningful one, use a Capital letter to identify the actual name of the
variable after the prefix identifier.

Enter the line of text as shown below.

On the system code words, if you forget to use a capital letter, it will be adjusted, as seen in the finished line
complete image.

However, ensure that your actual variable name is entered correctly, format is important.

Note as you enter the first letter after the ‘as’ word a predictive drop down list appears, making entering the
code a little easier and removing the problem of spelling mistakes.

Locate and <LClick> on the required option, then pressing the <SpaceBar> will enter the code directly to
your listing, saving you the job of typing.

Introduction to API 19
After adding the correct entry, press <Enter> to complete the line, notice that the ‘dim’ statement is then case
corrected.

A second Dim statement is required to allow us to set up different names for different parts of the drawing, this
allows you to manipulate the result easier once the function of the coding becomes more complex.

The rectangle defining the outside of the door is referred to as a ‘Path’ or a type of object that you can use to
apply tool paths to.

Creating the second Dim statement informs the system that you have a specific named item and it has a
definite use.

Introduction to API 20
Creating the Outside rectangle
The next lines of code will draw the rectangle shape for us, though we need to inform the code where it is to
create the rectangle.

Add in a blank line to separate the code sections, then use the <Tab > key to step in from the edge of your
current coding.
Using a stepped format, plus having blank lines to separate sections makes it easier to follow the code
structure.

The line Set oDrw = App.ActiveDrawing tells the code that it will be writing into the current open session of
ALPHACAM.

Adding the line Set oOutside = oDrw.CreateRectangle(0, 0, 400, 650) 'Draw outer rectangle is the actual
command that will draw our outside shape.

The structure of this command is the same as the Rectangle command in ALPHACAM.
The values in the brackets state the first corner X, Y position and then the X,Y second corner position.

After the bracket is the optional ‘Draw outer rectangle remark, adding remarks allows you to place relevant
information about what individual lines or sections of your code is doing, anything after the single quote mark is
an information statement.

Save your current project as DoorExample in “…. LICOMDIR / VBMacros”

Introduction to API 21
Run the code
Using any of the following options, RUN > Run Sub/User Form, the <F5> key or the triangle symbol from the
Run button bar

Depending on how you have coded or what subs are available, you may encounter this dialogue.

In this instance, we only have the single item to work with, so <LClick> on [Run].

The API interface and the ALPHACAM drawing environment are independent of each other so you can see
what has been drawn using the [Run] command, whilst you are coding.

The Undo command in ALPHACAM will allow you to step back as well to see if there are any problems in the
drawing window.

Introduction to API 22
Run the macro code once more, or as many times as you wish to <LClick> on the [Run] option.

Multiple runs of the current code will produce more and more rectangles in the same location.

Introduction to API 23
Preventing multiple common rectangles
To prevent the code from generating multiple instances of the final product, we could inform the user to only
run the macro once, but this would be too risky.
A neater solution is to have the code written correctly in the first instance.

The line App.New is the same as FILE > New and instructs the code to begin a new drawing each time the
code is run.

So, adding that one simple line of code will prevent multiple instances of our geometry from being created.

Bring it all into view


You will see that each time we run the macro we only see a small section of the drawing.

To bring the whole item into view, we can add a single line of code to use the Zoom All functionality.
Simply adding the command oDrw.ZoomAll at the end of the section performs this.

Introduction to API 24
Creating a variable Outer rectangle
Whilst the code we have written draws a rectangle, it is of a fixed size because that is what we coded, 0,0 to
450,600.
That is fine if you always create this size of part, but what about variations on a theme.

To allow for changes in size we now need to add in specific variables with suitable names to identify which part
of the drawing they apply to.
Naming conventions are not cast in stone but giving your variable names that apply to what they do will make
things easier to understand as you become more practiced in writing complex coding.

Adding the new variables

We will edit the code we have written now to include two new variables, using a naming convention as listed
earlier.

Add in the two lines of code as shown above.

Using the Public statement and placing these values in the Option Explicit section means that any Sub we
create can use the two new variables dblWidth and dblHeight plus the room for error has reduced as the
predictive nature of the coding text input can now read these items.

Introduction to API 25
Adding values for the variables

Just adding the two new variables is not enough, we need to inform the coding of the values we wish to work
with.

In the current coding list, between the Dim statements and the App.New statement, add the two lines as
shown below.

These will set the sizes of the rectangle for us once we edit the last section of the code as shown below.

Making the second corner X, Y locations into the variable names allows you to now change the two sizes to
create different rectangles, but still just using the same single rectangle statement.

At present, for ease of coding, we will be adjusting the values in the Sub, however, further on in this tutorial we
will look at a much neater method of allowing the user to perform this function.

Save your current project as DoorExample in “…. LICOMDIR / VBMacros”

Introduction to API 26
Creating the Inner form
The second set of geometry that is required is the arched inner form.
This geometry will need to be placed correctly to set locations.

Using the above drawing as a guide, the two side distances, bottom offset distance and the top of the arch are
all positioned using the value we will give to a variable called Stile.

The size of the Arch will be created using a variable called ArchHeight.

Whilst it is entirely practical to have differing variables for the top and
bottom offset values, for ease of learning we will keep it set to a simple
single variable.

Introduction to API 27
Create the new variables
In the Option Explicit section, add the dblStile and dblArchHeight lines as shown below.

Using the Public statement and placing these values in the Option Explicit section means that any Sub we
create can use the new variables, plus the room for error has reduced as the predictive nature of the coding
text input can now read these items.

Add the indicated lines as well, to give the variables a value.

Introduction to API 28
Create a new 2D object
The way in which the inner geometry is created is using three Line statements and an Arc statement, just as
you would draw this manually, these items are all individual elements.
Adding the following ‘Dim oGeo2D as Geo2D’ allows us to use a single object to manipulate the items later.

Naming the inner form


Finally, in the same way that we assigned a specific name to the outer rectangle, we need to do the same for
the inner form.

Drawing the Inner form


To allow for ease of manufacture later, this inner form is drawn in a specific manner so that we can identify set
locations to apply toolpaths later, there is no right or wrong method at this stage, so long as the form is correct
and when altering the values, the form changes shape to suit.

The inner form is drawn from its bottom right hand corner and progresses in an anti-clockwise direction.

The format of the coding uses a command to set the start point, oDrw.Create2DGeometry.
Then uses the following two commands;

• oGeo2D.AddLine

• oGeo2D.AddArc2Point

in their required order to give the code the correct information to draw the shape.
In the same manner that you would use a Line or Arc command in ALPHACAM, the structure follows a similar
form;

• oDrw.Create2DGeometry (X start value, Y start value)

• oGeo2D.AddLine X end value, Y end value

• oGeo2D.AddArc2Point X second value, Y second value, X end value, Y end value

With this example, we will also be using simple maths to work out the correct positions based on the variables
and how they work with each other.

Introduction to API 29
Enter a couple of blank lines below the ‘Set oOutside =….’ line to make your coding easier to read.

Create the following two lines.

A simple remark statement to tell you what is happening followed by the line that defines the starting location
of the shape.

Set oGeo2D = oDrw.Create2DGeometry (dblWidth – dblStile, dblStile)

The calculations in the brackets set the start point for the shape to be drawn.
Width of the full shape subtracting the Stile amount for the X start location, then the Stile amount as the Y
start location.

The first .AddLine command takes the shape from the previous point to the start point of the arch.

The .AddArc2Point command states the mid point of the arc with the X value being half the full door width and
the Y value being the full height subtracting the Stile value.
Then the end point of the arc using the Stile value for X and calculating the Y value to the correct position.

The left line down the side is a simple statement of the Stile value for X and Y

Introduction to API 30
The line across the bottom of the inner form is a repeat of the start point location.

Finally, we must make sure that the system understands that this is a complete entity and allow it to be drawn.

Using the Set oInside = oGeo2D.CloseAndFinishLine line achieves this. The line instructs the code to place
all the elements that go to make the shape drawn as a single shape and assigns the name oInside to that
shape.

Save your current project as DoorExample in “…. LICOMDIR / VBMacros”

Then using your preferred run command, check to make sure that your coding is correct.

Introduction to API 31
Central Slat design detail
To finish off the design stage of the macro, we now need to add in the required code that will draw the lines in
the central section to represent a slat style of design.

This section of the code will allow us to first work out via a variable, approximately how many lines are required
on the design.

Then because the design itself is variable, we will need to work out exactly how far apart these lines need to
be to give the finished design.

Finally, we will remove sections of the drawing which are not required to give us the completed design, ready
for machining.

Create the new variables


In the Option Explicit section, add the ApproxGap line as shown.

Introduction to API 32
Add the following lines as well, these are new variables required to create the lines for the Slats correctly, a full
explanation of what they are for or do will be listed as they are applied within the code.

These variables are added into the current Sub as we are only using them within this section of the coding.
Lastly add in the variable value to allow the calculations to be performed.

These new variables have been added to the listing in the order that they
will be used, but this is not to say that they must appear in any order.

You may eventually choose to place all variables of the same type together
to make it easier to read.

Introduction to API 33
Calculate the position of the Lines
The first section of code to add calculates firstly how many slats will be required based on the approximate gap
we have assigned.
Then, using this calculation, to work out the exact distance needed between each line.

Variable intSlatN takes the calculated width of the central section and divides this figure by our applied
approximate gap between the lines.

Variable dblActualGap now reworks the calculation by dividing the central width value by the number of lines
that will fit to give the exact gap between the lines.

Line coding
The next section of code introduces you to the concept of repeating sections of code without having to write
the same sections of code repeatedly.

Using the following For / Next loop structure, allows us to repeat the line drawing section for as many or as
few lines that are required for the design, remember, as the design width alters, so will the number of lines.

Below is the required coding.

Introduction to API 34
For/Next Loop explained
So, an explanation of the structure of the code we have just written.

• For intN = 1 to intSlatN – 1

The opening line of the loop sets the counter to start at 1, then until the value assigned to intSlatN minus 1 is
reached, continue doing all the code between this line and

• Next intN

The reason for the ‘minus 1’ statement is that without it we would draw a line over the actual side of the
central section.
Where we need to stop is one step over before the actual central profile vertical side.

Draw the line


The calculations for the actual line drawing are very simple once looked at in detail.

Set oLine = oDrw.Create2DLine (dblStile + intN * dblActualGap, 0, dblStile + intN * dblActualGap,


dblHeight)

We have used the .Create2DLine command earlier so all we are concerned when drawing a line is the start
point and the end point.

The start value is calculated as

• X - the Stile value plus the count value in intN multiplied by the ActualGap value. Using standard
mathematical ordering, the multiplication section is performed first, then this value is added to the value held in
Stile.

• Y is set to zero to start the line at the very bottom of the drawing.

The end value keeps the X value the same but sets the Y value to be the full Height of the actual design.

Consider this when looking at the next section, if you were to apply a calculation to
place the Y Start value in the correct location for the design, then some of the following
section would be worked on differently.

Introduction to API 35
Manipulating the drawn items

As you can see from the above image, the lines have been drawn as we have coded, but now we can see
there are areas where we do not need the lines when compared to the actual final design.

The sections between the central design and outer rectangle need to be removed.

If you were drawing this design in ALPHACAM, the next process you would carry out would be to trim the outer
sections of the vertical lines so that the only remaining section is the central bounded lines.

This process can also be written to the code but an understanding of how the lines are treated is required.

As we drew the lines, they started at Y0, so now a complete line is treated as a member of the oLine
statement.

In this example, we will employ the Break command and the option Use Cutting Geometries, once this
command has been actioned the lines will be split into three sections;

1. From the start point to the first breaking geometry will now be classed as the oLine section,

2. The other sections are now classified as Remaining and depending on how many sections the geometry has
been split into, the Remain sections are then assigned a rising number to identify each section.

In our example, once we break all the lines, we will be left with a Lines section, a Remains (1) section and a
Remains (2) section.

Introduction to API 36
Create the new variables
Add the following lines to your variable listing in the actual Sub. These will be used to identify and control the
lines once broken.

Create Collections
A Collection can be thought of in the terms of a group, it is an object that contains a set of related objects.
Using Collections is a good way of manipulation similar items and makes processing the code easier.
To make working with the Slat lines easier we will need to create two Collections, one for the Lines
themselves, and another for the parts that Remain, once we have broken the geometries.

The following two lines of code set up the collection statements.

The two lines are placed before the start of the Loop section so that as the code for each line is run, depending
on how many lines are needed, they are added to the collections depending on how they have been affected
by the Break command which will be added to the loop.

Introduction to API 37
Break Using Cutting Geometries
The process used in ALPHACAM would be to select the Break command, set the  Use Cutting Geometries
active, select the geometries to perform the Break with, then Delete the items not required.

The coding works the opposite way by selecting the geometry to break with first, then invoking the Break
command.

Adding the oInside.Selected = True line immediately after the drawing command, selects the shape called
oInside and will use this as the cutting geometry.

The Set oRemains = oLine.BreakWithCuttingGeos is used to perform two functions, first the drawn Line is
broken using the previously selected Inside shape, then those broken geometries are placed into the
Collection defined as Remains.

Introduction to API 38
Delete the unwanted lines
The next part of the coding will remove the unwanted sections of the vertical lines, but a little thought needs to
be applied when working with multiple section elements which the Lines now are.

Firstly, the naming convention has adjusted itself due to the line having been broken.
What was a line from the bottom to the top, or more correctly, from the Start point to the Finish point, is now
in three pieces.

The only piece that is still named Line is the section from the original Start point to the breaking geometry, the
other two sections are now renamed to the Remains collections and have an identifier added to them.

With the ghost tools on it is easy to see in the above image how the lines are now identified after the Break
command has been actioned.

Whenever you are working with items in this manner, remember that the
original name will only be applied from the Start point of the generated
geometry, in some cases you may need to think about how to draw an item
to suit manipulation via code first, rather than coding it to draw it as you
would normally in ALPHACAM.

In this example we have tried to keep things simple so that we can explain the workings of the differing
commands, but consider on the line you have just created, you could have taken the command;

Set oLine = oDrw.Create2DLine (dblStile + intN * dblActualGap, 0, dblStile + intN * dblActualGap,


dblHeight)

And instead of the ,0 for the start location in the Y axis, you could have used the Variable for the dblStile as
the start location.

This would then not have drawn the section of oLine underneath the inner design and the name of the items to
keep in the collection would have been oLine instead of oRemains(1).

Introduction to API 39
Because we only need to keep the central section of the vertical line, we will apply the delete command to the
oLine and the oRemains(2) sections.

Simply adding the .Delete command to a named object will perform the delete function.

Understanding the naming process is fundamental to working with the Delete command in this section, if a
more complex design were created, then the Remains section would have many more suffix numbers to work
with.

Finally, to make using these new lines easier when we apply machining later, we will place them into their own
new collection.

Save your current project.

Then using your preferred run command, check to make sure that your coding is correct.

Finally, in this section, to ensure no possible errors may occur, add the line oInside.Selected = False to
deselect the inside profile.

In this code list, it does not matter if the oInside.Selected = False is within the loop section or not, however it
may have an impact on more complex coding.

Introduction to API 40
Introduction to API 41
Considerations for Manufacture
Now we have created the final design, we need to think about how we are going to machine the part.

Start point location maybe an issue depending on the methods to be employed.

If time is a factor in the manufacturing process, perhaps machining the central line details all in the same
direction could be slower than machining one up and the next one down.

Are all these designs always the same thickness, or the central design the same depths?
Do you need to consider Fixed Z machining or Auto Z machining?

Thinking about how a part is to be manufactured can influence how you write your code initially or perhaps,
modify it afterwards once proof of concept works.

In this example, we will now;

• Assign depth values for the three sets of geometries we have created.

• Set the start positions to suit how we wish to machine the part and to save time.

• Cut the lines up one then down the next.

• Set the Ghost Tools to the correct side of the lines to machine.

Introduction to API 42
Reversing the directions of alternate slat lines
If this were a small design, the time taken to travel from the top of one line to the bottom of the next may be
minimal, consider if this were a very tall item, perhaps 2m, there would be considerable wasted machine
motion when cutting the slat lines.

Reversing the direction of each alternate line will allow us to cut up the first line, down the second, up the third
etc.

To allow for the calculation of which is the correct line to reverse we use the Mod function.
Mod takes one value and divides it by another, then returns the remainder of the calculation.
So, a statement of 3 Mod 2 would return a value of 1.

To identify every other line, we need to find all the even numbers lines in the collection oLines.

As the lines will be numbered in ascending order, dividing by 2 and looking for a result of zero will only pick up
on the even options.

From the image above, the following lines of code need to be added after the
oInside.Selected = False statement.

• For intN = 1 To oLines.Count

A new loop start line, commencing at 1 and continuing until all the lines in the collection oLines have been
looked at by using the .Count option.

• If intN Mod 2 = 0 Then oLines(intN).Reverse

Using the If statement, we question the identity of the line number to see if it is odd or even by using the Mod
function and dividing the value in intN by 2.
Should the remainder be 1, then this is an odd number and the line is ignored, however, a result of 0 means an
even number and the line direction is reversed by use of the oLines(intN).Reverse statement.

• Next intN

Closes the loop function and, until the number of lines is reached, continues the checking procedure.

Save your current project.

Then using your preferred run command, check to make sure that your coding is correct.

Introduction to API 43
Introduction to API 44
Setting the correct Tool Side
The correct sides now need to be set for the outer rectangle of the door and the inside detail so that it forms a
pocket.

Add the following two lines of code to set the inner design to Inside and the main rectangle to Outside.

These lines have been added after all the drawing instructions only for
clarity and to demonstrate the coding listed in the order you would perform
these whilst drawing in ALPHACAM.

You could write these lines at the actual drawing section if you preferred.

Setting Start Points for the Inside design


Depending on the needs of the machine or part, it may prove necessary to alter the start point of a geometry to
suit manufacture depending on how the geometry has been coded.

The following two lines are added before the .ToolInOut command to find the new start point location, then to
actually set it.

The oInside.Elements(1).PointAtFractL statement allows you to find a location on a specific section of a


geometry, indicated by the value in the brackets, in this instance the first element of the profile, using a value
from 0 to 1.

For example, 0.25 would be a quarter of the way along the chosen element, 0.5 would be half way along.

The .SetStartPoint command does what it says to which named object precedes the function, in this case we
are altering the oInside start point location.

Introduction to API 45
New Variables for PointAtFractL and SetStartPoint
In both previous two command structures the required format must include the X Y Z statements.
So, three new variables will also need to be added to the current listing.

Setting Start Points for the Outer Rectangle


The format for the lines of code to work on the rectangle are the same as the internal design, but you need to
make sure the object names are correct.

Note that the only differences are the object reference, either oInside or oOutside depending on which
collection we are working with.

On the oOutside collection, the start point is on the second element drawn.

Introduction to API 46
Introduction to API 47
Working with Z levels

Attributes
Depending on the type of machining you would wish to apply to a part, there may be a requirement to add
extra information to the coding that will allow you to work with the Auto Z method of machining.

The process used to create these Z levels involves using attributes set up inside ALPHACAM that reference
the items in question.

LicomUKDMBGeoZLevelTop is an example of an attribute, this one specifically will set a value in Z to


represent the upper level of the chosen geometry.

Attributes have a specific naming structure to them and if you wish to create your own, you would be advised
to maintain the structure.

The naming structure is broken into three sections.

• LicomUK – The originating company and country.

• DMB – The authors initials.

• GeoZLevelTop – The name of the command structure the attribute is working with.

The first two are the easy parts to name, the third section is creating a name that reflects exactly what the
attribute will do.

There are many attributes already available within the ALPHACAM API.
If you require information on them, please contact the support team with
your specific needs and they will advise further. This advice is primarily
because detailing all the available attributes is well beyond the scope of this
manual.

Introduction to API 48
New Variables for Attributes
As you cannot use the attributes directly as themselves, we must set up two new variables that will be linked to
them.

These two new variables are set using the Const option or Constant.

This infers that this value will never alter from what it is defined as and as such, cannot be modified in the
same manner that the values of the five entries above could using calculations.

Assigning the new values


Two lines of code now need to be added to the existing list,

The line of code is set up as follows;

• oInside.Attribute (strZlevelTop) – This section of the code states on which object an attribute is to be assigned
a value.

• = CDbl (0) – The CDbl is the dedicated command to inform the processing of the type of value and then in
brackets the actual value.

So, this line will set the top value in Z on the inner design to 0, or the top of the actual part.
The second line sets the lower value to -8, an 8mm deep cut.

Introduction to API 49
Note the subtle difference in the way in which the code has been entered for the outer rectangle.

If you wish to, you can use a colon : as a line separator instead of placing coding on individual lines.

This is a perfectly acceptable method of coding, though it may be easier when learning to place everything on
individual lines, in some instances it can make reading the code a lot easier.

The final lines of code are applied to the slat details.

Placing the slat Z Level options within the loop which is used to reverse the directions means that each line is
acted upon during the loop and none will be missed.

Introduction to API 50
Machining
Adding the correct code for machining involves adding the correct code statements to the bottom of our listing
but also creating a brand new Sub section in which we will set up the required instructions for actually
applying the machining.

Placing the instruction set in its own Sub section means that we only have to place a call for this section, rather
than writing the code out two or three times on this part, but perhaps more times on more complex designs.

Create the Sub


At the very bottom of your current code listing, after the End Sub statement, enter the following line of code.

Note the difference in the naming structure compared to the Sub Main ( ) we have been working in all this
time.

The values in brackets are variable options that will be passed from Sub Main ( ) into this Sub.
Those items are the geometry collection that we wish to machine at the point we call up this Sub, and the
name of the machining style we wish to apply.

Declare the variables


The next two lines assign two new variables for use in this Sub only.

MillStyle sets the variable as a machining method, this is not to be confused if you are working in the Router
or Stone module, you will still use the MillStyle function.

Path sets the variable as an item that can be followed correctly.

Introduction to API 51
Select the items to machine
The next three lines of code represent the process of selecting geometries in ALPHACAM where you would

<LClick> on the item you wish to machine.

When we pass the information to this Sub for the machining to be added, we will have set up collections using
the oGeos name.

The For / Next loop written above looks at every individual element within that collection and sets it as

Selected, exactly in the same manner as <LClick> if you were adding the machining manually.

Apply the machining cycle


Once the geometries are selected, the last two lines apply the correct machining style to the geometries.

The Set line takes the value held in the variable strMcStyleName and assigns that to the object oMcStyle.

The next line applies that machining style to the selected geometries.

Applying the logic for the coding in this manner reduces the amount of code you need to write, the only
sections you need to repeat will be to define the differing collections of geometries, and which machining style
is to be used.

Save your current project.

Then using your preferred run command, check to make sure that your coding is correct.

Nothing will happen with regards to the machining, as we have yet to create the code for that section.

Introduction to API 52
Call the Sub for the Slat lines
In the next single line of code, we will tell the process which sub section we need to run and what to apply the
process to.
We will also state where the correct machining style can be found.

The command Call tells the process we are to jump to another section within the macro, in this instance, the
newly created Sub ApplyMachiningStyle.

For this first section of machining the first variable in the name of the Sub, oGeos, is ignored because we are
stating a definite collection via the oLines statement.

The next section tells the process exactly where to look for the machining style.

• App.LicomdatPath – This takes the location of LICOMDAT from your


Home > Configure > Folders location in ALPHACAM, so that it knows where to look.

• & - and add the following

• “LICOMDIR\Styles\APIintro\APIintro_Engrave.ary” – The exact path to the machining style to use.

Writing the code in this manner will rule out any changes of location for the LICOMDAT and LICOMDIR
folders, but it will not allow for changes in the location inside LICOMDIR.
If the machining style does not exist, or the folder location below LICOMDIR alters, the coding will error out.

This first line of machining applies a tool path to all the slat lines in the centre section of the design.

Note that the extension name of the machining style will alter depending on
the module in use.

*.ary for Router, *.amy for Mill, *.asy for Stone etc

Introduction to API 53
Call the Sub for the Inside geometries
The next three lines of code will do the same as the previous section of code with a few differences.

First the Set oGeos line sets up a collection for the geometries we wish to machine to be added into.

oGeos.Add oInside looks for the already stated collection of oInside and passes that information to the new
collection called oGeos.

Remember that doing it this way keeps a single collection name for the Sub, but
allows us to pass many different collections to it.

Finally, the Call line does as previously described, but this time passes the geometries for the inside design to
the sub section for machining.

One thing not to forget is that in the Main section of the coding at present, there is no variable called oGeos,
you will need to add this to your list.

Introduction to API 54
Call the Sub for the Outside rectangle
The next three lines of code will do the same as the previous section of code but for the outside detail.

The repeated section of code restates the Set oGeos line so that a new collection of geometries can be
created.

The oGeos.Add line makes the oOutside geometries now the working collection.

Then the correct path and machining style is added to the design.

Adding a Material for Simulation


Whilst this is not critical to the actual process of the macro, it could prove beneficial to be able to see exactly
what the design will look like once you have run the macro by running the Simulation in ALPHACAM.

To allow us to set a rectangle to be a material we need to declare one more variable at the start of the sub.

The following lines of code create another rectangle around the complete form with an offset value hard coded
to the listing, along with the same values for the thickness of the material as used for the Outer rectangle
during the design phase.

Introduction to API 55
Alter the viewing perspective
All through the tutorial we have looked at the part from the top down XY view, or manually altered the view
perspective to the ISO view using the ribbon commands.

To allow the macro to perform this takes automatically, add the following line of code after the Zoom All
statement.

Save your current project.

Introduction to API 56
Conclusion so far
With a little thought and practical application, we have seen how using the ALPHACAM API we can not only
draw basic simple designs but turn those simple items into more complex designs.

We have seen how to manage individual geometric elements into collections so that you can then use differing
commands or sections of coding to act upon those collections.

The layout we have used is a functional one, but is fully open to interpretation, for example, during the creation
of the coding, we added the variables as we needed them and always to the bottom of our growing list.
There is nothing wrong in setting out all your variables first and in a specific format should you wish.
Some coders like to have all their Integers listed together, all their Doubles listed together and so on.
The format is up to you.

There is one big conclusion you should draw from the example we have worked on so far, the fact that it is a
fixed size item unless you specifically alter the variables for the size of the part within the coding itself.

In the next section of this manual we will look at further customisation to your project so that you can add a
more dynamic appeal to the process which will allow the user to alter the sizes of the part to suit a variation of
dimensions.

Introduction to API 57
User Forms
To create a more user friendly scenario, User Forms are set up on many macros to allow input of information
or to offer advice to the user depending on the nature of the code in question.

Before we begin creating our form there must be a little piece of advice passed to you as a coder.

We will not be writing this form completely from scratch as there are several elements that need to be in place
so that everything works and it is well beyond the scope of this manual to teach you all the definite required
articles.

With this in mind, we will be Inserting a prewritten form and its required items from the examples supplied with
this tutorial, then editing the sections in the form to suit us.

After that we will look back at our original coding list and edit this to allow the form to be used.

Import the required files

From your list of Projects, locate the DoorExample and <RClick> on it to access the pop up context
menu.

Once the browser window opens, locate and import the following files.

You can only import one file at a time, so you will need to repeat the process for all required files.

Introduction to API 58
The names of the three additional files under the Modules heading all must remain as written.

The name of the form can be anything you wish, note the prefix Frm for form and just like any other item, no
spaces are allowed in the name.

In some cases, like this, it is perfectly acceptable to copy working code from
another project to save time in rewriting the same code over and over.

Building up a library of working code modules is good practice.

The FrmAPIintro will be the section of code that we will be working with to create a User Form that suits our
needs for this project.

In the modules section, Evaluate performs mundane functionality such as changing a comma separator into a
point separator which ALPHACAM must use.

In this example, Events will control the name and grouping used for the ribbon bar entries for the new macro.

These are just examples of the vast amount of functionality that can be used within the VBA environment.

Introduction to API 59
Form Design Basics
To allow for ease of explanation, we have imported a prebuilt form.

Forms can be viewed in two different ways, the above image shows the form in the Object view which is how
the item will be seen by the user, this is by far the easiest view to work with as it allows for ease of positioning
any items needed in the form.

Forms use a Toolbox which lets you add such items as Labels to identify certain areas or input boxes. The
actual input dialogues along with functionality buttons such as the OK and Cancel ones we see here.

Introduction to API 60
The second view you can use for the form is in Code view.

Within a form maybe several differing sections that will perform actions depending on the needs of the form.
For example, actions which will only be carried out once a button is actioned, sections to check that the user
input is valid for the process to be carried out.

The form we will be using will be a simple single page item but there is nothing to stop you from designing
multi tab or page items like the dialogue boxes which you use when physically creating toolpaths in the main
ALPHACAM window.

Introduction to API 61
Initial Imported Form Design
The imported form design has several simple functions set up to make the next section easy to follow.

Should you wish to create a brand-new form, using the <RClick> context menu on the Forms section will
allow you to Insert a new UserForm.

Introduction to API 62
Structure
Once you have the base form started, using the handles around the outer edge allows for resizing, sometimes
it can prove beneficial to have the form larger than you need to allow you to design better.

The sample form already has three distinct items placed for you to work with;

• Labels – These allow for the naming of various elements on the form. The dialogues to the left of the white
space boxes.

• Text Boxes – Allow for the entry of data to be used in the macro. The white space boxes to the right of the labels

• Buttons – Allow additional functionality, in this case OK and Cancel.

All these items and any others you may wish to use are dragged from the Toolbox and positioned within the
forms main area.

In the same manner that we applied variables when creating the main code section, every item on a form
needs to have a unique name to identify it.
As you add more items, the name will increment by one.

For example, without changing the name of an item it could be called TextBox1, the next would be TextBox2
etc.

The above image shows how the form would have looked during the initial design stage.

Introduction to API 63
<LClick> on any of the Labels or Text Boxes will show you the Properties window for that item.

Here is where all the differing options for the varied items are located, whilst dragging and dropping allows for
quick and easy approach to designing the form, you will want to access the Properties window to rename the
object as well as alter size and position.

The properties dialogue is an important feature that you should understand, here you can alter the name of the
item, the colour of the text, the style of the actual item being worked on.
This is where you can personalise your forms.

The name of a label is not as significant as the name of a text box though, here it is crucial that you know
which box you are working with as this will be where the user enters information, and this information will be
passed to the actual coding we have already completed earlier.

The next useful property for a text box is the entry named TabIndex.
This sets the order for how the form is navigated if you use the <Tab> key to jump to the next dialogue
option.

TabIndex is defined in an increasing number scale as you add in the boxes, bear in mind that you may be
adding the boxes in a random design order at first, TabIndex is incremented on each new box so you will be
returning to them later to ensure a logical order for completion.

Using the <Tab> key on the form in the designing view will demonstrate the order that the boxes will be
accessed.

Introduction to API 64
Termination Code
Viewing the form in Code View, you will see at the very beginning two simple sub sections which control the
options if the user clicks on the standard cross at the top of any Windows dialogue or clicks on the Cancel
button.

In both subs is the command blnFrmTerminate. This tells the code if the form is in use or not.
The line below Me.Hide is the inbuilt command that switches off the form. As we have seen during the coding
for the door shape, Me. also has many options available to use with it which may enhance the form as the user
selects differing options.

To allow the form to function correctly, this new variable blnFrmTerminate must be added as shown below to
the Code section of your project.

Introduction to API 65
Initial Settings Code

The next section of code in the form sets up the initial starting values to be used when the form is first opened.

The first two lines allow for an option to read a dedicated text file which can have the name values for labels
and buttons assigned to them. This can be useful if a change is required to a form but you want to prevent
access to the actual coding to prevent errors, simply altering the master text file that accompanies the macro
will then alter the names on the buttons or labels.

In this example, we have directly set the values in the Properties section so the two lines are not actually
required but are useful to leave should you change your mind later.

The next line of code sets the initial value for the text box named TxtWidth to a value of 500.
Note the use of the command RemoveComma, this informs the code to jump into the Evaluate sections of
coding and look for the sub section named RemoveComma and run that code set to swap any comma
markers to decimal point markers.

The next two lines set the starting point for the entry of the values and how large the value can be.

Finally, the .SetFocus line allows you to highlight a specific Text Box as the active item when the form first
opens.

So, on opening the form, Width is set as the active text box with a starting value of 500, with the other
dialogues set as per the options shown in the speech marks sections.

The CStr command converts the values into a text string to be able to pass the values from the form to the
main section of coding.

Introduction to API 66
When you click OK code

The above listing of code uses a loop system that cycles through all the required input dialogue text boxes

looking for a valid entry should the user <LClick> on the OK button.

Each If section looks for a value of more than zero to proceed and if none is found, uses the .SetFocus option
to highlight the text box with the missing information.

If all the conditions are met, the last section sets the values of the variables listed, to the values in the dialogue
text boxes and then closes the form.

Currently the listed variables are hard coded in our initial project coding
section, these will need to be altered to suit the new method of information
entry.

Introduction to API 67
Tidy Up the Values code

The above sections of code simply repeat for each variable entry, a process to check for a valid entry and to
remove any trailing zeros.

The routine to carry out the operation is held in a separate sub section called TextBoxCalculate in the
Evaluate module.

Introduction to API 68
Make the Form visible
Without the next piece of editing in your main coded section, the whole form will be worthless.

These first line displays the form and if the user then clicks on the cross or the Cancel button, the second line
will exit the entire macro.

Placing the new lines after the App.New line will clear the existing drawing and start a brand new one.

If you do not remark out the original variables, it will not matter what values you enter on the form, these will
replace them.

Once you have proven that everything works correctly, there would be
nothing preventing you from removing any unwanted items that you have
remarked out, simply to tidy up the code.

Having items remarked out during the design and debugging stage is a
better option.

Introduction to API 69
Adding to the ALPHACAM Interface
Regardless of all the hard work put into the coding and form design, unless the macro is in the correct folder
structure your macro is never going to be used.

All through this manual we have used a folder structure “…. LICOMDIR / VBMacros” as the default working
location just for convenience.

To ensure that your macro is loaded correctly when ALPHACAM is started, you need to place your macro in a
specific folder.

“…. LICOMDIR / VBMacros / StartUp/Your Folder Name”

The “Your Folder Name” section will be where all your files for the macro are stored.

Editing the following sub in the Events module allows you to alter the name of the Tab on the ribbon as well as
the names of the section and title of the actual command.

This means that we can leave the macro, for the time being, DoorExample but when the functionality is run in
ALPHACAM the following is applied.

• Tab name – Altered to the value assigned to strTab =

• Command name – Altered to the value assigned to strCommand =

• Tab Group – Altered to the value assigned to strGroup =

Introduction to API 70
Conclusion
Whilst the purpose of this course is to introduce you to the functionality available when using the ALPHACAM
API it can seem extremely daunting to the first-time programmer.

Supplied with the course are several working examples for you to look at to get a better understanding of how
the ALPHACAM API can be used and to give you a few design ideas for future projects.

Working with the ALPHACAM API needs structure so that all your requirements are met, you also need to
have a dedicated goal for each project that you undertake otherwise you will not be able to write the code
correctly.

Additional Examples
Included on the supplied course USB are several projects ranging from simple coding to apply a dedicated
Program Stop to your NC code, to an expanded version of the Door Example worked on earlier.

To allow these to be functional in ALPHACAM, either open the code in the VB Editor, or copy the supplied
macros to the VBAMacros / StartUp folder location.

Introduction to API 71
Version amendments
V Amendment Description A Software Version Amended Date
8 Updated to new 2024 release. 0 2024.1 08/04/2024
7 Updated to new Nexus links 1 2023.3 21/09/2023
7 Updated to new Hexagon template 0 2023.1 13/03/2023
6 Adjustments to images. 2 2022.2 18/07/2022
6 Error on Reading postcode 1 2022.1 16/05/2022
6 Updated to new Hexagon Template and software release 0 2022.1 22/04/2022
5 Table of Figures removed. Wiki page links added. 0 2022.0 16/06/2021
4 Updated to new Hexagon template 0 2021.0 23/03/2020
3 Minor text formatting alterations. 1 2020.1 10/10/2019
3 Template altered to Hexagon branding 0 2020.0 15/03/2019
ALPHACAM
Floor Two Tel.+44 (0) 1189 226677

No. One, Waterside Drive Email. alphacaminfo@hexagon.com

Arlington Business Park Web. nexus.hexagon.com/home/product/alphacam/

Theale

Reading Support. support.alphacam.uk@hexagon.com

Berkshire Portal. customers.ps.hexagonmi.com

RG7 4SW

United Kingdom

You might also like