Here's the macro I use, you'll just have to change the file paths.
To Export (make sure project is saved):
FUNCTION MAIN() {
STRING $template_name = INPUT "Save Tool Template As..."
STRING $template_path = "S:/Software/PowerMill/Templates/Tool Templates/" + $template_name
IF $length(project_pathname(0)) == 0 {
MESSAGE WARN 'Save project first.'
MACRO ABORT ALL
}
IF $SIZE(folder('tool')) == 0 {
MESSAGE WARN 'No tools in project.'
MACRO ABORT ALL
}
PROJECT SAVE
IF dir_exists($template_path) {
DELETE DIRECTORY $template_path
}
MKDIR $template_path
STRING $pmlprj_content = ""
FOREACH t IN folder('Tool') {
// FOREACH t IN folder('Workplane') {
STRING $tool_name = "x" + $t.ID + ".pmlent"
STRING $tool_full = project_pathname(0) + "/" + $tool_name
STRING $dest_path_full = $template_path + "/" + $tool_name
COPY FILE $tool_full $dest_path_full
$pmlprj_content = $pmlprj_content + $tool_name + " pmlEntTool '" + $t.Name + "'" + CRLF
// $pmlprj_content = $pmlprj_content + $tool_name + " pmlEntWorkplane '" + $t.Name + "'" + CRLF
}
STRING $proj_name = "/" + project_pathname(1) + ".pmlprj"
STRING $path_full = project_pathname(0) + $proj_name
FILE OPEN $path_full FOR READ AS input
STRING L1 = ""
STRING L2 = ""
STRING L3 = ""
FILE READ $L1 FROM input
FILE READ $L2 FROM input
FILE READ $L3 FROM input
FILE CLOSE input
$L1 = $SIZE(folder('tool')) + substring($L1, position($L1, " ", 0), length($L1))
// $L1 = $SIZE(folder('workplane')) + substring($L1, position($L1, " ", 0), length($L1))
STRING $dest_path_full = $template_path + $proj_name
FILE OPEN $dest_path_full FOR WRITE AS output
FILE WRITE $L1 TO "output"
FILE WRITE $L2 TO "output"
FILE WRITE $L3 TO "output"
FILE WRITE $pmlprj_content TO "output"
FILE CLOSE output
MESSAGE INFO "Tool objects saved successfully."
}
To Import:
FUNCTION MAIN() {
// Create a list of ptf files including the full folder path.
STRING LIST $ptf_files = list_files('dirs', 'S:\Software\PowerMill\Templates\Tool Templates')
// Create a new list "$Template_Names" without the pathname included. Only the filename.
STRING LIST $Template_Names = {}
FOREACH $File IN $ptf_files {
INT $Ok = add_last($Template_Names, TOKENS($File, "/")[SIZE(TOKENS($File, "/"))-1])
}
// Display only the "$Template_Names" in your pulldown list
INT LIST $C = INPUT CHOICE MULTIPLE $Template_Names "Select File"
// Import file(s) from the original list which includes the full pathname
foreach file IN C {
PROJECT IMPORT ${$ptf_files[$file]}
}
}
Put these on a button on your custom ribbon tab.
the numbers never lie