<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Tool Replace Macro Help in PowerMill Forum</title>
    <link>https://forums.autodesk.com/t5/powermill-forum/tool-replace-macro-help/m-p/9107827#M13635</link>
    <description>&lt;P&gt;Thank you , this will help&lt;/P&gt;</description>
    <pubDate>Fri, 25 Oct 2019 06:54:27 GMT</pubDate>
    <dc:creator>James-b123</dc:creator>
    <dc:date>2019-10-25T06:54:27Z</dc:date>
    <item>
      <title>Tool Replace Macro Help</title>
      <link>https://forums.autodesk.com/t5/powermill-forum/tool-replace-macro-help/m-p/9105258#M13633</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I want to be able to activate a tool... it then find the toolpaths which this tool is present in. then a prompt to say what tool I want to replace it with (with same geometry) from a drop down.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is this possible with a macro?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 07:25:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/powermill-forum/tool-replace-macro-help/m-p/9105258#M13633</guid>
      <dc:creator>James-b123</dc:creator>
      <dc:date>2019-10-24T07:25:05Z</dc:date>
    </item>
    <item>
      <title>Re: Tool Replace Macro Help</title>
      <link>https://forums.autodesk.com/t5/powermill-forum/tool-replace-macro-help/m-p/9105615#M13634</link>
      <description>&lt;P&gt;&lt;FONT&gt;Not a complete solution, just a sketch:&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;IF NOT entity_exists('tool','') {
   RETURN
}
ENTITY T1=entity('tool','')
DIALOGS MESSAGE OFF
STRING FLT="Tool.Name == '"+$t1.Name+"'"
STRING LIST Toolpaths=extract(filter(folder('toolpath'),$FLT),'Name')
IF error($Toolpaths) {
   RETURN
}
$FLT="(diameter == "+$T1.Diameter+") AND (name !='"+$T1.Name+"') AND (type == '"+$t1.Type+"')"
SWITCH $T1.Type {
   CASE 'tip_radiused'
   $FLT=$FLT+" AND (tipradius == "+$T1.Tipradius+")"
   break
   CASE 'drill'
   $FLT=$FLT+" AND (DrillAngle == "+$T1.DrillAngle+")"
   break
   CASE 'end_mill'
   CASE 'ball_nosed'
   CASE 'form'
   DEFAULT
// nothing
}
STRING LIST RepTools=extract(filter(folder('tool'),$flt),'Name')
IF size($repTools) == 0 {
   RETURN
}
FOREACH TP IN $Toolpaths {
   STRING Prompt="Please select replace tool for toolpath "+$TP
   INT I=INPUT CHOICE $RepTools $Prompt
   IF NOT ERROR($I) {
      STRING Cmd="EDIT TOOLPATH '"+$TP+"' REPLACE_TOOL '"+$RepTools[$I]+"'"
      DoCommand $Cmd
   }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;FONT&gt;I did not use the geometry_equal() function, because it only return TRUE to completely identical tools&lt;/FONT&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 10:25:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/powermill-forum/tool-replace-macro-help/m-p/9105615#M13634</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-10-24T10:25:03Z</dc:date>
    </item>
    <item>
      <title>Re: Tool Replace Macro Help</title>
      <link>https://forums.autodesk.com/t5/powermill-forum/tool-replace-macro-help/m-p/9107827#M13635</link>
      <description>&lt;P&gt;Thank you , this will help&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2019 06:54:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/powermill-forum/tool-replace-macro-help/m-p/9107827#M13635</guid>
      <dc:creator>James-b123</dc:creator>
      <dc:date>2019-10-25T06:54:27Z</dc:date>
    </item>
    <item>
      <title>Re: Tool Replace Macro Help</title>
      <link>https://forums.autodesk.com/t5/powermill-forum/tool-replace-macro-help/m-p/9132592#M13636</link>
      <description>&lt;P&gt;Hi James,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I wrote this one a while ago, doesn't work for all tool types but is fairly comprehensive for those it does work for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It was written to be run from the user menu with some tools pre-selected, but this can be easily modified.&lt;/P&gt;
&lt;PRE&gt;//This macro cycle over the selected tools and finds all the tools in the project with matching geometry.
//These are presented to the user to choose the correct replacement. Or if there is only 1 selection available it will continue and replace the selected tool with that one.
//The macro will then identify all the toolpaths using the tool to be replaced and replace it with the selected replacement tool.
//The selected tools will then be deleted.

//Add to Custom tool menu using below code:
//  &amp;lt;button
//    command='MACRO "&amp;lt;Filepath to macro&amp;gt;"'
//    label="Replace Selected Tools"
//    multiple_selection="allowed"
//    behaviour="run_once"
//  /&amp;gt;

//Useful commands to speed up process and prevent popups not created by the macro
DIALOGS ERROR OFF
DIALOGS MESSAGE OFF
GRAPHICS LOCK

//Initiate variables
STRING $MessageText = ""
INT $Err = 0
BOOL $DeleteSelectedToolsAfterReplacement = false
STRING $Decision = ""
BOOL $Err1 = false

//Ask user if tools should be deleted after use
$DeleteSelectedToolsAfterReplacement = QUERY "Would you like to delete the tools after they have been replaced?"

//Create a list of the tools and check that at least 1 was selected.
ENTITY LIST $TLS = explorer_selected_entities()
IF SIZE($TLS) == 0 {
    MESSAGE ERROR "No tools selected, please select tools and rerun the macro."
}

//Loop through the list, all tasks will now be done on individual tools.
FOREACH $TL IN $TLS {
    STRING $Type = $TL.Type
    //Build string to filter list of tools by
    //The $Decision string will be used to filter the full tool list to just those that match the geometry of the tool.
    //The minimum number of criteria required for this process is used to provide users with the most options that the macro will work for.
    $Decision = "type=='${$Type}'"
    //The type is used to decide which parameters need to be compared
    SWITCH $Type {
        //Switch statement trickles through so types at the top will have more parameters to match.
        CASE 'taper_tipped'
            $Decision = $Decision + " AND TaperDiameter == " + STRING($TL.TaperDiameter)
        CASE 'taper_spherical'
            $Decision = $Decision + " AND taperangle == " + STRING($TL.taperangle)
        CASE 'tip_radiused'
            $Decision = $Decision + " AND tipradius == " + STRING($TL.tipradius)
        CASE 'ball_nosed'
        CASE 'end_mill'
            $Decision = $Decision + " AND diameter == " + STRING($TL.diameter)
            BREAK
            //Trickling through stops at a break statement
        
        //Add more cases in here to make it suitable for use with more tool types.
        
        DEFAULT
            //If not an identified tool type ignore the tool and carry on, inform the user.
            MESSAGE ERROR "Tool type ${$TL.Type} not supported. Tool: ${$TL.Name} not replaced. Continuing to next tool."
            PRINT "Tool type ${$TL.Type} not supported. Tool: ${$TL.Name} not replaced. Continuing to next tool."
            CONTINUE
            //Continue statement forces a loop to restart with the next item, if using them in a while loop ensure that conditions have been properly incremented.
    }

    //Build a list of appropriate replacements using the decision created for it, remove the original
    STRING LIST $ReplacementTools = EXTRACT(FILTER(Folder('tool'),$Decision),'name')
    $Err1 = REMOVE($ReplacementTools,$TL.Name) 
    //Choose replacement tool or error out if no replacement available.
    STRING $NewTool = ''
    IF SIZE($ReplacementTools) == 0 {
        //No tools available, skip this tool.
        Message ERROR "Tool geometry not found for tool ${$TL.Name}. Tool has not been replaced, continuing to next tool."
        PRINT "Tool geometry not found for tool ${$TL.Name}. Tool has not been replaced, continuing to next tool."
        CONTINUE
    } ELSEIF SIZE($ReplacementTools) == 1 {
        //Only 1 suitable replacement. Use that.
        $NewTool = $ReplacementTools[0]
    } ELSE {
        //Multiple suitable tools, allow the user to select which tool to use.
        STRING $ReplaceTool = "Please select tool to replace tool ${$TL.Name}"
        $Err = INPUT CHOICE $ReplacementTools $ReplaceTool
        $NewTool = $ReplacementTools[$Err]
    }
    
    //Identify toolpaths using the current tool, loop through them replace the tool with the selected replacement.
    ENTITY LIST $TPs = FILTER(Folder('toolpath'),"tool.name == '${$TL.Name}'")
    $MessageText = "Tool: ${$NewTool} matches the described geometry and is used in the following toolpaths:" + CRLF
    FOREACH $TP IN $TPs {
        $MessageText = $MessageText + $TP.Name + CRLF
        ACTIVATE TOOLPATH $TP
        ACTIVATE TOOL $NewTool
        EDIT TOOLPATH $TP REPLACE_TOOL ;
    }
    PRINT $MessageText
    
    //Delete the tool if requested.
    IF $DeleteSelectedToolsAfterReplacement {
        DELETE TOOL $TL
    }
}

//Restore the GUI
DIALOGS ERROR ON
DIALOGS MESSAGE ON
GRAPHICS UNLOCK&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Nov 2019 10:03:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/powermill-forum/tool-replace-macro-help/m-p/9132592#M13636</guid>
      <dc:creator>richard.pedley</dc:creator>
      <dc:date>2019-11-07T10:03:15Z</dc:date>
    </item>
    <item>
      <title>Re: Tool Replace Macro Help</title>
      <link>https://forums.autodesk.com/t5/powermill-forum/tool-replace-macro-help/m-p/9765405#M13637</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4473740"&gt;@richard.pedley&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello Richard, would you be able to do me a favor with this macro, would you be able to add in a bit where it opens up the feed and speed window and applies&amp;nbsp; the new feed rate of the tool that you have replaced it with. i have tried to do it my self but my knowledge is very limited.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2020 09:27:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/powermill-forum/tool-replace-macro-help/m-p/9765405#M13637</guid>
      <dc:creator>James-b123</dc:creator>
      <dc:date>2020-09-24T09:27:09Z</dc:date>
    </item>
    <item>
      <title>Re: Tool Replace Macro Help</title>
      <link>https://forums.autodesk.com/t5/powermill-forum/tool-replace-macro-help/m-p/10719715#M13638</link>
      <description>&lt;P&gt;Thanks for sharing. Just the quick question:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why do you added this line of code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;behaviour="run_once"&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My understanding is that if you do not include&amp;nbsp;"%s" in the command, it will run once anyway.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Oct 2021 10:06:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/powermill-forum/tool-replace-macro-help/m-p/10719715#M13638</guid>
      <dc:creator>artur.boszczyk</dc:creator>
      <dc:date>2021-10-28T10:06:26Z</dc:date>
    </item>
  </channel>
</rss>

