Introduction CAMMaster is a very high performance CAM software program. Most of the functions that you can perform manually can be automated by utilizing the methods and properties that are exposed by CAMMaster. These methods and properties can be controlled by writing scripts. Scripts are essentially a recorded set of instructions that tell CAMMaster to perform a desired set of operations. There are many advantages to utilizing scripts with CAMMaster: Repetitive and/or tedious operations can be performed very quickly. This results in reduced operator fatigue and improved performance. Once programmed properly, scripts don t make mistakes. This ensures higher quality. Using scripts can help users that are not familiar with CAMMaster to become productive quickly. Scripts can be written to ensure that no procedural steps are missed when generating your CAM data. There are many ways to generate CAMMaster scripts. You can utilize the built in SAX Basic editor to record, store and run macros (simple scripts). Those familiar with the Visual Basic programming language can utilize it to automate CAMMaster. In our opinion, the serious script writer should consider using Visual Basic 2008 (previously known as VB.NET) to write CAMMaster scripts. VB 2008 is a very powerful object oriented language based upon the Microsoft.NET framework. Programs generated using VB 2008 and compiled under the.net framework run very quickly. This document provides a brief overview of how to automate CAMMaster using Visual Basic 2008. Visual Basic 2008 is offered by Microsoft and is available in several different configurations. It is available as a low cost standalone product or as part of one of the many Visual Studio packages. The examples shown in this application note are created using the Professional edition of Visual Studio 2008. This document is not intended to be an exhaustive treatment of the subject. It is intended to give the user interested in scripting CAMMaster a starting point for further development. Copyright 2008 PentaLogix, LLC All rights reserved Page 1
Configuring Visual Studio Start Visual Studio and select Tools >Options as shown below. Expand the Environment node and select the Keyboard node. Ensure that the keyboard mapping scheme is set to Visual Basic 6. Click on OK to dismiss the dialog. Copyright 2008 PentaLogix, LLC All rights reserved Page 2
Starting a New Project You save data pertaining to your script in a Microsoft Visual Studio project. To start a new project, either press Ctrl+N or select File >New Project as shown below: Ensure that you select the Windows Forms Application project type. Name your project My First Script and click on the OK button. Copyright 2008 PentaLogix, LLC All rights reserved Page 3
Starting a New Project continued After creating the new project, your screen should appear as shown below: Copyright 2008 PentaLogix, LLC All rights reserved Page 4
Adding the CAMMaster Tool Class Reference CAMMaster uses Active X to expose the many methods and properties that you can utilize to automate the operation of the program. To use these features, you must add a reference to the CAMMaster Tool Class. Select Project >Add Reference Click on the COM tab and then scroll down and select the PentaLogix CAM tools Type Library entry. Click on the OK button to add the CAMMaster Tool Class to your project. In the upper right corner, click on the Show All Files button and then expand the References folder. Notice that the CAMMaster tool class reference has been added to your project. Copyright 2008 PentaLogix, LLC All rights reserved Page 5
Adding Some Controls to Your Startup Form Click on the Show All Files button again to hide the support files of your project. Ensure that you click on the item called Form1.vb as shown below: When you start your project, this form will be displayed. Let s add a few controls to this form. Start by expanding the Common Controls folder in the ToolBox window. Then drag a button control onto your form as shown below: Copyright 2008 PentaLogix, LLC All rights reserved Page 6
Adding Some Controls to Your Startup Form continued If not already selected, click on the button to select it. Notice the Properties window in the lower right of the screen. Enter the words Do Now for the button Text and press Enter Scroll up in the Properties window and name the button btndonow. Copyright 2008 PentaLogix, LLC All rights reserved Page 7
Adding Some Controls to Your Startup Form continued Expand the Containers folder in the Toolbox window and drag a GroupBox control onto your form as shown below. You may need to reposition and resize it as appropriate. With GroupBox1 selected, set the Text property to Show and the Name property to grpshow. Your form should now look as follows: Copyright 2008 PentaLogix, LLC All rights reserved Page 8
Adding Some Controls to Your Startup Form continued Finally, add four radio button controls to your form as shown below: Set the Name and Text properties of each radio button as shown in the table below: Name opttraces optpads optbothtracesandpads optneithertracesnorpads Text Traces Pads Both Traces And Pads Neither Traces Nor Pads Copyright 2008 PentaLogix, LLC All rights reserved Page 9
Running the Program for the First Time We have now added the controls we need for our project. We will have to write some code that responds to the controls. However, for now, let s run our program. Press F5 or select Debug >Start Debugging as shown below: Our program should start and be displayed as shown below: Notice that none of the radio buttons are selected when the form starts. You can click on the individual radio buttons. Notice that the previously selected button is deselected when a new radio button is clicked. This is part of the built in operation when several radio buttons are placed into a group box control. You can also click on the Do Now button. Nothing happens... because we haven t written the Event Handlers for our controls. We ll do this in a subsequent section. But first, we ll declare some variables and import the CAMMaster tool class into our project. Exit the program before continuing. Copyright 2008 PentaLogix, LLC All rights reserved Page 10
Declaring Variables and Importing the CAMMaster Tool Class Ensure that the Form1 item is selected in the Solution Explorer. Then click on the View Code button as shown below: The code associated with Form1.vb is shown in the center part of the screen: Place the cursor at the beginning of the word Public and press the Enter key twice to add a couple of blank lines to the top of the code. Move the cursor to the beginning of the first line and start typing Imports. You ll notice that as soon as you type the I, Visual Studio will display the following Intellisense window: Press the Tab key and Visual Studio will automatically add the word Imports to your code. Copyright 2008 PentaLogix, LLC All rights reserved Page 11
Declaring Variables and Importing the CAMMaster Tool Class continued When you press the spacebar, Visual Studio next suggests the following items to be imported. Press the C key and the Intellisense choices are narrowed to CAMMaster. Press the Tab key to add the word CAMMaster to the code. Your code should now look as shown below: In our code we will need a variable that references the CAMMaster Tool Class. Let s call this variable CAM. Declare the variable by adding the following line to your code. Make sure that you add this line below the Public Class Form1 line and above the End Class line as shown in the figure below. Also add three variables called IsTrue, IsFalse and stritemstoshow as shown: Copyright 2008 PentaLogix, LLC All rights reserved Page 12
Writing Code to Respond to the Radio Button Controls We need to respond when the user selects one of the radio buttons. Add the following code above the End Class line. Note that you should use the Intellisense features whenever possible to avoid unnecessary typing. We will call this subroutine anytime the user clicks one of the radio button controls. In the first line, we identify which radio button was clicked. Notice that when you click a radio button, this subroutine will be called twice. It will be called the first time when the previously selected radio button is deselected. We don t want to respond to this event, so we exit the subroutine if the radio button is not checked. The routine is entered a second time when the new radio button is checked. In this case, we process the rest of the routine. We now need to tie each of the radio button controls to the optrb_checkedchanged event handler. Add the following code above the optrb_checkedchanged subroutine (notice that I ve collapsed the optrb_checkedchanged subroutine for clarity). Copyright 2008 PentaLogix, LLC All rights reserved Page 13
Writing Code to Respond when the Do Now Button is Clicked I think it is preferable to write event handlers as shown in the previous section. However, there is a simpler way to write an event handler. We ll do this now for the btndonow.click event handler. Click on the View Designer button to switch back to the Design view from the Code view: Double click on the Do Now button. Visual Studio adds a subroutine that will be called every time the user clicks the Do Now button. The view is automatically switched back to the Code view and Visual Studio automatically adds the following subroutine (shown below the optrb_checkedchanged subroutine): Add the following code to the new subroutine: Notice the With CAM... End With block. This lets you write.tracesvisible and.padsvisible instead of CAM.TracesVisible and CAM.PadsVisible respectively. Copyright 2008 PentaLogix, LLC All rights reserved Page 14
Initializing the Form The Page Load Event When our program starts, we need to make sure that certain things are initialized. For example, we need to call the subroutine that will add our event handlers. We also need to activate one of the radio buttons by default. Before adding the Page Load event, your code should appear as follows (all subroutines are collapsed for brevity): Click in the Class Name combo box and select the Form1 (Events) item as shown below: Then, click in the Declarations combo box, scroll down and select the Load item as shown below: Copyright 2008 PentaLogix, LLC All rights reserved Page 15
Initializing the Form The Page Load Event continued Visual Studio adds a subroutine called Form1_Load. This subroutine is executed when your program starts and the main form is loaded. Add the following code to the Form1_Load subroutine: Notice that we first call the subroutine that adds the event handlers. We then make sure that the option to select both traces and pads is selected. Finally, we ask that the btndonow.click event is called. Copyright 2008 PentaLogix, LLC All rights reserved Page 16
Run the Final Program To run without errors, you should ensure that you have exactly one instance of CAMMaster started before you start your program. Start CAMMaster and load a file that contains both traces and pads. To make things easier, it s probably best to activate only one layer: Now start your program by switching to Visual Studio and pressing F5. Your program should appear as shown below: Click on the Traces radio button and then click on the Do Now button... voila! We hope that this tutorial helps you get started with VB 2008 and CAMMaster. There s lots more to learn. Please feel free to call on us for additional information! Copyright 2008 PentaLogix, LLC All rights reserved Page 17