Introduction

The API's contained in this section can all be utilized inside of a BobCAD *.bcpst post processor file.


One major advantage to the Lua scripting is that you are able to call any of the available Lua API's covered in this help system from the post processor.  So not only can you get access to all of the posting options, but you can access operation parameters, create dialogs, and even create CAD geometry in the BobCAD document if needed.

Structure

We have defined two different methods for utilizing Lua scripting with the BobCAD post processing system:

Method 1

Much like the VB scripting blocks that have existed for years, the same structure can be utilized starting with block 2701-2799 within a *.bcpst post processor file.


By utilizing a variable named lua_block_# this will call the corresponding block within the post containing the Lua scripting, for example:


lua_block_1 calls the 2701. block

lua_block_2 calls the 2702. block

.

.

.

lua_block_99 calls the 2799. block

Method 2

Alternatively, we have created a second method for linking your Lua scripts to a post processor which involves just keeping all your Lua scripts in a separate *.lua file with the same name as the *.BcPst file.

Let's say you are working on the BC_3x_Mill.bcpst post processor.  

Method 2a

    • You can simply create a BC_3x_Mill.lua file and put all of your Lua scripts in this file. These files must be located in the same directory, which is typically the Posts\Mill, Posts\Lathe, or Posts\MillTurn folder located in your products Data folder.


OR 

Method 2b


You can also create a sub directory inside of your Posts\Mill, Posts\Lathe, or Posts\MillTurn folder and add block 732. Lua sub folder? "MySubFolder" into the post processor itself, and then the posting engine will look for this sub folder and load any *.lua files that are located inside of this sub folder. 

    • Inside of your Posts/Mill folder you can create a folder named whatever you want, let's use 3x_Mill as our folder name.  
    • Inside of this 3x_Mill folder you create the MyLua.lua file which contains all of your Lua scripting functions.  The name can be whatever you like and you can also have multiple Lua files.  
    • Add block 732. Lua sub folder? "3x_Mill" to the BC_3x_Mill.bcpst so that the system knows where to find your Lua scripts.


By utilizing a variable named lua_func_FunctionName inside the post processor this will call the corresponding Lua function from the loaded Lua file using the methods mentioned above. 


Notes

There are a few things I believe we should note regarding this functionality and the design:


  • There is a general assumption and recommendation that when using Method 2b that each different .bcpst file will have its own sub folder created.  
    • While it is entirely possible to share the same folder with multiple post processors you must be careful that if you have multiple lua files in the same folder, that all function names are unique across all the Lua script files.  If multiple lua files have the same function name, and you call that function from within the post processor, the last Lua file loaded into memory will get used.  You cannot guarantee in any case which one will be called!