REQUIRED RENAMING TOOLPATH ACORDING TO TOOLS NAME

REQUIRED RENAMING TOOLPATH ACORDING TO TOOLS NAME

rahulwalekar14
Participant Participant
1,483 Views
13 Replies
Message 1 of 14

REQUIRED RENAMING TOOLPATH ACORDING TO TOOLS NAME

rahulwalekar14
Participant
Participant

REQUIRED RENAMING TOOLPATH ACCORDING TO TOOLS NAME.

0 Likes
1,484 Views
13 Replies
Replies (13)
Message 2 of 14

TK.421
Advisor
Advisor

let's see a little bit of effort on your part. i know there's macros on this forum that do exactly that.  this isn't a fast food drive-thru


the numbers never lie
Message 3 of 14

icse
Advisor
Advisor

A bit more information what the macro should do exactly wowuld be nice to have...

 

This prefixes the selected toolpaths with the tool name, it also can 'exchange' the tool name if you recalculate the toolpath with another tool and rerun the macro and it tryes to removes the _1's from copyed toolpaths.

entity LIST $input = explorer_selected_entities()

if size($input) <= 0 or $input[0].RootType != 'toolpath' {
	return
}

string list $tTemp = extract(folder('tool'),'Name')
string list $toolNames = {}

INT $minIndex = min(apply(folder('tool'), 'length(this.Name)')) 
INT $maxIndex = max(apply(folder('tool'), 'length(this.Name)')) 

while $minIndex <= $maxIndex {
	FOREACH tool IN $tTemp {
		IF $length(tool) == $minIndex {
			INT x = add_first($toolNames, $tool)
		}
	}
	$minIndex = $minIndex + 1
}


foreach $tp in $input {

	string $newName = $tp.Name
	
	//remove old tool Name
	foreach $name in $toolNames {
	
		int $pos = position($tp.name, $name)
		if $pos == 0 {
			$newName = substring($tp.Name,$length($name))
			if position($newName, '_') == 0 {
				$newName = substring($newName,1)
			}
			break
		}
	}
	
	if not entity_exists($tp.Tool) {
		continue
	}
	
	
	int $lastToken = tokens($newName,'_')[size(tokens($newName,'_')) - 1]

	while $lastToken > 0 {
		string list $tkn = tokens($newName,'_')
		int $i = remove_last($tkn)
		$newName = join($tkn, '_')
		$lastToken = tokens($newName,'_')[size(tokens($newName,'_')) - 1]
	} 
	
	
	
	$newName = $tp.Tool.Name + '_' + $newName
	
	if $tp.Name == $newName {
		continue
	}
	
	if entity_exists(entity('toolpath',$newName)) {
		$newName = new_entity_name('toolpath', $newName)
	}
	
	rename toolpath $tp $newName
}
Message 4 of 14

rich11
Enthusiast
Enthusiast

I use this one. 

 

It sequences the programme number, name it based on the type of tool, diameter used and inserts any folder name in there to. It has a section to help tidy up messy names in the tool library too.

 

// string $wpName = ''
// $wpName = entity('NCProgram','').filename
// REAL diam = entity('boundary';name).Tool.Diameter

REAL TOOLDIAMETERNUM = 0
STRING TOOLDIAMETER = ""
INT STARTPROGRAMME = 0
STRING NEWNAME = ""
STRING FIRSTPROGNAME = ""
STRING TOOLTYPE = ""
STRING TOOLNAME = ""
STRING PROJECTNAME = ""
INT PREFIX = 0
STRING PROGNUMBER = ""
STRING OPFOLDER = ""
STRING PROJFOLDER = ""
INT FOLDEROP = 0
INT PROGLENGTH = 0
INT NAMESCHANGED = 0
INT UPDATEALL = 0
REAL TEST = 0

$PREFIX = INPUT "Enter the first programme number. Three digits minimum please."
$UPDATEALL = INPUT "Update ALL, 1 = YES"
$OPFOLDER = INPUT "Update by folder?, 0 = NO"

if ($OPFOLDER) == "0" {
$OPFOLDER = ""
}

if ($ORFOLDER) == "" {
$PROJFOLDER = 'NCProgram'
$FOLDEROP = 0
} ELSE {
$PROJFOLDER = 'NCProgram' + "\" + $OPFOLDER
$FOLDEROP = 1
}

//CORRECT THE FIRST PROGRAMMES NUMBER
$PREFIX = $PREFIX - 1

