Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Saving Template Objects

TK.421
Advisor

Saving Template Objects

TK.421
Advisor
Advisor

after my project is loaded with workplanes, toolpaths and nc programs, is there a means I can export only the tools as a template object without having to delete everything else? I dont want to use tool database, only template objects.

 

thanks!

David


the numbers never lie
Reply
Accepted solutions (3)
3,100 Views
20 Replies
Replies (20)

rafael.sansao
Advisor
Advisor

All tools in a single ptf? I do not know a way to do that.
One file for each tool is possible.

 

EDIT

I figured out how to do it. It is not a very simple solution. Let's wait and see if a simple solution is suggested.

Rafael Sansão

OptiNC - www.optinc.tech

EESignature

iamcdn79
Mentor
Mentor

Is the problem when you import the template file that you have the toolpaths, boundaries in it as well?

 

If it is you could make a macro that deletes everything except your tools after importing the file.


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

TK.421
Advisor
Advisor

Thank you guys both for the reply!

 

I thought of doing @iamcdn79 's solution, but sometimes I import templates when I am halfway through my project so I would have to build into the macro logic to keep any current entities that I already have. I was curious to see if there is a way to do it on the front end when I save the template objects. @rafael.sansao , what was your thought, if it doesnt take too much to explain?

 

 


the numbers never lie
0 Likes

rafael.sansao
Advisor
Advisor
Accepted solution

@iamcdn79 Importing the complete project and then deleting everything that is not a tool would work, but it is not a good solution.

 

 

@TK.421 Try this:

 

For export:

STRING $template_path = "C:\temp\template_tools"
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 template saved successfully."

For import:

PROJECT IMPORT "C:\temp\template_tools"

Rafael Sansão

OptiNC - www.optinc.tech

EESignature

5axes
Advisor
Advisor

Hello @TK.421 ,

 

Herewith my solution : I'm using 5 macros to manage tool  via the pmlent native format.  Every Tool element are export into a folder depending of the current stockmaterial.  You can save every tool of your project into this folder, It's fast and you are not oblige to have all your tool into a Pmill Project to update your "Tool database". 

 

SaveTool : Save every tool into the folder "C:\(MACRO_PATH)\Lib_Tool_PmlEnt\(StockMat)"

LoadTool : Load every tool define in the folder "C:\(MACRO_PATH)\Lib_Tool_PmlEnt\(StockMat)" into your current project

 

RazTool : Delete every tool define in the folder "C:\(MACRO_PATH)\Lib_Tool_PmlEnt\(StockMat)" ( Used  mainly to redefine a 'Fresh' library from the current project )

 

RenomeOutil : Saving the tool only under his pmlent format doesn't store the folder information, so this macro is used after the import to replace the tool into his original folder . You must of course use the macro ResetUserParamOutil to create initialy the user parameters Ident & Folder 

 

S
I "Export Tool PmlEnt" 1 "MACRO 'SaveTool.mac'"
I "Import Tool PmlEnt" 1 "MACRO 'LoadTool.mac'"
I "Delete All Tool PmlEnt" 1 "MACRO 'RazTool.mac'"
I "Rename All Tool with user param" 1 "MACRO 'RenomeOutil.mac'"
I "Reset user param all Tool" 1 "MACRO 'ResetUserParamOutil.mac'"

Using the PmlEnt format offer you also the possibility to import tool one by one if you want ( Joined Video).

0 Likes

TK.421
Advisor
Advisor

thank you guys for all your responses! I will look these over today and provide my feedback on them.  I've been shorthanded here for several months (hence my minimal activity on the forum) so it may take some time for me to respond.

 

I appreciate each of you taking time to post your thoughts and codes!

David

<><


the numbers never lie

Anonymous
Not applicable

This is  one that has always bugged me as well. Why no option to save the tool on its own ? .

I also do not use the tool database.

What i do when i add a tool to a project is to save the tool path as a strategy with the new tool.

I then open a fresh PM and load in the strategy.

Strip out the tool path leaving only the tool then save it with template objects.

If you have a few to do it doesn't take long tbh.

 

Ken

0 Likes

Anonymous
Not applicable

The attached macro saves all tools in a single .ptf file.
What's really interesting about it is the "FUNCTION FileSaveDialog (STRING StartDir, STRING Prompt, STRING Filter, OUTPUT STRING Result)" which can be used well in other macros.

0 Likes

TK.421
Advisor
Advisor

I like @rafael.sansao 's solution. It is closest to what I've been using in that I give it a name and that's it. i tend to save cutter templates as I go and I keep them for a long time to use on similar jobs. this way i have them stored on the server and can choose them via pull down menu.

 

@5axes , your macros are very cool indeed, but they are more than I need for this particular purpose. I do not use stock material ever, so I'm sure I was not using your macros to their full extent or capability.

 

Thanks again for all the replies and help!

David

<><


the numbers never lie

TK.421
Advisor
Advisor

