Frequently asked questions
How do I loop through all the toolpath entities?
The folder() function returns all the items that are in the Explorer folders, for example Machine Tools, Toolpaths, Tools, Boundaries, Patterns etc.. The easiest way to loop through all the items is to use the FOREACH statement:
FOREACH tp IN folder(‘Toolpath’) {
PRINT = tp.name
}
The folder function returns all the items in the specified folder and in any subfolders. You can limit the number of items returned by specifying a specific subfolder to loop through:
FOREACH tp IN folder(‘Toolpath\semi-finishing’) {
PRINT = tp.name
}
How do I only loop over the items in a parent folder (and exclude any subfolders)?
As described above, the folder() function returns items from a parent folder and any subfolders. If you only want to loop over the items in the parent folder, you need to filter the results. For example, if you have the folder 'Semi-finishing' and the subfolder 'Not used', which contains temporary or alternative toolpaths, then to access the toolpaths only in the 'Semi-finishing' folder, you need to use the pathname and dirname functions:
STRING fld = ‘Toolpath\semi-finishing’
FOREACH tp IN folder($fld) {
IF dirname(pathname(tp)) == $fld {
PRINT = tp.name
}
}
You can also achieve the same result as above by using a complex expression for the FOREACH loop. In some cases this may make your code easier to understand and in other cases much harder. In the following example, the results of the folder() function are filtered so the IF statement can be removed.
STRING fld = ‘Toolpath\semi-finishing’
STRING filt = ‘dirname(pathname(this)) == fld’
FOREACH tp IN filter(folder($fld), $filt) {
PRINT = tp,name
}
How do I loop over the items in the active folder?
The inbuilt function active_folder() returns the name of the folder that is currently active in the Explorer.
STRING fld = active_folder()
IF fld == "" {
// No active folder use the root instead
$fld = ‘Boundary’
} ELSEIF position(fld,’Boundary\’) != 0 {
MESSAGE "Active folder isn’t a boundary folder"
RETURN
}
How can I tell if a toolpath has been calculated?
The Toolpath’s parameter 'Computed' is be true if it has been calculated. Sometimes a toolpath may have been calculated but contain no cutting segments. If this is an issue then you should check the number of segments as well:
IF tp.Calculated AND segments(tp) > 0 {
PRINT "Toolpath is calculated and has segments"
}