FOREACH ent IN folder($PROJFOLDER) {
//INDEX THE PROGRAMME
$STARTPROGRAMME = $STARTPROGRAMME +1
$PROJECTNAME = PROJECT.NAME

//BUILD THE PROGRAM NUMBER
$PROGNUMBER = $PREFIX + $STARTPROGRAMME

//GET FIRST TOOL PATH OF NC PROGRAM
ACTIVATE NCProgram $ent.Name
$FIRSTPROGNAME =ent.PARTNAME


//ACTIVATE TOOLPATH TO GET TOOL DIAMETER
ACTIVATE TOOLPATH $FIRSTPROGNAME
$TOOLDIAMETERNUM = TOOLPATH.TOOL.DIAMETER
$TOOLDIAMETERNUM = ROUND($TOOLDIAMETERNUM,2)
$TOOLDIAMETER = $TOOLDIAMETERNUM
$TOOLDIAMETER = REPLACE($TOOLDIAMETER, ".", "-")


//GET TOOL NAME AND CONVERT TO TOOLTYPE
$TOOLNAME = TOOLPATH.TOOL.NAME

IF position($TOOLNAME, "BNS") >= 0 {
$TOOLNAME = "BNS"
}
IF position($TOOLNAME, "BALLNOSED") >= 0 {
$TOOLNAME = "BNS"
}
IF position($TOOLNAME, "BULL") >= 0 {
$TOOLNAME = "BULL"
}
IF position($TOOLNAME, "CBORE") >= 0 {
$TOOLNAME = "CBORE"
}

IF position($TOOLNAME, "CHF") >= 0 {
$TOOLNAME = "CHF"
}
IF position($TOOLNAME, "CHAM") >= 0 {
$TOOLNAME = "CHF"
}

IF position($TOOLNAME, "DRILL") >= 0 {
$TOOLNAME = "DRILL"
}
IF position($TOOLNAME, "END") >= 0 {
$TOOLNAME = "END"
}
IF position($TOOLNAME, "ENDMILL") >= 0 {
$TOOLNAME = "END"
}
IF position($TOOLNAME, "ENGRAVE") >= 0 {
$TOOLNAME = "ENGRAVE"
}
IF position($TOOLNAME, "FORM") >= 0 {
$TOOLNAME = "FORM"
}
IF position($TOOLNAME, "GRANLUND") >= 0 {
$TOOLNAME = "GRANLUND"
}
IF position($TOOLNAME, "HIGHFEED") >= 0 {
$TOOLNAME = "HIGHFEED"
}
IF position($TOOLNAME, "REAM") >= 0 {
$TOOLNAME = "REAM"
}
IF position($TOOLNAME, "SPOTTER") >= 0 {
$TOOLNAME = "SPOTTER"
}
IF position($TOOLNAME, "TAPER") >= 0 {
$TOOLNAME = "TAPER"
}
IF position($TOOLNAME, "THREADMILL") >= 0 {
$TOOLNAME = "THREADMILL"
}
IF position($TOOLNAME, "TIPDISC") >= 0 {
$TOOLNAME = "TIPDISC"
}
IF position($TOOLNAME, "UDRILL") >= 0 {
$TOOLNAME = "UDRILL"
}


//BUILD THE NAME IF UPDATE ALL IS 1
IF $UPDATEALL == 1 {
$OPFOLDER = REPLACE($OPFOLDER, "\", "-")
$NEWNAME = TRIM("" + PROJECT.NAME + " " + $OPFOLDER + " " + $PROGNUMBER + " " + $TOOLDIAMETER +"MM" + " " + $TOOLNAME)
$NAMESCHANGED = $NAMESCHANGED + 1
PRINT "UPDATE ALL"
} ELSE {
//BUILD THE NAME IF PROJECT NAME IS NOT IN THE SAME
IF position($ent.Name, '$PROJECTNAME') < 0 {
$OPFOLDER = REPLACE($OPFOLDER, "\", "-")
$NEWNAME = TRIM("" + PROJECT.NAME + " " + $OPFOLDER + " " + $PROGNUMBER + " " + $TOOLDIAMETER +"MM" + " " + $TOOLNAME)
$NAMESCHANGED = $NAMESCHANGED + 1
}
}

//RENAME THE NC PROGRAM
RENAME NCProgram $ent.Name $NEWNAME

//TIDY
$NEWNAME = ""
}

MESSAGE INFO "Finished" + crlf + "Amount of Names changed = " + $NAMESCHANGED+ CRLF + CRLF

0 Likes
Message 5 of 14

rahulwalekar14
Participant
Participant
NOT WORKING
0 Likes
Message 6 of 14

rahulwalekar14
Participant
Participant
NOT WORKING
0 Likes
Message 7 of 14

rich11
Enthusiast
Enthusiast

Have you trusted the macro path.

0 Likes
Message 8 of 14

icse
Advisor
Advisor

Can you may tell us what exactly does not work? With no detail to the error at all its not possible to help...

0 Likes
Message 9 of 14

rahulwalekar14
Participant
Participant

rahulwalekar14_0-1732180491309.png

As these type of toolpath i have and after running the macro it comes for the serial no. and other options when i put the input it doesn't work . nothing happens. 

rahulwalekar14_1-1732180609718.pngrahulwalekar14_2-1732180649329.pngrahulwalekar14_3-1732180670401.png

 

0 Likes
Message 10 of 14

icse
Advisor
Advisor

Did you tryed to run my macro? (It will only change the names of the Selected toolpahts in the exploerer)

0 Likes
Message 11 of 14

rich11
Enthusiast
Enthusiast

Sorry but my macro runs on the NC programme name.

0 Likes
Message 12 of 14

mechzombie
Participant
Participant

Did you even try to make one? or atleast go through the forum? Forum already has too many working macro for the purposes.

Message 13 of 14

TK.421
Advisor
Advisor

I agree 100% @mechzombie   People are so lazy on here. 

@icse @rich11  this is exactly why I don’t help people who make zero effortIt ends up being a huge waste of time. This guy has everything he needs to make the macro function how he wants. Cut your losses and leave him to figure it out. Stop doing it for him. 


the numbers never lie
Message 14 of 14

rich11
Enthusiast
Enthusiast

I understand, I need help sometimes I just try where I can.

0 Likes