Bcc.RegisterCamObjCallbackFunctions
Bcc.RegisterCamObjCallbackFunctions(ObjectID, {FunctionList})
Description
This function allows you to define a set of callback functions that will be called during different events that occur during CAM such as:
- Editing a feature/operation
- Computing a toolpath
- Posting an NC program
- Deleting a CAM feature/operation
In order to register a callback function with a particular feature or operation and have it operational is done with the following overall workflow which will be covered with the complete example:
- User must select a feature or operation in the CAM tree.
- A user defined Lua function must be fired (typically from the ribbon) that will grab the object ID and register the chosen callback functions to the CAM events for that particular feature or operation.
- Then when the event is fired, the registered Lua function will be called with BobCAD passing the object ID to this function to perform whatever actions you have defined.
Parameters
- ObjectID - integer number representing the object ID
- FunctionList - table including the event function key names and their subsequent Lua function to call when fired.
- Supported function Key names
- EditBegin - This event is fired when a user edits the registered feature or operation
- EditEnd - This event is fired when a user closes the CAM wizard
- ComputeTPBegin - This event is fired when a user begins calculating the registered feature or operation
- ComputeTPEnd - This event is fired when the registered feature or operation is done computing toolpath
- PostingBegin - This event is fired when the users chooses to post an NC program
- PostingEnd - This event is fired when the posted NC program is finished
- DeleteBegin - This event is fired when the user chooses to delete a feature or operation from the CAM tree
- DeleteEnd - This event is fired after the chosen feature or operation has been deleted from the CAM tree
Example
Basic Format
-- Register the callback functions that are fired during events in the CAM package
Bcc.RegisterCamObjCallbackFunctions(objID, {EditBegin = ObjEditBegin, EditEnd = ObjEditEnd, ComputeTPBegin = ObjTpCalculationBegin, ComputeTPEnd = ObjTpCalculationEnd})
Complete Example
---------------------------------------------------------------------------
---------------------------------------------------------------------------
-- Main Connection to BobCAD to create the ribbon and controls and link --
-- the buttons to functions --
---------------------------------------------------------------------------
---------------------------------------------------------------------------
function ConnectToBCC()
--First we create a button to display our dialog to choose which callback functions to register --
Bcc.AddCommand({ TabName="Lua Scripting", GroupName="CAM", ButtonName="CAM Watchdog", CallbackFuncName="camWatchdogUI", ImageNameLarge="Toolpath.png", ImageNameSmall="Toolpath.png", ToolTip="Monitors bad decisions in CAM operations" })
end
-----------------------------------------------------------------
-- This function is called by pressing our CAM Watchdog button --
-- This UI allows you to enable when the watchdog should --
-- check this status --
-----------------------------------------------------------------
-- Feature or operation must be selected in the CAM tree when --
-- this function is called --
-----------------------------------------------------------------
function camWatchdogUI()
-- Create all the checkboxes for all the options
dataChkBoxEditBegin = { ControlID = "EditBegin", ControlType = "CheckBox", Text= "On Feature Edit", IsChecked=false }
dataChkBoxEditEnd = { ControlID = "EditEnd", ControlType = "CheckBox", Text= "On Feature Close", IsChecked=false }
dataChkBoxTpBegin = { ControlID = "TpBegin", ControlType = "CheckBox", Text= "Toolpath Calculation Begin", IsChecked= true }
dataChkBoxTpEnd = { ControlID = "TpEnd", ControlType = "CheckBox", Text= "Toolpath Calculation End", IsChecked=false }
dataChkBoxPostingBegin = { ControlID = "PostingBegin", ControlType = "CheckBox", Text= "Posting Begin", IsChecked=true }
dataChkBoxPostingEnd = { ControlID = "PostingEnd", ControlType = "CheckBox", Text= "Posting End", IsChecked=false }
dataChkBoxDeleteBegin = { ControlID = "DeleteBegin", ControlType = "CheckBox", Text= "Delete Begin", IsChecked=false }
dataChkBoxDeleteEnd = { ControlID = "DeleteEnd", ControlType = "CheckBox", Text= "Delete End", IsChecked=false }
-- Create the window and add the controls
local windowParas = { Title = "Enable Watchdog for Selected Operation", Width = 350}
local itemlist = {dataChkBoxEditBegin, dataChkBoxEditEnd, dataChkBoxTpBegin,dataChkBoxTpEnd,dataChkBoxPostingBegin,dataChkBoxPostingEnd,dataChkBoxDeleteBegin,dataChkBoxDeleteEnd}
-- Display the dialog box
local retDlg = Bcc.ShowDialogBox(windowParas, itemlist)
-- If user clicks OK on the dialog
-- Set which actions should be enabled for the callback
-- Set all callbacks to call our camWatchdog function
if retDlg ~= nil then
objID = Bcc.GetSelectedCamObjID()
paras = {}
if retDlg.EditBegin.IsChecked then paras.EditBegin = camWatchdog end
if retDlg.EditEnd.IsChecked then paras.EditEnd = camWatchdog end
if retDlg.TpBegin.IsChecked then paras.ComputeTPBegin = camWatchdog end
if retDlg.TpEnd.IsChecked then paras.ComputeTPEnd = camWatchdog end
if retDlg.PostingBegin.IsChecked then paras.PostingBegin = camWatchdog end
if retDlg.PostingEnd.IsChecked then paras.PostingEnd = camWatchdog end
if retDlg.DeleteBegin.IsChecked then paras.DeleteBegin = camWatchdog end
if retDlg.DeleteEnd.IsChecked then paras.DeleteEnd = camWatchdog end
retTable = Bcc.RegisterCamObjCallbackFunctions(objID, paras)
end
end
-- Check the operation for machine comp and lead status
-- IMPORTANT: objID is being passed by BobCAD automatically to this function
function camWatchdog(objID)
objName = Bcc.GetCamObjName(objID)
--Bcc.ShowMessageBox("Watchdog working for "..objName)
-- Get the status of machine comp and leads for the registered operations
retTable = Bcc.GetCamObjParameters(objID, {{"Patterns", "machine_compensation"}, {"Leads", "leadin_type"}, {"Leads", "leadout_type"}})
-- Check to see if machine compensation is on at all --
if retTable["Patterns"]["machine_compensation"] ~= "Off" then
-- If both the lead in and lead out are vertical, prompt to fix it
if retTable["Leads"]["leadin_type"] == "Vertical" and retTable["Leads"]["leadout_type"] == "Vertical" then
-- Prompt the user they are using comp with no leads and ask to correct it
retDlg = Bcc.ShowMessageBox("Using machine comp with no lead-in or lead-out!\n\nWould you like to correct this?", {Title="Watchdog!", ButtonType="YesNo", ImageType="Question"})
-- If the user chooses yes --
if retDlg == 6 then
-- Set the lead in and lead out to blend types
setLeads = { Leads = {leadin_type = "Blend", leadout_type="Blend"} }
-- Update the operation parameters
Bcc.SetCamObjParameters(objID, setLeads)
end
end
end
end