How to remove duplicate tools in a list for a Notepad file

How to remove duplicate tools in a list for a Notepad file

iamcdn79
Mentor Mentor
1,637 Views
2 Replies
Message 1 of 3

How to remove duplicate tools in a list for a Notepad file

iamcdn79
Mentor
Mentor

I have a macro that posts all my tools used in a toolpath for setups into a Notepad file.

 

The problem is if I have toolpaths that use the same tool they will show up in the list which I don't want and have to remove them manually. See video.

 

 

Is there a way to remove these duplicate tools from appearing in the Notepad list?

 

//This macro oders toolpaths by their setup

    MKDIR "C:\Temp\Lineup"

    STRING dir = "C:\Temp\Lineup" + "/" + project.Name + ".txt"

    IF ($powermill.Status.MultipleSelection.First) OR ($powermill.Status.MultipleSelection.Total == 0) {

        DELETE FILE $dir

    }

   

     	STRING TOOLName=''
        

	STRING LIST SetupList = {}

	FOREACH SetupTP IN folder('setup') {
	  FOREACH TP IN components(SetupTP) {
	   int $Count = add_last(SetupList, TP.name)
	  }
	}



ENTITY LIST $Selected_Toolpath = INPUT ENTITY MULTIPLE TOOLPATH "Select Toolpaths For List Of Tools" "" $SetupList
FOREACH $tp IN $Selected_Toolpath {


    
     ACTIVATE TOOLPATH $tp
    ENTITY Tool = ENTITY('Tool', '')



	STRING LIST msgList = {}




    // Check that the toolpath is computed and that it has at least 1 segment.
    IF (NOT ENTITY('toolpath','').computed) OR (SEGMENTS(toolpath) == 0) {
        
        RETURN
    }

    INT toolDia = ROUND(($Tool.Diameter * 25.4), 1)

    IF (POSITION($Tool.Name, "MM") > -1) {

        IF $Tool.Diameter == "0.059" { 

            STRING msg = "T" + $tool.Number.Value + " " + ROUND(($Tool.Diameter * 25.4), 1) + " " + "MM " + $Tool.Description +  " " + ROUND($Tool.Overhang, 3) + " LONG"   

            INT $Ok = add_last($msgList, $msg)

        } ELSEIF $Tool.Diameter != "0.059" {

            STRING msg = "T" + $tool.Number.Value + " " + $toolDia + " " + "MM " + $Tool.Description + " " + ROUND($Tool.Overhang, 3) + " LONG"   

            INT $Ok = add_last($msgList, $msg)

        }
            

        } ELSE {

            STRING msg = "T" + $tool.Number.Value + " " + $Tool.Diameter + " " + $Tool.Description + " " + ROUND($Tool.Overhang, 3) + " LONG"  

            INT $Ok = add_last($msgList, $msg)

        }


    FOREACH item IN msgList {
        

        FILE OPEN $dir FOR APPEND AS "out"
        FILE WRITE $item TO "out"
        FILE CLOSE "out"

            }
            
}
        IF (size($Selected_Toolpath) != 0)  {


        OLE FILEACTION 'open' $dir

    }

 


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
Accepted solutions (1)
1,638 Views
2 Replies
Replies (2)
Message 2 of 3

rafael.sansao
Advisor
Advisor
Accepted solution
//This macro oders toolpaths by their setup

MKDIR "C:\Temp\Lineup"
STRING dir = "C:\Temp\Lineup" + "/" + project.Name + ".txt"

IF ($powermill.Status.MultipleSelection.First) OR ($powermill.Status.MultipleSelection.Total == 0) {
	DELETE FILE $dir
}

STRING TOOLName=''
STRING LIST SetupList = {}
FOREACH SetupTP IN folder('setup') {
	FOREACH TP IN components(SetupTP) {
		int $Count = add_last(SetupList, TP.name)
	}
}

