The previous lesson generated two delay records, one of which references a recipe parameter. This lesson covers the next everyday tasks: inserting a record between existing instructions, copying an instruction, saving work for later editing, and using a program with its matching recipe.
We continue with the standard Teach page and its existing scripts. No new buttons or instructions are needed. Follow the operations first, then read the short scripts that make them work.
Open Teach and select Program on the left. The buttons below the program table form three rows: record selection and paging, record editing, then New, Save, Open and Load Code.
Click the screenshot to view the original image.
The close-up below makes the labels easier to read. Save and Open in this lesson refer to these buttons.
Click the screenshot to view the original image.
In a practice copy of the software, prepare the two records from the previous lesson:
G04P1250
G04PINT[#1550.item[0]*1000]
Recipe item 1 is Delay time, with a value of 2.5; item 2 is Alternate delay, with a value of 0.75. The first instruction has a fixed delay of 1.25 seconds. The second reads recipe item 1 when NC interprets the expression. See Teach recipe references for the generation steps.
Save any program and recipe you need to keep before starting. This lesson inserts and deletes records and uses New to clear the practice program. Do not perform these operations on unsaved production data.
Each program record uses the same item index in four fields of #1551:
| Field | Purpose | Record 1 in this example |
|---|---|---|
#1551.item[0] |
Code written to the NC file | G04P1250 |
#1551.itemdesc[0] |
Text shown in the program table | G04P1250 |
#1551.itemversion[0] |
Instruction type used when recalling the record | 7, Delay |
#1551.itemtitle[0] |
Editing data used to restore the inputs on the right | A0B0C1.250DfalseE1 |
Here, .itemtitle[...] holds editing data, rather than a title shown to the operator. The previous lesson explains the A–E markers.
Three other values identify the record position:
| Parameter | Meaning |
|---|---|
#1551 |
Current record index, starting at 0 |
#1551.itemnum |
Allocated record count, including an inserted record that does not yet contain code |
#1551.channel |
Current program-table page, starting at 0, with 10 items per page |
Thus, item 2 on screen is index 1. The table number selects a Teach record; it is not an NC N number. A Spatial Arc record can contain two lines of code, so deleting one record does not necessarily delete just one NC text line.
We will place a copy of the fixed delay between the two existing records:
Click the screenshot to view the original image.
Insert runs env/teach/insnodeonly. This is the complete script:
IF#1551>=#1551.itemnumGOTO1
#1500.channel=0
widgetFunc["insertSystemParamItem",1551,#1551,1]
N1
The first line checks whether the current position is beyond the existing records. At the empty position after the last record, there is no record to move down, so this button does not insert anything. The three numeric arguments to insertSystemParamItem specify parameter 1551, the insertion position and a count of 1.
Insertion moves the existing code, display text, type and editing data together, leaving an empty record at the current position. It does not generate a record from the inputs on the right. After making room, generate code or paste a complete record into that position.
To append at the end, select the first empty position after the last record and generate or paste there. You do not need to press Insert first.
Complete the insertion:
G04P1250; the recipe delay remains at item 3. The inputs on the right also return to a fixed value of 1.25 seconds.Click the screenshot to view the original image.
env/teach/copy contains just one line:
#1551.version=#1551
It remembers the source record index. Copying item 1 stores 0 in #1551.version. It does not place the content on the Windows clipboard or store a separate copy of the record at this point.
The complete env/teach/paste script is:
IF#1551.version>=#1551.itemnumGOTO1
IF#1551==-1THEN#1551.itemnum=1
IF#1551==-1THEN#1551=0
IF#1551>=#1551.itemnumTHEN#1551.itemnum=#1551+1
#1551.item[#1551]=#1551.item[#1551.version]
#1551.itemtitle[#1551]=#1551.itemtitle[#1551.version]
#1551.itemdesc[#1551]=#1551.itemdesc[#1551.version]
#1551.itemversion[#1551]=#1551.itemversion[#1551.version]
widgetFunc["SysFunc","0","parser","/env/teach/parsenode"]
N1
It checks the source position, increases the destination record count if needed, copies the four fields, and calls parsenode to restore the inputs on the right. Paste keeps the current position at the destination. It does not advance to the next item as delay-code generation does.
Keep these three rules in mind:
| Where or when you paste | Result |
|---|---|
| Onto an existing record | Replaces that record; does not insert automatically |
| Into the first empty position after the last record | Increases the count and appends a record |
| After modifying and regenerating the copied source record | Reads the new content now held at the source position |
For example, copy a 1.25-second record, then change its source record to 3 seconds and regenerate it. A subsequent paste produces G04P3000, not the G04P1250 present when you pressed Copy.
Insertion and deletion also change record positions. To add a record in the middle, insert first, then select the source again, copy, select the destination and paste. Do not copy, insert before the source, and assume the remembered index follows the original record. After creating a new program or opening another one, select a valid source and press Copy again.
Delete the duplicate at item 2: leave it selected, press Delete, then confirm. The recipe delay moves from item 3 to item 2.
Click the screenshot to view the original image.
The complete env/teach/delnode script is:
IF#1551>=#1551.itemnumGOTO1
IFwidgetFunc["messageBox1",#1107.itemtitle[40],#1107.itemtitle[23],"null.nc"]==0GOTO1
#1500.channel=0
widgetFunc["removeSystemParamItem",1551,#1551,1]
widgetFunc["SysFunc","0","parser","/env/teach/parsenode"]
N1
If the current position does not contain a valid record, the script ends. It also ends if the confirmation returns 0. Once deletion is confirmed, the code and its associated data are removed together, later records move up, and the current position is used to recall the inputs.
Here, messageBox1 returns the confirmation result for the script to check. Do not interchange it with other similarly named message functions.
Deleting the last item leaves the current position at the empty end position. The script does not automatically select the preceding record; select it again if you want to edit it. Insert, Delete, Copy and Paste operate on the current Teach data. They do not automatically save changes to a file.
The original two records are now ready to save for later editing:
delay.program, and save.delay.formula in the same folder.Click the screenshot to view the original image.
The recipe area has its own file, Copy and Paste buttons:
Click the screenshot to view the original image.
Using the same base name, such as delay.program and delay.formula, makes the pair easier to manage. This is a naming convention for your files: matching names do not cause the software to open both files automatically.
| File | Created by | Contents | Read by |
|---|---|---|---|
.program |
Save in the program controls | Parameter 1551, including code, display text, types, editing data and record-position information | Open in the program controls |
.formula |
Save recipe | Parameter 1550, including recipe names and values | Load recipe |
program.nc |
Load Code in the program controls | Recorded NC code text | Displayed on the Program page by the same operation |
.program and .formula are the software's parameter files, not editable G-code text. Do not modify them with a text editor or change their extensions to use one as the other. Saving writes the whole corresponding parameter record, rather than only a few lines of displayed text.
The original Save button opens a file selection window each time. Even after an earlier save, confirm the destination and filename for this save. Use a new name to retain an earlier version.
We will deliberately change the recipe, then reopen the two files to see their separate roles.
In the recipe table, change the first value to 9 and press Enter. Do not save this recipe change. Return to Program, press New, and confirm that the records should be cleared.
Click the screenshot to view the original image.
The original env/teach/newfile script is:
IFwidgetFunc["messageBox1",#1107.itemtitle[41],#1107.itemtitle[23],"null.nc"]==0GOTO1
#1551.itemnum=0
#1551=0
#1551.channel=0
N1
It clears the records and sets the current index and page to 0. It does not delete saved files or clear the recipe in #1550. These three assignments do not clear the instruction's working parameters either. A value still visible on the right does not mean its record still exists.
Press Open and select the saved delay.program:
Click the screenshot to view the original image.
The inputs on the right return to Recipe Parameter Index and Delay time, because record 2 saved the data source and recipe index:
Click the screenshot to view the original image.
Switch to Recipe. The first value is still 9:
Click the screenshot to view the original image.
Press Load recipe and select delay.formula. Only then does the first value return to 2.5; the second remains 0.75:
Click the screenshot to view the original image.
When using a saved pair, open the program and load the recipe separately. Then check each referenced item's position, purpose, unit and value. A matching name alone is insufficient: if the position or purpose changes, #1550.item[0] may read unsuitable data.
Save runs env/teach/savefile:
widgetFunc["saveFileName","*.program","",100]
IF#100==""GOTO1
#1551.description=#100
N2
widgetFunc["SysFunc",#1551.description,"saveParamItemAs1",1551]
widgetFunc["messageBox",#1107.itemtitle[42],"",""]
N1
saveFileName opens the save window. *.program is the file filter, and 100 identifies the temporary path parameter #100. After a path is selected, it is placed in #1551.description. saveParamItemAs1 then writes the whole parameter 1551 to that file. No statement jumps to N2 here; that label does not start a second save operation.
Open runs env/teach/openfile:
widgetFunc["openFileName","*.program","",100]
IF#100==""GOTO1
#1551.description=#100
widgetFunc["SysFunc",#1551.description,"readParamItemFrom1",1551]
N1
widgetFunc["SysFunc","0","parser","/env/teach/parsenode"]
readParamItemFrom1 replaces parameter 1551 with the file's data. It does not append records to the end. parsenode then restores the inputs for the restored current record. Changing an input on the right without pressing Generate code line does not update the record being saved.
Recipe files use the same file commands with parameter 1550 instead. The write command in env/teach/saveformula is:
widgetFunc["SysFunc",#1550.description,"saveParamItemAs1",1550]
The complete env/teach/openformula script is:
widgetFunc["openFileName","*.formula","",100]
IF#100==""GOTO1
#1550.description=#100
widgetFunc["SysFunc",#1550.description,"readParamItemFrom1",1550]
#1550.version=#1550.itemnum
N1
The last assignment updates Recipe sheet parameters number: to the actual item count read from the file. This script does not call parsenode or rewrite the Teach records in #1551.
These scripts do not ask separately whether to save current changes before opening a file. Save anything you want to keep before opening another file. The calling script determines the destination parameter number; changing an extension does not convert one parameter file into another.
The standard scripts use #100 as the file-selection result, but the two selection functions handle cancellation differently:
| Operation | What Cancel does to #100 |
Effect on the original script |
|---|---|---|
saveFileName |
Writes an empty string | The save script skips writing the file |
openFileName |
Leaves its previous value; the current function returns an empty string | If #100 still holds an old path, the open script may read that path again |
For example, open delay.program, change record 1 to 4 seconds and generate it, then press Open again but cancel the selection window. Because #100 still holds the path to delay.program, the original script reads it again. Record 1 returns to the saved G04P1250. Load recipe uses the same selection function and check, so it has the same issue.
Do not rely on cancelling an open window to protect unsaved changes. Save the data you need before opening or loading. If values return to an earlier state after cancellation, check whether the previously selected file was read again.
Also, openfile still calls parsenode after N1. Even when no file is read, the current record may refill the inputs on the right. Cancelling an open operation is not a way to retain input changes that have not been generated into a record.
When reading or customizing similar scripts, distinguish the current function's return value from a path parameter left by an earlier operation. Detect cancellation from the current selection result, rather than merely checking whether a stored path is nonempty.
After restoring both files, switch back to Program and press Load Code. The Program page displays:
Click the screenshot to view the original image.
The output command in env/teach/codeGenerate is:
widgetFunc["systemParamToFile",1551,0,"/env/teach/doc/program.nc"]
It writes the nonempty code text in #1551.item[...] in order. It does not rerun each Teach generation script, include the editing data from .itemtitle[...], or substitute fixed numbers for current recipe references.
The complete everyday sequence is:
.program file. Save the .formula file separately if its recipe has changed.If you edit records after loading, load the code again. Saving .program does not automatically update the program.nc already displayed. If only a referenced recipe value changes, the code can remain unchanged, but confirm the current recipe before machining.
Load Code outputs and displays a file; it does not start machining. A plain .nc file also cannot automatically restore all the Teach editing data described here. Keep .program to continue editing through Teach, and keep its corresponding .formula when using recipe references.
The recipe buttons run env/teach/formulacopy and env/teach/formulapaste.
The copy script is:
#1550.permission=#1550
This feature uses .permission to remember the source index. Its field name alone does not mean this assignment changes a user's access rights.
The paste script is:
IF#1550.permission>=#1550.itemnumGOTO1
IF#1550>=#1550.itemnumGOTO1
#1550.item[#1550]=#1550.item[#1550.permission]
#1550.itemtitle[#1550]=#1550.itemtitle[#1550.permission]
N1
It copies only the recipe value and name. It does not copy a Teach instruction or automatically increase the recipe count. If you need more positions, prepare them first using the recipe-count input.
For example, copying item 1 onto item 2 changes item 2's name and value to Delay time and 2.5. Alternate delay and 0.75 are overwritten. Any existing [1] reference still selects item 2, but now reads different content. Recipe Paste therefore does more than copy a name.
Recipe Copy also remembers a source position. If that source changes before Paste, the new value is copied. After loading another recipe, select the source and copy it again.
Teach lets the operator enter parameters, generate records, then save editable data or output NC code. This explains why “the input changed,” “the record changed,” “the file was saved” and “the machining file was updated” are different states.
| What you see | What to check |
|---|---|
| Insert leaves an empty row | Insert only makes room; generate or paste a record |
| Paste replaces an instruction | The destination already held a record; insert first to preserve it |
| Paste differs from the value present when Copy was pressed | Copy remembers an index; the source content or position may have changed |
| Reopening loses an input change | Was Generate code line pressed before saving? |
| Recipe values remain after New | New clears Teach records; recipe data is managed separately |
| A reopened program uses an unexpected delay | Was the matching recipe loaded, and does the referenced index match? |
| Changes disappear after cancelling Open | Check for a reread of the previous path or a recall of the current record |
| The Program page still shows old code after Save | Was Load Code used again after saving the data? |
| Only NC remains and the original parameter choices cannot be restored | NC holds code; use the saved program data to continue editing in Teach |
For similar configuration features, keep working inputs separate from confirmed records. Store code and recall data together for each record. Move, delete and copy the related data together. Manage the editable file separately from the code file used for machining.
The main files are env/teach/teach.ui, insnodeonly, copy, paste, delnode, newfile, savefile, openfile, saveformula, openformula, formulacopy, formulapaste, parsenode and codeGenerate. The original scripts in this chapter explain the existing feature; you do not need to create additional files with these names.
You can now follow Teach from parameter entry through records, recipes, saved files and NC output. For execution of that output, review machining controls. The next subject is the existing Machining Wizard: generating a complete toolpath from dimensions.