Post Processor Lessons - Lesson 8
POST MODIFICATION LESSON 8: VB SCRIPTING 3
                                            
                                            In the previous lessons we covered
- Variables
- Basic math
- Outputting a Message Box
- Outputting to the NC file using an API
                                                
In scripting sometimes you need to be able to retrieve a value, or calculate a value and store it for use later in the program. In this lesson we are going to write some values to the storage memory locations and then retrieve them from another scripting block and display them using a message box. This lesson shows how to store and retrieve the values but you can apply these principals to accomplish your specific needs. There are multiple API’s available to write and retrieve data from memory. Reference the Post Variable API Reference document for details on each.
                                            
                                                
                                                
                                            
We are going to use the following files for this lesson:
| 
                                                                 | 
                                                                 | 
                                                
     
                                                
                                            
Lesson 8 – Step 1:
Open the post processor and navigate to the Post Block: 2. In this Post Block we are going to create the call to the scripting block where we want to write data to memory.
Add the following after the tool change in the Post Block so that your includes “program_block_1” in the same location as the following.
    "(TOOL #",list_tool_number," ",tool_diameter," ",tool_label,")"
                                                
    n,t,"M06"
                                                
    program_block_1
                                                
    force_no_add_spaces
                                            
Lesson 8 – Step 2:
Now that we created the call to the Scripting Block we need to actually write the script that will write data to memory. In the post processor, navigate to Post Block: 2001. and add the following code.
   2001. Program Block 1.
                                                
    dim writestring  // Create string variable
                                                
    dim writeint  // Create integer variable
                                                
    dim writedouble  // Create double variable
                                                
    
                                                
    writestring = "Write This String"  // Assign value to String
                                                
    writeint = 12345              // Assign value to Integer
                                                
    writedouble = 12.345             // Assign value to double
                                                
    
                                                
    CALL MILL_SetStringMemoryLoc(0, writestring)    // Write String to memory location 0
                                                
    CALL MILL_SetIntMemoryLoc(0, writeint)        // Write Integer to memory location 0
                                                
    CALL MILL_SetDoubleMemoryLoc(0,writedouble)   // Write Double to memory location 0
                                            
                                                
In the notes of this code you can see we are creating the variables,  assigning values to the variables, and then writing them to memory.
                                            
Lesson 8 – Step 3:
Now we need to add a call to our 2nd scripting block. Navigate in the post processor to Post Block: 3. and add the following code.
n,t,"M06"
                                                
program_block_2
                                                
force_no_add_spaces
                                            
Lesson 8 – Step 4:
In this 2nd scripting block we need to add the code to retrieve the values we previously stored in memory. In the following code you can see in the notes how we are creating new variables to hold the retrieved values and then building a string to output the values to the user with a message box.
2002. Program Block 2.
                                                
    dim retstr// Create variable to hold output string
                                                
    dim readstring// Create variable to hold string read in from memory
                                                
    dim readint// Create variable to hold integer read in from memory
                                                
    dim readdouble// Create variable to hold integer to read in from memory
                                                
    
                                                
    readstring = MILL_GetStringMemoryLoc(0) // Read in string from memory and put in variable
                                                
    readint = MILL_GetIntMemoryLoc(0)     // Read in integer from memory and put in variable
                                                
    readdouble = MILL_GetDoubleMemoryLoc(0)  // Read in double from memory and put in variable
                                                
    
                                                
    retstr = readstring& " - " &readint& " - " &readdouble// Build output string
                                                
    MsgBox(retstr)         // Use Message Box to display output variable to user
                                            
                                                
Now save the post processor and generate the NC code. Notice the message box displaying the values that were written and then read from memory from two different locations in the post processor. (NOTE: You will receive the Msg Dialog for every time the script is called while processing through the features of your part.
                                            
 
                                                 
                                            



