Here are two macros that I use to save out tools from a project and then load them into another project. A couple notes: The project has to be saved first, and the path that it writes/reads from is hard coded.
The saving macro:
Code: Select all
//----------------------------------------------------------------//
// This macro saves template cutters from current project. //
// written by David 09/21/2017 //
// Jesus is Lord! //
//----------------------------------------------------------------//
// UPDATES //
// //
// 03/01/2019 - DRA - Updated logic to make more robust. Special //
// thanks to Rafael Sanso for the assistance. //
//----------------------------------------------------------------//
// Some functions used in this macro may be located another file. //
// If there is an error or the macro does not function properly, //
// please report it to the developer: adamcadcam@pm.me //
//----------------------------------------------------------------//
// This macro and all included functions and code is/are the //
// intellectual property of David R.W. Adam. Any unauthorized //
// copy or use of these without expressed permission is strictly //
// prohibited. //
//----------------------------------------------------------------//
reset localvars
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') {
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
}
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))
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."
}
Code: Select all
//----------------------------------------------------------------//
// This macro imports template cutters from selected file. //
// written by David 09/21/2017 //
// Jesus is Lord! //
//----------------------------------------------------------------//
// UPDATES //
// //
// 03/01/2019 - DRA - Loads project file (containing tools only) //
// from server //
// 04/21/2022 - DRA - Code changed to select & import multiple //
// files //
//----------------------------------------------------------------//
// Some functions used in this macro may be located another file. //
// If there is an error or the macro does not function properly, //
// please report it to the developer: adamcadcam@pm.me //
//----------------------------------------------------------------//
// This macro and all included functions and code is/are the //
// intellectual property of David R.W. Adam. Any unauthorized //
// copy or use of these without expressed permission is strictly //
// prohibited. //
//----------------------------------------------------------------//
reset localvars
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]}
}
}