Macro to change tool numbers in NC Program

Macro to change tool numbers in NC Program

E-Singer89
Contributor Contributor
1,526 Views
9 Replies
Message 1 of 10

Macro to change tool numbers in NC Program

E-Singer89
Contributor
Contributor

Hey all, so I was wondering if there is a way to write a macro to change tool numbers in an NC Program. The reason I ask is because; all of our 3-axis machines allow up to like 500 tools in the offset page whereas our 5-axis machines only allow up to like 200 (Haas). So, when programming and a job starts in 3-axis and ends in 5-axis, when I go to post out a 5-axis program I have to go into the NC program and manually change all the tool numbers, so we don't get an alarm on the machine. I would rather not have multiple tool libraries or multiple entries in the tool library to accommodate for this. Is there a way to write a macro that would change these tool numbers in the NC Program for me when I'm ready to post? I'm aware i would have to build the list in its entirety into the macro but that's fine. I'm just very unsure of how to phrase all the if-then statements (If that's what I would even use)

0 Likes
Accepted solutions (1)
1,527 Views
9 Replies
Replies (9)
Message 2 of 10

nguyenthinhvt95
Advocate
Advocate

Could you share some picture in detail?

Maybe somebody can help you.

0 Likes
Message 3 of 10

icse
Advisor
Advisor

This macro takes every tool in the project with a number larger than 200 and replaces its number with the first free lowest tool number:

int $newToolNumb = 0

foreach $t in filter(folder('tool'),'this.Number.Value > 200') {
	$newToolNumb = $newToolNumb + 1
	int list $toolnumbers = extract(folder('tool'), 'Tool.Number.Value')
	
	while member($toolnumbers, $newToolNumb) {
		$newToolNumb = $newToolNumb + 1
	}
	
	EDIT TOOL ${t.Name} NUMBER COMMANDFROMUI ${newToolNumb}
}
0 Likes
Message 4 of 10

E-Singer89
Contributor
Contributor

Interesting, thank you. But not quite what I need. We have a set tool list of what tool is assigned to what offset number

0 Likes
Message 5 of 10

E-Singer89
Contributor
Contributor

sorry about that. 

 

here is an example of a 3-axis program

3-axis nc prog settings.JPG

 

5-axis program before settings change

5-axis nc prog b4.JPG

 

this is where i change my tool numbers in the nc program

5-axis nc prog change this.JPG

 

and this is what it looks like after the change, the asterisk notes that a change was made.

5-axis nc prog after.JPG

0 Likes
Message 6 of 10

icse
Advisor
Advisor

you coud make a .txt file for mapping

 

500|200

400|1

....

 

so number 500 is changed to 200, 400 is changed to 1 and so on

 

sry i misunderstood you i rewrite the macro

 

 

 

0 Likes
Message 7 of 10

E-Singer89
Contributor
Contributor

this is what i had in mind for sure. Is this going to change the tool numbers in the project though or just in the nc program? see my pictures above

0 Likes
Message 8 of 10

icse
Advisor
Advisor
Accepted solution

Try this:

string $mappingPath = "C:\YourPath\mapping.txt"

if not file_exists($mappingPath) {
	message info "Can't find mapping file"
	return
}



string list $mapping = {}

FILE OPEN $mappingPath FOR READ AS Input
FILE READ $mapping FROM Input
FILE CLOSE Input

entity list $ncPrograms = input entity multiple ncprogram "Select NcPrograms to change tool numbers"

foreach $ncprogram in $ncPrograms {

	foreach $line in $mapping {
		int $target = tokens($line,'|')[0]
		int $dest = tokens($line,'|')[1]
		
		foreach $tp in filter(components($ncprogram),'this.ToolNumber.FromTool == "' + $target + '"') {
			$tp.ToolNumber.UserDefined = 1
			$tp.ToolNumber.Typed = $dest
			$tp.ToolNumber.Value = $dest
		}
	}	
}

but please make a backup of your project first i did not tested it jet...

Message 9 of 10

E-Singer89
Contributor
Contributor

I will test this on a dummy file. Thank you! ill let you know how it goes

0 Likes
Message 10 of 10

E-Singer89
Contributor
Contributor
it works!!!! thank you!!!!