Hi, I'm pretty new to making macros within powermill and would like some help. I am trying to write a macro that reads through all the toolpaths and checks if they are within a NC program. If not I'd like it to tell me which program is not posted and if they are all posted then I would like a message of "ok". This is what I have so far, the macro can't tell if my toolpaths are in the NC programs or not. It returns with a message of "ok" for all my toolpaths even though some are in the NC programs and some are not.
STRING $Path = dirname(pathname(toolpath))
STRING $NC = dirname(pathname(NCProgram))
FOREACH toolpath IN folder ("TOOLPATH") {
IF $Path != $NC {
STRING MSG = "TOOLPATH $toolpath.name NOT POSTED"
MACRO PAUSE $MSG
} ELSE {
STRING MSG1 = "OK"
MACRO PAUSE $MSG1
}
}
Solved! Go to Solution.
Solved by kandennti. Go to Solution.
Hi @Richard.CNC
try something like this
FORM COLLISION
DIALOGS MESSAGE OFF
DIALOGS ERROR OFF
// TOOLBAR COMMANDBAR RAISE
STRING LIST $trcfile = {}
string $msg = ""
echo off
tracefile open c:\temp\MultiCheckStatus.txt
FOREACH $Selected_TP IN (explorer_selected_entities()) {
$$Exit if the selected entities are not NCprograms
IF $Selected_TP.RootType != "toolpath" {
DIALOGS MESSAGE ON
DIALOGS ERROR ON
break
}
ACTIVATE Toolpath $Selected_TP.name
EDIT COLLISION TYPE COLLISION
EDIT COLLISION STOCKMODEL_CHECK N
EDIT COLLISION SCOPE ALL
EDIT COLLISION SPLIT_TOOLPATH N
EDIT PAR 'Verification.UseVerificationThickness' 0
EDIT COLLISION HOLDER_CLEARANCE "0.5"
EDIT COLLISION SHANK_CLEARANCE "0.5"
EDIT COLLISION DEPTH Y
EDIT COLLISION ADJUST_TOOL N
Print = 'Toolpath: ' + $entity('toolpath','').name
EDIT COLLISION APPLY
// project save // comenta esta linha se não for necessario gravar a cada verificação
}
// project save // comenta esta linha se não for necessario gravar no final
tracefile close
FILE OPEN "c:\temp\MultiCheckStatus.txt" FOR READ AS input
FILE READ $trcfile FROM input
FILE CLOSE input
FOREACH line IN trcfile {
$msg = $msg + $line + crlf
}
MESSAGE INFO $msg
DIALOGS MESSAGE ON
DIALOGS ERROR ON
Hey @rui_rita thanks for the reply, but I am not looking to verify the tool to make sure it is safe. I'm trying to get powermill to see what toolpaths I have written and to check that they are in a NC program. There are times where I have a lot of toolpaths and I forget to put some of them into a NC program. Any help would be greatly appreciated, thanks.
Hi @Richard.CNC
My bad... I read "check" and in my mind i thoug you wanted to verify...
here it is
string $msgNotPosted = ""
string $msgOK = ""
FOREACH tp IN folder ("toolpath") {
IF NOT entity_exists('ncprogram', tp.name) {
$msgNotPosted = $msgNotPosted + "TOOLPATH: ' "+ $tp.name + " ' NOT POSTED" + CRLF
} ELSE {
$msgOK = $msgOK + "TOOLPATH: ' "+ $tp.name + " ' OK" + CRLF
}
}
if $msgOK == "" {
message info "NONE TOOLPATH IS POSTED"
} else {
macro pause $msgOK
}
if $msgNotPosted == "" {
message info " EVERY TOOLPATH IS POSTED"
} else {
MACRO PAUSE $msgNotPosted
}
@rui_rita The macro is almost what I wanted it to be. I need "tp.name" code in the macro changed so that it will look at the toolpaths within the NC programs and not the title of the actual NC program itself. Right now it's looking at the name of the NC program and not reading the toolpaths that are in the NC program, and therefore telling me that the programs aren't posted. I can't figure out what the code is for that. I've attached a picture for reference. Thanks
Hi rich.ng89
I think that if the number of times to reference entities and objects is fewer, the macro will handle it faster.
//pm2018 macro //Find_Toolpath_not_registered_in_NCProgram.mac function main() { //all toolpath string list all_tps = extract(folder('toolpath'), 'name') //Ncprogram use toolpath string list nc_tps = extract(flatten(extract(folder('ncprogram'), 'nctoolpath')), 'name') //Toolpath_not_registered_in_NCProgram string list non_regist_tps = subtract($all_tps, $nc_tps) if size($non_regist_tps) > 0 { string msg = join($non_regist_tps, crlf) INFOBOX NEW "***** Not_registered_in_NCProgram *****" INFOBOX CLEAR FORMAT INFOBOX STYLE "NORMAL" INFOBOX APPEND $msg } message info 'Done' }