In part one of this series, we looked at how to use CIMCO Editor macros to prompt us for the program information to add to our NC-Base database. If you missed part one, you can find it here. Today we’ll look at how we can use the same approach to update the NC file header automatically from information in the database.
Let’s say for example that you have a lot of legacy programs that were added in bulk as older storage systems are phased out. Or maybe the company requirements have changed as to what data the NC file must contain. Whatever the case maybe, having to manually type the data into the program headers for more than a few programs can quickly become a very time intensive task.
Our Target – A program to search
To get started, we need to create a program that will make it easy to figure out which fields in the database contain the information that we want to capture for our macros. On the Database tab in NC-Base, click on ‘Add Program’
Select a machine group and select
‘new file’ from the drop down.
Fill in your Program, Part Number, Drawing Number, Description, and Customer as follows.
To accomplish our goal, we actually need to create two macros to create one. We will be using CIMCO variables to access the database fields for our program and updating the program header dynamically based on the data they contain. In order to do that, first we need to figure out which fields contain which pieces of information. Enter our first macro. Since we don’t know which fields carry which piece of info, we are going to write a macro that queries all of them. We will then figure out which ones we need to use to give us the result we are after.
Macro “A” – Discovery
In order to create a macro, you are going to need to click on the ‘NC Functions’ tab
Click on the ‘Macro Setup’ button
Here we are on the screen that will allow us to create both of our macros. We are only going to concentrate on the first one for now. Click the add button, name it ‘Get Database Fields’, and click ok.
Now that we have added our macro, we can add the variables that we want to check the values of. While the Program Name and Customer have their own named variables, the other values are accessed with numbered variables. We are going to query all of them and see what lines up. Enter the variables as follows and click ok. The parenthesis are important for knowing when a field was returned but was empty.
Now we are ready to use our macro to find the data we want to use in step two to update our NC file. To do that we need to go back to the Database tab.
Now we want to click on the program we created and click ‘Open’
Now that we have our program open in CIMCO Edit, we can use our new macro to query the database. All we have to do is click on ‘Get Database Fields’ in NC-Assistant and click ‘Add’ at the bottom.
NC-Assistant will then grab all the info we asked for and paste it into our program file.
If we compare the variables in my example to what was returned, we see that
all the data we need is in the first five variables
$DBPROGRAM = Program Number
$DBCUSTOMER = Customer Name
$DBPRGFIELD1 = Part Number
$DBPRGFIELD2 = Drawing Number
$DBPRGFIELD3 = Description
(These will be the variables that we are going to use in our second macro to add the data to the NC file header.)
Macro “B” – Application
Now it is time to apply what we have learned. We are going to need to create another macro, call this one ‘Update Info From Database’. In order to make sure that our programs all match, we need to copy the sample text from the ‘Program Format’ section of our database configuration. We covered this in detail in part one of this article which is linked at the top. Because of that, we are going to skip it this time around.
When you paste the contents of your program format sample into your macro to be, it should look something like this.
What we are going to want to do is take the variable from macro “A” that gave us the correct information and paste it into the macro in place of the sample data. Click ok.
Now we can delete the result of our first macro and run our second one. We do this by selecting ‘Update Info From Database’ and clicking ‘Add’.
All the fields should now be inserted in the correct order to match our configuration.
The only thing left to do is save the file.
The Result – Fruits of our labor
If we go back over to our NC-Base database, we can see that our program has been updated in the database and the NC file header correctly matches the data.
Now we can use our macro on any program in NC-Base. Before you know it, you will have a program library of standardized files that contain accurate data. Once again we are looking at one specific way to use the CIMCO Editor macros to make our lives a little simpler through automation. In this case we leveraged the database variables to access the data we wanted to add to our program header. This just scratches the surface of what is possible with CIMCO Editor, Macros and NC-Base, and doesn’t even touch on the more advanced tool CIMCO MDM, we’ll save that for another day.
During this two part series, we covered how to create your own variables and how to access the built in ones. How can you take what we have learned and apply it in your own environment? We would love to hear ways that you use macros to save time and money in the comments.