@rafael.sansao should this work for toolpaths, too? I tried changing everywhere the tool folder or pmlEntTool was referenced, I'm sure I didnt miss anything this time as I did with the workplane. when I go to load the project, i get that project failed to load warning complete with a variety pack of possible explanations. are toolpaths different than other entities in this regard?

 

STRING $template_name = INPUT "Save Toolpath Template As..."
STRING $template_path = "S:\Administration\Software\PowerMill\Templates\Toolpath Templates\" + $template_name
IF $length(project_pathname(0)) == 0 {
	MESSAGE WARN 'Save project first.'
	MACRO ABORT ALL
}
IF $SIZE(folder('Toolpath')) == 0 {
	MESSAGE WARN 'No toolpaths 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('Toolpath') {
	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 + " pmlEntToolpath '" + $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('Toolpath')) + 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 "Toolpath template saved successfully."

the numbers never lie
0 Likes

rafael.sansao
Advisor
Advisor
Accepted solution

Yes. You need to create the active_entity file
Add this before the "MESSAGE INFO"

STRING $dest_path_act = $template_path + "\active_entity.pmldat"
FILE OPEN $dest_path_act FOR WRITE AS output
$L1 = "0 0 # Active Entities (DO NOT EDIT!)"
FILE WRITE $L1 TO "output"
FILE CLOSE output

Rafael Sansão

OptiNC - www.optinc.tech

EESignature

0 Likes

TK.421
Advisor
Advisor

that didn't quite do it, leaving the original code the way it was, and inserting your above code as prescribed when i went to load it. if i open the file and drag the pmlprj file into powermill, it'll load the toolpaths and then give me a warning saying each toolpath is missing its dat file. all the toolpaths are still calculated which is not a huge deal, i can invalidate them and remove their workplanes (which are also created upon toolpath activation).

 

Is this expected behavior? I've never messed around with any of these files, so this is new to me.

 

I can make this work as is, but if there is a better way to do it, let me know!

 

thanks again!


the numbers never lie
0 Likes

rafael.sansao
Advisor
Advisor

You can save the toolpath templates instead of copying the .pmlent file.
Just save the template of each toolpath and rename it with the same name as the .pmlent file.

Rafael Sansão

OptiNC - www.optinc.tech

EESignature

0 Likes

TK.421
Advisor
Advisor

Hi @rafael.sansao ,

 

I'm back on this again. I'm using your above idea to save individually the toolpath templates. I've been trying for a while now to get powermill to save the template with the correct name, but all it outputs is '$filePath' to the directory. how do I get it to save the template name with the value that is in $filePath?

 

STRING template_name = INPUT "Save Toolpath Objects As..."
STRING template_path = "S:/Administration/Software/PowerMill/Templates/Toolpath Templates/" + $template_name

IF NOT dir_exists(template_path) {
    MKDIR $template_path
}

EDIT TEMPLATESAVE SAVEPATH $template_path

FOREACH tp IN explorer_selected_entities() {
    STRING filePath = $template_path + "/" + $tp.ID + ".ptf"
    KEEP ADVTOOLPATH $tp.name FILESAVE "'" + $filePath + "'"
}

 

EDIT:

I've tried

KEEP ADVTOOLPATH $tp.name FILESAVE "'" + $filePath + "'"
KEEP ADVTOOLPATH $tp.name FILESAVE $filePath

and many other variations...


the numbers never lie
0 Likes

rafael.sansao
Advisor
Advisor
Accepted solution
KEEP ADVTOOLPATH $tp.name $filePath

Rafael Sansão

OptiNC - www.optinc.tech

EESignature

0 Likes

TK.421
Advisor
Advisor

*bangs head against desk*

 

thanks brother


the numbers never lie

Anonymous
Not applicable

how to recalculate only the selected route?

 

0 Likes

TK.421
Advisor
Advisor

FOREACH ent IN explorer_selected_entities() {

     ACTIVATE TOOLPATH $ent.Name

     EDIT TOOLPATH ; CALCULATE

}


the numbers never lie
0 Likes

urizenYHS3W
Advocate
Advocate

Having saved your project you can read the .pmlprj file into a string list and discard the first three lines. Then cycle over the rest and look for any lines that contain pmlEntTool. Use IMPORT FROM to read the tool entity file

 

DELETE ALL YES

STRING $proj_name = "\" + project_pathname(1) + ".pmlprj"
STRING $path_full = project_pathname(0) + $proj_name
FILE OPEN $path_full FOR READ AS input
STRING LIST $proj = {}
FILE READ $proj FROM input
FILE CLOSE input

STRING $line = remove_first($proj)

$line = remove_first($proj)

$line = remove_first($proj)
FOR $line in $proj {
  STRING LIST items = tokens(line)
  IF items[1] == "pmlEntTool" {
    IMPORT FROM ${project_name(0) + "\" + $items[0]

  }

}

 

 

 

0 Likes