Good Day,
I'm trying to create this macro to export selected tools as *.ptf files to a location and drop them into folders based on their tool type, but It's not working for me, any ideas where I'm going wrong.
Thanks Jon K
DIALOGS MESSAGE OFF
DIALOGS ERROR OFF
GRAPHICS LOCK
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
STRING $pmlprj_content = ""
FOREACH $tl IN explorer_selected_entities() {
IF $tl.type == 'tip_radiused' {
STRING $template_path = "C:\Powermill\Template Objects\Tools\Tip Radiused"
}ELSE IF $tl.type == 'routing' {
STRING $template_path = "C:\Powermill\Template Objects\Tools\Routing"
STRING $tool_name = "x" + $tl.ID + ".pmlent"
STRING $tool_name_new = $tl.Name + ".ptf"
STRING $tool_full = project_pathname(0) + "\" + $tool_name
STRING $dest_path_full = $template_path + "\" + $tool_name_new
COPY FILE $tool_full $dest_path_full
}
}
DIALOGS MESSAGE ON
DIALOGS ERROR ON
GRAPHICS UNLOCK
Solved! Go to Solution.
Solved by icse. Go to Solution.
Does this work?
DIALOGS MESSAGE OFF
DIALOGS ERROR OFF
GRAPHICS LOCK
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
STRING $pmlprj_content = ""
FOREACH $tl IN explorer_selected_entities() {
IF $tl.type == 'tip_radiused' {
STRING $template_path = "C:\\Powermill\\Template Objects\\Tools\\Tip Radiused"
} ELSE IF $tl.type == 'routing' {
STRING $template_path = "C:\\Powermill\\Template Objects\\Tools\\Routing"
}
STRING $tool_name = "x" + $tl.ID + ".pmlent"
STRING $tool_name_new = $tl.Name + ".ptf"
STRING $tool_full = project_pathname(0) + "\\" + $tool_name
STRING $dest_path_full = $template_path + "\\" + $tool_name_new
COPY FILE $tool_full $dest_path_full
}
DIALOGS MESSAGE ON
DIALOGS ERROR ON
GRAPHICS UNLOCK
Change to
} ELSEIF $tl.type == 'routing' {
I can't test it atm but somethimes checking enums in powermill in a loop/if statement does not work correctly try to create a string variable first and check those.
try this:
DIALOGS MESSAGE OFF
DIALOGS ERROR OFF
GRAPHICS LOCK
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
STRING $pmlprj_content = ""
FOREACH $tl IN filter(explorer_selected_entities(),'this.RootType == "tool"') {
string $e = $tl.type
IF $e == 'tip_radiused' {
STRING $template_path = "C:\\Powermill\\Template Objects\\Tools\\Tip Radiused"
} ELSE IF $e == 'routing' {
STRING $template_path = "C:\\Powermill\\Template Objects\\Tools\\Routing"
}
STRING $tool_name = "x" + $tl.ID + ".pmlent"
STRING $tool_name_new = $tl.Name + ".ptf"
STRING $tool_full = project_pathname(0) + "\\" + $tool_name
STRING $dest_path_full = $template_path + "\\" + $tool_name_new
COPY FILE $tool_full $dest_path_full
}
DIALOGS MESSAGE ON
DIALOGS ERROR ON
GRAPHICS UNLOCK
also added a filter to the explorer selected enties so it does only work with tools
Close, reopen the project and rerun the macro
Ok, I fiddled around with the code a bit, so when I select routing tools and run the macro it puts them into the correct folder, however when I select tip radiused tools it fails to populate the correct folder.
DIALOGS MESSAGE OFF
DIALOGS ERROR OFF
GRAPHICS LOCK
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
STRING $pmlprj_content = ""
FOREACH $tl IN filter(explorer_selected_entities(),'this.RootType == "tool"') {
string $e = $tl.type
IF $e == 'tip_radiused' {
STRING $template_path = "C:\Powermill\Template Objects\Tools\Tip Radiused"
} ELSEIF $e == 'routing' {
STRING $template_path = "C:\Powermill\Template Objects\Tools\Routing"
STRING $tool_name = "x" + $tl.ID + ".pmlent"
STRING $tool_name_new = $tl.Name + ".ptf"
STRING $tool_full = project_pathname(0) + "\" + $tool_name
STRING $dest_path_full = $template_path + "\" + $tool_name_new
COPY FILE $tool_full $dest_path_full
}
}
DIALOGS MESSAGE ON
DIALOGS ERROR ON
GRAPHICS UNLOCK
I looked it up in the debugger found some bugs, the $template_path variable is declared in the if statement and gets lost if the if block is closed also some {} where wrong.
I updated the macro so it works with every tool type out of the box:
if length(project_pathname(0)) == 0 OR project_modified() == 1 {
bool $save = 0
$save = query 'Save?'
if $save {
project save
} else {
return
}
}
foreach $t in filter(explorer_selected_entities(),'this.RootType == "tool"') {
string $template_path = 'C:/Powermill/Template Objects/Tools/' + $t.type
STRING $tool_name = "x" + $t.ID + ".pmlent"
STRING $tool_name_new = $t.Name + ".ptf"
STRING $tool_full = project_pathname(0) + "/" + $tool_name
STRING $dest_path_full = $template_path + "/" + $tool_name_new
if not dir_exists($template_path) {
mkdir ${template_path}
}
COPY FILE ${tool_full} ${dest_path_full}
}
You may have to change the / to \ in the path variable.
Thanks so much, I've been wanting to migrate away from using the tool database and this has tidied up that decision.
Best Regards Jon K
Can't find what you're looking for? Ask the community or share your knowledge.