ENTITY LIST $Selected_Toolpath = INPUT ENTITY MULTIPLE TOOLPATH "Select Toolpaths For List Of Tools" "" $SetupList
STRING LIST msgList = {}
FOREACH $tp IN $Selected_Toolpath {
	//ACTIVATE TOOLPATH $tp
	//ENTITY Tool = ENTITY('Tool', '')

	// Check that the toolpath is computed and that it has at least 1 segment.
	IF (NOT $tp.computed) OR (SEGMENTS($tp) == 0) {
		RETURN
	}

	ENTITY Tool = $tp.Tool
	INT toolDia = ROUND(($Tool.Diameter * 25.4), 1)
	IF (POSITION($Tool.Name, "MM") > -1) {
		IF $Tool.Diameter == "0.059" { 
			STRING msg = "T" + $tool.Number.Value + " " + ROUND(($Tool.Diameter * 25.4), 1) + " " + "MM " + $Tool.Description +  " " + ROUND($Tool.Overhang, 3) + " LONG"   
			IF NOT MEMBER($msgList, $msg) {
				INT $Ok = add_last($msgList, $msg)
			}
		} ELSEIF $Tool.Diameter != "0.059" {
			STRING msg = "T" + $tool.Number.Value + " " + $toolDia + " " + "MM " + $Tool.Description + " " + ROUND($Tool.Overhang, 3) + " LONG"   
			IF NOT MEMBER($msgList, $msg) {
				INT $Ok = add_last($msgList, $msg)
			}
		}
	} ELSE {
		STRING msg = "T" + $tool.Number.Value + " " + $Tool.Diameter + " " + $Tool.Description + " " + ROUND($Tool.Overhang, 3) + " LONG"  
		IF NOT MEMBER($msgList, $msg) {
			INT $Ok = add_last($msgList, $msg)
		}
	}
}
IF (size($Selected_Toolpath) > 0)  {
	FILE OPEN $dir FOR APPEND AS "out"
	FOREACH item IN msgList {
		FILE WRITE $item TO "out"
	}
	FILE CLOSE "out"
	OLE FILEACTION 'open' $dir
}

Rafael Sansão

OptiNC - www.optinc.tech

EESignature

Message 3 of 3

kevin.hammond3WX4X
Advocate
Advocate

I see your query has been answered, but thought I would share my tool list creation macro.

It allows you to pick the relevant tools, it save them along with some other tool details that i like to check prior to closing project to an XML file, i then have it open in Excel.

 

// Macro to offer user a list of Tools in project, user selects those used for export ot Excel file for use in set up sheet - KJH 20/01/2023
//Variables
string user = user_id()
string msg = ""
string $Proj_path = project_pathname(0) + "\Tool_List"
MKDIR $proj_path
String logfile = "\Tool-list.csv"
String Log = $proj_path + $logfile
Message info "Tool list will be saved to -" +crlf+ $log +crlf+ "Then opened in Excel"
int toolnumber = ""
string Toolname = ""
string Toolid = ""
real tooloverhang = ""
string toolholder = ""
string pitch = ""
real tap_pitch = ""
string s = ","
string log_entry = ""
string type = ""
string log_space = ""
//create a list of tools in project
$msg = "select Tools for Output to list"
ENTITY LIST Tool = INPUT ENTITY MULTIPLE Tool $msg

//creates log file
FILE OPEN $log FOR WRITE AS log_file
$log_entry = "Tool_number, Tool_name, Tool_Overhang, Tool_Holder, Tap-Pitch,"
FILE WRITE $log_entry TO log_file
FILE CLOSE log_file

//loop through selected tools in list
FOREACH tl IN Tool {
Activate TOOL $tl.name
$toolnumber = $tl.Number.Value
$Toolname = $tl.Name
$toolid = $tl.Identifier
$tooloverhang = $tl.Overhang
$toolholder = $tl.HolderName
IF entity('tool','').type == 'tap' {
FORM TOOL ;
$tap_pitch = $widget("pmlTappingTool.Shell.TPGeom.Geometry.Pitch").value
$pitch = $tap_pitch
TOOL ACCEPT
} Else {
$pitch = ""
}
//write data to file
FILE OPEN $log FOR APPEND AS log_file
$log_entry = $toolnumber + "," + $Toolname + "," + $tooloverhang + "," + $toolholder + "," + $pitch
FILE WRITE $log_entry TO log_file

FILE CLOSE log_file
}
OLE FILEACTION 'OPEN' $log