Exporting set of tools as.ptf

Exporting set of tools as.ptf

anto_joseph4HH2K
Contributor Contributor
525 Views
2 Replies
Message 1 of 3

Exporting set of tools as.ptf

anto_joseph4HH2K
Contributor
Contributor

Hi ,

 

Can anyone advise me on how to export a set of tools used in a project as .ptf so i can call in these tools later in different projects.?

0 Likes
Accepted solutions (2)
526 Views
2 Replies
Replies (2)
Message 2 of 3

iamcdn79
Mentor
Mentor
Accepted solution

Make sure to just have your tools in the project, if you have workplanes, boundaries it might save that. When saving, save as .ptf

iamcdn79_0-1725975378338.png

 

When importing 

iamcdn79_1-1725975515304.png

 

 

 


Intel Core i9 13900KF CPU
128 GB Kingston Beast DDR4 SDRAM
PNY RTX A2000 6GB Video Card
WD 1 TB SSD Hard Drive
Windows 11 Pro

0 Likes
Message 3 of 3

TK.421
Advisor
Advisor
Accepted solution

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