Post Processor Lessons - Lesson 7

 

 

Parent    Previous    Next

Post Modification Lesson 7: VB Scripting 2

In lesson 6 we learned some VB Scripting basics to be used in the BobCAD-CAM posting engine. The previous lesson just started to scratch the surface of what exists in the scripting system and how to use it. We will be continuing on to expose and instruct working with scripting in the BobCAD-CAM posting engine.

We are going to use the following files for this lesson:


Machine File: BC_3x_Mill   

Post Processor: BC_3x_Mill.BCPst

Part File: Post Guide – Lesson 7.bbcd

Lesson-5 Image-1


In this lesson we are going to go over the following:

  • Building output from variables and string literals.


Open your post processor and make sure your scripting block matches the following:

(This is the same as where we left off in Lesson 6)

2001. Program Block 1.
    Dim testvar1
    Dim testvar2
    Dim testresult

    testvar1 = 5
    testvar2 = 8
    
testresult = testvar1 + testvar2
    
    MsgBox(testresult)

Lesson 7 – Step 1:

So far we have created variables, assigned values, performed some addition, and output the result to a message box. To continue with this we will now combine some string values and variables to format our message that is returned. There are several ways to accomplish this but I am going to show a method which I recommend as good practice. This is to create an output variable prior to calling the Message Box function.

We will start by adding our new variable to hold the output string we will build. Add the following code to your script.

Dim retstr

retstr = ""



 Though you can put these lines of code anywhere in the script above where we are going to use the variable, it’s best to keep your scripts organized. This means keeping your variable declarations in one section, variable initial value assignments in one section, and so on to keep things neat and tidy.

The code below shows the new variable declaration in the code and the initial value being assigned.

2001. Program Block 1.
    Dim testvar1
    Dim testvar2
    Dim testresult
    Dim retstr
    
    testvar1 = 5
    testvar2 = 8
    
testresult = testvar1 + testvar2
    retstr = ""
    
    MsgBox(testresult)


Lesson 7 – Step 2:

In the previous step the variable that is going to hold the output string has been created with no data in it. Now the output string can be built using the following code.

2001. Program Block 1.
    Dim testvar1
    Dim testvar2
    Dim testresult
    Dim retstr
    
    testvar1 = 5
    testvar2 = 8
    
testresult = testvar1 + testvar2
    retstr = ""
    
retstr = "Adding " & testvar1 & " and " & testvar2 & " equals the value: " & testresult
    MsgBox(retstr)


Lesson 7 – Step 3:

Save and generate the NC code. Notice the message box that is displayed as seen below.

 

As shown in the dialog box the values of the variables are used when displaying the message to the user. Here we are building  a string and outputting to a dialog, next we will look at outputting this string to the NC code output.

Lesson 7 – Step 4:

Open the Post Variable & API Reverence document and search for “MILL_SetReturnString”. This is an API function that is used to return a string to the NC file.

NOTE: There are other additional ways of outputting to the NC file as well. You can find them in the Post Variable & API Reference document.

This function works similar to the MsgBox() command we have already used. With this function we use the MILL_SetReturnString function to output our string into the NC file. Add the following code to your scripting block:

2001. Program Block 1.
    Dim testvar1
    Dim testvar2
    Dim testresult
    Dim retstr
    
    testvar1 = 5
    testvar2 = 8
    
testresult = testvar1 + testvar2
    retstr = ""
    
    retstr = "Adding " & testvar1 & " and " & testvar2 & " equals the value: " & testresult
    MsgBox(retstr)
    MILL_SetReturnString(retstr)


Lesson 7 – Step 5:

Save and generate the NC output code. Notice now that you still get the Message Box because we have not removed the “MsgBox(retrstr) code from our script. However, if we look at the NC code generated now you will find our string output into the first line of the program.

NOTE: The location of the output is dependent on where the call to the scripting block is placed. Remember that we have the call “program_block_1” as the first thing in Post Block: 0.


Using the knowledge gained from this lesson you can now access values from all the API calls in the Post Variable & API Reference guide.